Issues (45)

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.

tests/Command/UserCommandsTest.php (2 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
declare (strict_types = 1);
4
5
namespace HMLB\UserBundle\Tests\Command;
6
7
use HMLB\DDD\Message\Event\PersistentEvent;
8
use HMLB\DDDBundle\Repository\PersistentCommandRepository;
9
use HMLB\DDDBundle\Repository\PersistentEventRepository;
10
use HMLB\UserBundle\Command\ChangeEmail;
11
use HMLB\UserBundle\Command\ChangePassword;
12
use HMLB\UserBundle\Command\ConfirmEmail;
13
use HMLB\UserBundle\Command\RegisterUser;
14
use HMLB\UserBundle\Command\RequestEmailValidation;
15
use HMLB\UserBundle\Command\RequestPasswordReset;
16
use HMLB\UserBundle\Command\ResetPassword;
17
use HMLB\UserBundle\Event\EmailChanged;
18
use HMLB\UserBundle\Event\EmailConfirmed;
19
use HMLB\UserBundle\Event\EmailValidationRequested;
20
use HMLB\UserBundle\Event\PasswordChanged;
21
use HMLB\UserBundle\Event\PasswordReset;
22
use HMLB\UserBundle\Event\PasswordResetRequested;
23
use HMLB\UserBundle\Event\UserRegistered;
24
use HMLB\UserBundle\User\Role;
25
use HMLB\UserBundle\User\User;
26
use HMLB\UserBundle\User\UserRepository;
27
28
/**
29
 * RegisterUserTest.
30
 *
31
 * @author Hugues Maignol <[email protected]>
32
 */
33
class UserCommandsTest extends AbstractCommandTest
34
{
35
    /**
36
     * @test
37
     */
38
    public function usersCanRegister()
39
    {
40
        $command = new RegisterUser('test', '[email protected]', '123', [new Role('ROLE_USER')]);
41
42
        $this->handleCommandAndAssertTraced(
43
            $this->getCommandBus(),
44
            $command,
45
            $this->getCommandRepository()
46
        );
47
48
        /** @var UserRegistered $event */
49
        $event = $this->getEvent(UserRegistered::class);
50
        $this->assertEquals($command->getUsername(), $event->getUsername());
51
52
        /** @var User $user */
53
        $user = $this->container->get('hmlb_user.repository.user')->get($event->getUserId());
54
        $this->assertInstanceOf(User::class, $user);
55
        $this->assertEquals('test', $user->getUsername());
56
        $this->assertEquals('[email protected]', $user->getEmail());
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function usersCanChangePassword()
63
    {
64
        $register = new RegisterUser('test', '[email protected]', '123', [new Role('ROLE_USER')]);
65
        $this->getCommandBus()->handle($register);
66
67
        $user = $this->getUserRepository()->getByUsername($register->getUsername());
68
        $beginningPwd = $user->getPassword();
69
        $command = new ChangePassword('456', $user->getId());
70
71
        $this->handleCommandAndAssertTraced(
72
            $this->getCommandBus(),
73
            $command,
74
            $this->getCommandRepository()
75
        );
76
        $endPwd = $user->getPassword();
77
78
        $this->assertNotEquals($beginningPwd, $endPwd);
79
80
        /** @var PasswordChanged $event */
81
        $event = $this->getEvent(PasswordChanged::class);
82
        $this->assertEquals($command->getUserId(), $event->getUserId());
83
        $this->assertNotEquals($event->getOldPassword(), $event->getNewPassword());
84
    }
85
86
    /**
87
     * @test
88
     */
89
    public function usersCanChangeEmail()
90
    {
91
        $register = new RegisterUser('test', '[email protected]', '123', [new Role('ROLE_USER')]);
92
        $this->getCommandBus()->handle($register);
93
94
        $user = $this->getUserRepository()->getByUsername($register->getUsername());
95
        $beforeEmail = $user->getEmail();
96
        $command = new ChangeEmail('[email protected]', $user->getId());
97
98
        $commandRepo = $this->getCommandRepository();
99
        $this->handleCommandAndAssertTraced(
100
            $this->getCommandBus(),
101
            $command,
102
            $commandRepo
103
        );
104
        $afterEmail = $user->getEmail();
105
106
        $this->assertNotEquals($beforeEmail, $afterEmail);
107
        $this->assertEquals('[email protected]', $afterEmail);
108
109
        /** @var EmailChanged $event */
110
        $event = $this->getEvent(EmailChanged::class);
111
112
        $this->assertEquals($beforeEmail, $event->getOldEmail());
113
        $this->assertEquals($afterEmail, $event->getNewEmail());
114
    }
115
116
    /**
117
     * @test
118
     */
119
    public function usersCanValidateEmail()
120
    {
121
        $register = new RegisterUser('test', '[email protected]', '123', [new Role('ROLE_USER')]);
122
        $this->getCommandBus()->handle($register);
123
124
        $user = $this->getUserRepository()->getByUsername($register->getUsername());
125
        $this->assertFalse($user->isEmailConfirmed());
126
        $command = new ConfirmEmail($user->getConfirmationToken(), $user->getId());
127
128
        $this->handleCommandAndAssertTraced(
129
            $this->getCommandBus(),
130
            $command,
131
            $this->getCommandRepository()
132
        );
133
134
        $this->assertTrue($user->isEmailConfirmed());
135
136
        /** @var EmailConfirmed $event */
137
        $event = $this->getEvent(EmailConfirmed::class);
138
        $this->assertEquals($user->getId(), $event->getUserId());
139
        $this->assertEquals($user->getEmail(), $event->getEmail());
140
    }
141
142
    /**
143
     * @test
144
     */
145 View Code Duplication
    public function emailValidationCanBeRequested()
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.

Loading history...
146
    {
147
        $register = new RegisterUser('test', '[email protected]', '123', [new Role('ROLE_USER')]);
148
        $this->getCommandBus()->handle($register);
149
150
        $user = $this->getUserRepository()->getByUsername($register->getUsername());
151
        $confirm = new ConfirmEmail($user->getConfirmationToken(), $user->getId());
152
        $this->getCommandBus()->handle($confirm);
153
        $this->assertTrue($user->isEmailConfirmed());
154
155
        $command = new RequestEmailValidation($user->getId());
156
157
        $this->handleCommandAndAssertTraced(
158
            $this->getCommandBus(),
159
            $command,
160
            $this->getCommandRepository()
161
        );
162
163
        $this->assertFalse($user->isEmailConfirmed());
164
165
        /** @var EmailValidationRequested $event */
166
        $event = $this->getEvent(EmailValidationRequested::class);
167
        $this->assertEquals($user->getId(), $event->getUserId());
168
        $this->assertEquals($user->getConfirmationToken(), $event->getValidationToken());
169
    }
170
171
    /**
172
     * @test
173
     */
174 View Code Duplication
    public function passwordResetCanBeRequested()
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.

Loading history...
175
    {
176
        $register = new RegisterUser('test', '[email protected]', '123', [new Role('ROLE_USER')]);
177
        $this->getCommandBus()->handle($register);
178
179
        $user = $this->getUserRepository()->getByUsername($register->getUsername());
180
181
        $this->assertFalse($user->isPasswordResetRequested());
182
        $this->assertEmpty($user->getResettingToken());
183
184
        $command = new RequestPasswordReset($user->getId());
185
186
        $this->handleCommandAndAssertTraced(
187
            $this->getCommandBus(),
188
            $command,
189
            $this->getCommandRepository()
190
        );
191
192
        $this->assertTrue($user->isPasswordResetRequested());
193
        $this->assertNotEmpty($user->getResettingToken());
194
195
        /** @var PasswordResetRequested $event */
196
        $event = $this->getEvent(PasswordResetRequested::class);
197
        $this->assertEquals($user->getId(), $event->getUserId());
198
        $this->assertEquals($user->getResettingToken(), $event->getResetToken());
199
    }
200
201
    /**
202
     * @test
203
     */
204
    public function passwordCanBeReset()
205
    {
206
        $register = new RegisterUser('test', '[email protected]', '123', [new Role('ROLE_USER')]);
207
        $this->getCommandBus()->handle($register);
208
209
        $user = $this->getUserRepository()->getByUsername($register->getUsername());
210
211
        $request = new RequestPasswordReset($user->getId());
212
        $this->getCommandBus()->handle($request);
213
214
        $command = new ResetPassword('456', $user->getResettingToken(), $user->getId());
215
216
        $beginningPwd = $user->getPassword();
217
        $this->handleCommandAndAssertTraced(
218
            $this->getCommandBus(),
219
            $command,
220
            $this->getCommandRepository()
221
        );
222
223
        $endPwd = $user->getPassword();
224
225
        $this->assertFalse($user->isPasswordResetRequested());
226
        $this->assertEmpty($user->getResettingToken());
227
        $this->assertNotEquals($beginningPwd, $endPwd);
228
229
        /** @var PasswordReset $event */
230
        $event = $this->getEvent(PasswordReset::class);
231
        $this->assertEquals($user->getId(), $event->getUserId());
232
        $this->assertEquals($beginningPwd, $event->getOldPassword());
233
        $this->assertEquals($endPwd, $event->getNewPassword());
234
    }
235
236
    /**
237
     * @param $eventClassName
238
     *
239
     * @return PersistentEvent
240
     */
241
    private function getEvent($eventClassName)
242
    {
243
        $eventRepository = $this->getEventRepository();
244
245
        $foundEvents = $eventRepository->getByMessage($eventClassName);
246
        $this->assertCount(1, $foundEvents);
247
248
        $event = $foundEvents[0];
249
        $this->assertInstanceOf($eventClassName, $event);
250
251
        return $event;
252
    }
253
254
    private function getUserRepository(): UserRepository
255
    {
256
        return $this->container->get('hmlb_user.repository.user');
257
    }
258
259
    private function getCommandRepository(): PersistentCommandRepository
260
    {
261
        return $this->container->get('hmlb_ddd.repository.command');
262
    }
263
264
    private function getEventRepository(): PersistentEventRepository
265
    {
266
        return $this->container->get('hmlb_ddd.repository.event');
267
    }
268
}
269