Issues (245)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Service/Action/Collection/DeleteActionTest.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
4
 *
5
 * Licensed under The MIT License
6
 * Redistributions of files must retain the above copyright notice.
7
 *
8
 * @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com)
9
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
10
 */
11
12
namespace CakeDC\Api\Test\TestCase\Service\Action\Collection;
13
14
use CakeDC\Api\Exception\ValidationException;
15
use CakeDC\Api\Service\Action\Collection\DeleteAction;
16
use CakeDC\Api\Service\ServiceRegistry;
17
use CakeDC\Api\TestSuite\TestCase;
18
use CakeDC\Api\Test\ConfigTrait;
19
use CakeDC\Api\Test\FixturesTrait;
20
use Cake\ORM\TableRegistry;
21
22
class DeleteActionTest extends TestCase
23
{
24
    use ConfigTrait;
25
    use FixturesTrait;
26
27
    /**
28
     * @var DeleteAction
29
     */
30
    public $Action;
31
32
    /**
33
     * setUp method
34
     *
35
     * @return void
36
     */
37
    public function setUp()
38
    {
39
        parent::setUp();
40
    }
41
42
    /**
43
     * tearDown method
44
     *
45
     * @return void
46
     */
47
    public function tearDown()
48
    {
49
        ServiceRegistry::clear();
0 ignored issues
show
Deprecated Code introduced by
The method CakeDC\Api\Service\ServiceRegistry::clear() has been deprecated with message: 3.6.0 Use \CakeDC\Api\Service\Locator\ServiceLocator::clear() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
50
        unset($this->Service, $this->Action, $this->request);
51
        parent::tearDown();
52
    }
53
54
    /**
55
     * @return void
56
     */
57
    public function testExecuteSuccess()
58
    {
59
        $ArticlesTable = TableRegistry::get('Articles');
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\TableRegistry::get() has been deprecated with message: 3.6.0 Use \Cake\ORM\Locator\TableLocator::get() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
60
        $initialCount = $ArticlesTable->find()->count();
61
        $this->_initializeAction([
62
            ['id' => 1],
63
            ['id' => 2]
64
        ]);
65
66
        $this->Action->execute();
67
        $finalCount = $ArticlesTable->find()->count();
68
        $this->assertEquals(-2, $finalCount - $initialCount, 'We should have added 2 new articles');
69
    }
70
71
    /**
72
     * @return void
73
     * @expectedException \CakeDC\Api\Exception\ValidationException
74
     */
75
    public function testValidationPostNotArray()
76
    {
77
        $this->_initializeAction(
78
            ['id' => 1]
79
        );
80
        $this->Action->execute();
81
    }
82
83
    /**
84
     * @return void
85
     * @expectedException \CakeDC\Api\Exception\ValidationException
86
     */
87
    public function testValidationPostEmpty()
88
    {
89
        $this->_initializeAction();
90
        $this->Action->execute();
91
    }
92
93
    /**
94
     * @return void
95
     * @expectedException \CakeDC\Api\Exception\ValidationException
96
     */
97
    public function testValidationPostString()
98
    {
99
        $this->_initializeAction('something');
0 ignored issues
show
'something' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
        $this->Action->execute();
101
    }
102
103
    /**
104
     * @return void
105
     * @expectedException \CakeDC\Api\Exception\ValidationException
106
     * @expectedExceptionMessage Validation failed
107
     */
108
    public function testExecuteValidationEntityNotValid()
109
    {
110
        $this->_initializeAction([
111
            ['not-id' => 'something'],
112
            ['blank' => new \ArrayObject()]
113
        ]);
114
115
        $this->Action->execute();
116
    }
117
118
    /**
119
     * @return void
120
     */
121
    public function testValidatesEntity()
122
    {
123
        $this->_initializeAction([
124
            ['id' => 1],
125
            ['id' => 7]
126
        ]);
127
128
        $this->assertTrue($this->Action->validates());
129
    }
130
131
    /**
132
     * @return void
133
     */
134
    public function testValidatesEntityNotValid()
135
    {
136
        $this->_initializeAction([
137
            ['id' => 1],
138
            ['id' => '']
139
        ]);
140
141
        try {
142
            $this->Action->validates();
143
            $this->fail('ValidationException was expected');
144
        } catch (ValidationException $ex) {
145
            $this->assertSame([
146
                // note the index here is important, first entity (0) is valid
147
                1 => [
148
                    'id' => [
149
                        '_empty' => 'Missing id'
150
                    ]
151
                ]
152
            ], $ex->getValidationErrors());
153
        }
154
    }
155
156
    protected function _initializeAction($post = [])
157
    {
158
        $this->_initializeRequest([
159
            'params' => [
160
                'service' => 'articlesCollection',
161
            ],
162
            'post' => $post,
163
        ], 'POST');
164
        $options = [
165
            'version' => null,
166
            'service' => null,
167
            'request' => $this->request,
0 ignored issues
show
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
168
            'response' => $this->response,
0 ignored issues
show
The property response does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
169
            'baseUrl' => '/articles_collection/collection/delete'
170
        ];
171
        $this->Service = ServiceRegistry::get($this->request->getParam('service'), $options);
0 ignored issues
show
The property Service does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Deprecated Code introduced by
The method CakeDC\Api\Service\ServiceRegistry::get() has been deprecated with message: 3.6.0 Use \CakeDC\Api\Service\Locator\ServiceLocator::get() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
172
173
        $this->Action = new DeleteAction([
174
            'service' => $this->Service,
175
        ]);
176
        $this->Action->setTable(TableRegistry::get('Articles'));
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\TableRegistry::get() has been deprecated with message: 3.6.0 Use \Cake\ORM\Locator\TableLocator::get() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
177
    }
178
}
179