This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Ntb\RestAPI; |
||
4 | |||
5 | use Config; |
||
6 | |||
7 | /** |
||
8 | * Class SessionControllerTest |
||
9 | * @author Christian Blank <[email protected]> |
||
10 | */ |
||
11 | class SessionEndpointTest extends RestTest { |
||
12 | |||
13 | public function setUp() { |
||
14 | parent::setUp(); |
||
15 | Config::inst()->update('Director', 'rules', [ |
||
16 | 'v/1/RestrictedRoute/$ID' => 'Ntb\RestAPI\RestrictedResourceController', |
||
17 | 'v/1/SessionRoute/$ID' => 'Ntb\RestAPI\SessionController', |
||
18 | ]); |
||
19 | Config::inst()->update('Injector', 'ApiMemberAuthenticator', 'MemberAuthenticator'); |
||
20 | Config::inst()->update('BaseRestController', 'Owner', 'Member'); |
||
21 | } |
||
22 | |||
23 | protected static $fixture_file = [ |
||
24 | 'silverstripe-rest-api/tests/functional/fixture/Member.yml' |
||
25 | ]; |
||
26 | |||
27 | public function testTryGetRestrictedResourceWithoutSession() { |
||
28 | $this->makeApiRequest('RestrictedRoute', ['code' => 401]); |
||
29 | } |
||
30 | |||
31 | public function testGetRestrictedResource() { |
||
32 | $session = $this->createSession(); |
||
33 | $this->makeApiRequest('RestrictedRoute', ['token' => $session['token']]); |
||
34 | } |
||
35 | |||
36 | public function testDeleteSession() { |
||
37 | $session = $this->createSession(); |
||
38 | $this->makeApiRequest('SessionRoute/me', ['token' => $session['token'], 'method' => 'DELETE']); |
||
39 | } |
||
40 | |||
41 | View Code Duplication | public function testTryDeleteSessionWithoutID() { |
|
0 ignored issues
–
show
|
|||
42 | $session = $this->createSession(); |
||
43 | $result = $this->makeApiRequest('SessionRoute', ['token' => $session['token'], 'method' => 'DELETE', 'code' => 400]); |
||
44 | |||
45 | $this->assertTrue(array_key_exists('code', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
46 | $this->assertTrue(array_key_exists('message', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
47 | $this->assertEquals(404, $result['code']); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
48 | } |
||
49 | |||
50 | View Code Duplication | public function testTryDeleteSessionWithWrongId() { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
51 | $session = $this->createSession(); |
||
52 | $result = $this->makeApiRequest('SessionRoute/-2', ['token' => $session['token'], 'method' => 'DELETE', 'code' => 400]); |
||
53 | |||
54 | $this->assertTrue(array_key_exists('code', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
55 | $this->assertTrue(array_key_exists('message', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
56 | $this->assertEquals(404, $result['code']); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
57 | } |
||
58 | |||
59 | public function testCreateSession() { |
||
60 | $session = $this->createSession(); |
||
61 | $this->assertTrue(is_array($session)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
62 | $this->assertTrue(array_key_exists('user', $session)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
63 | $this->assertTrue(array_key_exists('token', $session)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
64 | } |
||
65 | |||
66 | View Code Duplication | public function testTryCreateSessionWithWrongPassword() { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
67 | $data = [ |
||
68 | 'email' => '[email protected]', |
||
69 | 'password' => 'wrongPass' |
||
70 | ]; |
||
71 | |||
72 | $dataString = json_encode($data); |
||
73 | $result = $this->makeApiRequest('SessionRoute', ['body' => $dataString, 'method' => 'POST', 'code' => 401]); |
||
74 | |||
75 | $this->assertTrue(array_key_exists('code', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
76 | $this->assertTrue(array_key_exists('message', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
77 | $this->assertEquals(401, $result['code']); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
78 | } |
||
79 | |||
80 | View Code Duplication | public function testTryCreateSessionWithWrongEmail() { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
81 | $data = [ |
||
82 | 'email' => 'foo.com', |
||
83 | 'password' => 'wrong' |
||
84 | ]; |
||
85 | |||
86 | $dataString = json_encode($data); |
||
87 | $result = $this->makeApiRequest('SessionRoute', ['body' => $dataString, 'method' => 'POST', 'code' => 422]); |
||
88 | |||
89 | $this->assertTrue(array_key_exists('code', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
90 | $this->assertTrue(array_key_exists('message', $result)); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
91 | $this->assertEquals(422, $result['code']); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<Ntb\RestAPI\SessionEndpointTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
92 | } |
||
93 | } |
||
94 | |||
95 | |||
96 | class RestrictedResourceController extends BaseRestController implements \TestOnly { |
||
97 | |||
98 | private static $allowed_actions = array ( |
||
0 ignored issues
–
show
|
|||
99 | 'get' => '->isAuthenticated' |
||
100 | ); |
||
101 | |||
102 | public function get() { |
||
103 | return ['message' => 'Test GET']; |
||
104 | } |
||
105 | } |
||
106 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.