15
15
use Symfony \Component \HttpFoundation \Request ;
16
16
use Symfony \Component \PasswordHasher \Hasher \PasswordHasherFactoryInterface ;
17
17
use Symfony \Component \PasswordHasher \PasswordHasherInterface ;
18
- use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
19
18
use Symfony \Component \Security \Core \User \InMemoryUser ;
20
19
use Symfony \Component \Security \Core \User \PasswordAuthenticatedUserInterface ;
21
20
use Symfony \Component \Security \Core \User \PasswordUpgraderInterface ;
22
21
use Symfony \Component \Security \Core \User \UserInterface ;
23
22
use Symfony \Component \Security \Core \User \UserProviderInterface ;
24
- use Symfony \Component \Security \Http \Authenticator \AuthenticatorInterface ;
25
23
use Symfony \Component \Security \Http \Authenticator \Passport \Badge \PasswordUpgradeBadge ;
26
24
use Symfony \Component \Security \Http \Authenticator \Passport \Badge \UserBadge ;
27
25
use Symfony \Component \Security \Http \Authenticator \Passport \PassportInterface ;
28
26
use Symfony \Component \Security \Http \Authenticator \Passport \SelfValidatingPassport ;
29
27
use Symfony \Component \Security \Http \Authenticator \Passport \UserPassportInterface ;
30
28
use Symfony \Component \Security \Http \Event \LoginSuccessEvent ;
31
29
use Symfony \Component \Security \Http \EventListener \PasswordMigratingListener ;
30
+ use Symfony \Component \Security \Http \Tests \Fixtures \DummyAuthenticator ;
31
+ use Symfony \Component \Security \Http \Tests \Fixtures \DummyToken ;
32
32
33
33
class PasswordMigratingListenerTest extends TestCase
34
34
{
@@ -58,13 +58,13 @@ public function testUnsupportedEvents($event)
58
58
$ this ->listener ->onLoginSuccess ($ event );
59
59
}
60
60
61
- public function provideUnsupportedEvents ()
61
+ public static function provideUnsupportedEvents ()
62
62
{
63
63
// no password upgrade badge
64
- yield [$ this -> createEvent (new SelfValidatingPassport (new UserBadge ('test ' , function () { return $ this ->createMock (UserInterface::class); })))];
64
+ yield [self :: createEvent (new SelfValidatingPassport (new UserBadge ('test ' , function () { return $ this ->createMock (UserInterface::class); })))];
65
65
66
66
// blank password
67
- yield [$ this -> createEvent (new SelfValidatingPassport (new UserBadge ('test ' , function () { return $ this -> createMock (TestPasswordAuthenticatedUser::class ); }), [new PasswordUpgradeBadge ('' , $ this -> createPasswordUpgrader ())]))];
67
+ yield [self :: createEvent (new SelfValidatingPassport (new UserBadge ('test ' , function () { return new DummyTestPasswordAuthenticatedUser ( ); }), [new PasswordUpgradeBadge ('' , self :: createPasswordUpgrader ())]))];
68
68
}
69
69
70
70
/**
@@ -96,7 +96,7 @@ public function testUnsupportedPassport()
96
96
97
97
public function testUpgradeWithUpgrader ()
98
98
{
99
- $ passwordUpgrader = $ this ->createPasswordUpgrader ( );
99
+ $ passwordUpgrader = $ this ->getMockForAbstractClass (TestMigratingUserProvider::class );
100
100
$ passwordUpgrader ->expects ($ this ->once ())
101
101
->method ('upgradePassword ' )
102
102
->with ($ this ->user , 'new-hash ' )
@@ -133,14 +133,14 @@ public function testUserWithoutPassword()
133
133
$ this ->listener ->onLoginSuccess ($ event );
134
134
}
135
135
136
- private function createPasswordUpgrader ()
136
+ private static function createPasswordUpgrader ()
137
137
{
138
- return $ this -> getMockForAbstractClass (TestMigratingUserProvider::class );
138
+ return new DummyTestMigratingUserProvider ( );
139
139
}
140
140
141
- private function createEvent (PassportInterface $ passport )
141
+ private static function createEvent (PassportInterface $ passport )
142
142
{
143
- return new LoginSuccessEvent ($ this -> createMock (AuthenticatorInterface::class ), $ passport , $ this -> createMock (TokenInterface::class ), new Request (), null , 'main ' );
143
+ return new LoginSuccessEvent (new DummyAuthenticator ( ), $ passport , new DummyToken ( ), new Request (), null , 'main ' );
144
144
}
145
145
}
146
146
@@ -151,9 +151,62 @@ abstract public function upgradePassword(PasswordAuthenticatedUserInterface $use
151
151
abstract public function loadUserByIdentifier (string $ identifier ): UserInterface ;
152
152
}
153
153
154
+ class DummyTestMigratingUserProvider extends TestMigratingUserProvider
155
+ {
156
+ public function upgradePassword (PasswordAuthenticatedUserInterface $ user , string $ newHashedPassword ): void
157
+ {
158
+ }
159
+
160
+ public function loadUserByIdentifier (string $ identifier ): UserInterface
161
+ {
162
+ }
163
+
164
+ public function refreshUser (UserInterface $ user )
165
+ {
166
+ }
167
+
168
+ public function supportsClass (string $ class )
169
+ {
170
+ }
171
+
172
+ public function loadUserByUsername (string $ username )
173
+ {
174
+ }
175
+ }
176
+
154
177
abstract class TestPasswordAuthenticatedUser implements UserInterface, PasswordAuthenticatedUserInterface
155
178
{
156
179
abstract public function getPassword (): ?string ;
157
180
158
181
abstract public function getSalt (): ?string ;
159
182
}
183
+
184
+ class DummyTestPasswordAuthenticatedUser extends TestPasswordAuthenticatedUser
185
+ {
186
+ public function getPassword (): ?string
187
+ {
188
+ return null ;
189
+ }
190
+
191
+ public function getSalt (): ?string
192
+ {
193
+ return null ;
194
+ }
195
+
196
+ public function getRoles (): array
197
+ {
198
+ return [];
199
+ }
200
+
201
+ public function eraseCredentials ()
202
+ {
203
+ }
204
+
205
+ public function getUsername ()
206
+ {
207
+ }
208
+
209
+ public function getUserIdentifier (): string
210
+ {
211
+ }
212
+ }
0 commit comments