Issues (19)

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.

test/JhUserTest/Controller/RoleControllerTest.php (1 issue)

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
namespace JhUserTest\Controller;
4
5
use JhUser\Entity\User;
6
use JhUser\Entity\HierarchicalRole;
7
use Zend\Console\Request;
8
use Zend\Http\Request as HttpRequest;
9
use Zend\Test\PHPUnit\Controller\AbstractConsoleControllerTestCase;
10
11
/**
12
 * Class RoleControllerTest
13
 * @package JhUserTest\Controller
14
 * @author Aydin Hassan <[email protected]>
15
 */
16
class RoleControllerTest extends AbstractConsoleControllerTestCase
17
{
18
19
    /**
20
     * @var User
21
     */
22
    protected $user;
23
24
    /**
25
     * @var Role
26
     */
27
    protected $role;
28
29
30
    public function setUp()
31
    {
32
        $this->setApplicationConfig(
33
            include __DIR__ . "/../../TestConfiguration.php.dist"
34
        );
35
        parent::setUp();
36
    }
37
38
    public function testUsersRoleCanBeSet()
39
    {
40
        $email  = '[email protected]';
41
        $roleId = 'admin';
42
43
        $this->configureMocks($email, $roleId);
44
45
        $this->dispatch(new Request(['scriptname.php', "set role $email  $roleId"]));
46
47
        $this->assertResponseStatusCode(0);
48
        $this->assertModuleName('jhuser');
49
        $this->assertControllerName('jhuser\controller\role');
50
        $this->assertControllerClass('rolecontroller');
51
        $this->assertActionName('set-role');
52
        $this->assertMatchedRouteName('set-role');
53
54
        $this->assertCount(1, $this->user->getRoles());
55
        $this->assertSame($this->user->getRoles()[0], $this->role);
56
    }
57
58
    public function testUsersRoleCanBeModified()
59
    {
60
        $email  = '[email protected]';
61
        $roleId = 'admin';
62
63
        $this->configureMocks($email, $roleId);
64
        $role = new HierarchicalRole;
65
        $role->setName('user');
66
        $this->user->addRole($role);
67
68
        $this->dispatch(new Request(['scriptname.php', "set role $email  $roleId"]));
69
70
        $this->assertResponseStatusCode(0);
71
        $this->assertModuleName('jhuser');
72
        $this->assertControllerName('jhuser\controller\role');
73
        $this->assertControllerClass('rolecontroller');
74
        $this->assertActionName('set-role');
75
        $this->assertMatchedRouteName('set-role');
76
77
        $this->assertCount(1, $this->user->getRoles());
78
        $this->assertSame($this->user->getRoles()[1], $this->role);
79
    }
80
81
    public function configureMocks($userEmail, $roleId)
82
    {
83
        $userRepoMock       = $this->getMock('JhUser\Repository\UserRepositoryInterface');
84
        $roleRepoMock       = $this->getMock('JhUser\Repository\RoleRepositoryInterface');
85
        $objectManagerMock  = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
86
87
        $this->user = new User();
88
        $this->user->setEmail($userEmail);
89
90
        $userRepoMock
91
            ->expects($this->once())
92
            ->method('findOneByEmail')
93
            ->with($userEmail)
94
            ->will($this->returnValue($this->user));
95
96
        $this->role = new HierarchicalRole();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \JhUser\Entity\HierarchicalRole() of type object<JhUser\Entity\HierarchicalRole> is incompatible with the declared type object<JhUserTest\Controller\Role> of property $role.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
97
        $this->role->setName($roleId);
98
99
        $roleRepoMock
100
            ->expects($this->once())
101
            ->method('findByName')
102
            ->with($roleId)
103
            ->will($this->returnValue($this->role));
104
105
        $objectManagerMock
106
            ->expects($this->once())
107
            ->method('flush');
108
109
        $serviceManager = $this->getApplicationServiceLocator();
110
        $serviceManager->setAllowOverride(true);
111
        $serviceManager->setService('JhUser\Repository\UserRepository', $userRepoMock);
112
        $serviceManager->setService('JhUser\Repository\RoleRepository', $roleRepoMock);
113
        $serviceManager->setService('JhUser\ObjectManager', $objectManagerMock);
114
    }
115
116
117
    public function testExceptionIsThrownIfRoleNotExists()
118
    {
119
        $email  = '[email protected]';
120
        $roleId = 'admin';
121
122
        $userRepoMock       = $this->getMock('JhUser\Repository\UserRepositoryInterface');
123
        $roleRepoMock       = $this->getMock('JhUser\Repository\RoleRepositoryInterface');
124
        $objectManagerMock  = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
125
126
        $user = new User();
127
        $user->setEmail($email);
128
129
        $userRepoMock
130
            ->expects($this->once())
131
            ->method('findOneByEmail')
132
            ->with($email)
133
            ->will($this->returnValue($user));
134
135
        $roleRepoMock
136
            ->expects($this->once())
137
            ->method('findByName')
138
            ->with($roleId)
139
            ->will($this->returnValue(null));
140
141
        $objectManagerMock->expects($this->never())->method('flush');
142
143
        $serviceManager = $this->getApplicationServiceLocator();
144
        $serviceManager->setAllowOverride(true);
145
        $serviceManager->setService('JhUser\Repository\UserRepository', $userRepoMock);
146
        $serviceManager->setService('JhUser\Repository\RoleRepository', $roleRepoMock);
147
        $serviceManager->setService('JhUser\ObjectManager', $objectManagerMock);
148
149
        $this->dispatch(new Request(['scriptname.php', "set role $email  $roleId"]));
150
        $this->assertResponseStatusCode(1);
151
        $this->assertModuleName('jhuser');
152
        $this->assertControllerName('jhuser\controller\role');
153
        $this->assertControllerClass('rolecontroller');
154
        $this->assertActionName('set-role');
155
        $this->assertMatchedRouteName('set-role');
156
        $this->assertApplicationException('RuntimeException', sprintf('Role: "%s" could not be found', $roleId));
157
    }
158
159
    public function testExceptionIsThrownIfUserNotExists()
160
    {
161
        $email  = '[email protected]';
162
        $roleId = 'admin';
163
164
        $userRepoMock       = $this->getMock('JhUser\Repository\UserRepositoryInterface');
165
        $roleRepoMock       = $this->getMock('JhUser\Repository\RoleRepositoryInterface');
166
        $objectManagerMock  = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
167
168
        $userRepoMock
169
            ->expects($this->once())
170
            ->method('findOneByEmail')
171
            ->with($email)
172
            ->will($this->returnValue(null));
173
174
        $roleRepoMock->expects($this->never())->method('findByName');
175
        $objectManagerMock->expects($this->never())->method('flush');
176
177
        $serviceManager = $this->getApplicationServiceLocator();
178
        $serviceManager->setAllowOverride(true);
179
        $serviceManager->setService('JhUser\Repository\UserRepository', $userRepoMock);
180
        $serviceManager->setService('JhUser\Repository\RoleRepository', $roleRepoMock);
181
        $serviceManager->setService('JhUser\ObjectManager', $objectManagerMock);
182
183
        $this->dispatch(new Request(['scriptname.php', "set role $email  $roleId"]));
184
        $this->assertResponseStatusCode(1);
185
        $this->assertModuleName('jhuser');
186
        $this->assertControllerName('jhuser\controller\role');
187
        $this->assertControllerClass('rolecontroller');
188
        $this->assertActionName('set-role');
189
        $this->assertMatchedRouteName('set-role');
190
        $this->assertApplicationException(
191
            'RuntimeException',
192
            sprintf('User with email: "%s" could not be found', $email)
193
        );
194
    }
195
}
196