16
16
use Symfony \Component \HttpFoundation \RequestStack ;
17
17
use Symfony \Component \RateLimiter \RateLimiterFactory ;
18
18
use Symfony \Component \RateLimiter \Storage \InMemoryStorage ;
19
- use Symfony \Component \Security \Core \Authentication \ Token \ TokenInterface ;
19
+ use Symfony \Component \Security \Core \Exception \ AuthenticationException ;
20
20
use Symfony \Component \Security \Core \Exception \TooManyLoginAttemptsAuthenticationException ;
21
21
use Symfony \Component \Security \Http \Authenticator \AuthenticatorInterface ;
22
22
use Symfony \Component \Security \Http \Authenticator \Passport \Badge \UserBadge ;
23
23
use Symfony \Component \Security \Http \Authenticator \Passport \SelfValidatingPassport ;
24
24
use Symfony \Component \Security \Http \Event \CheckPassportEvent ;
25
- use Symfony \Component \Security \Http \Event \LoginSuccessEvent ;
25
+ use Symfony \Component \Security \Http \Event \LoginFailureEvent ;
26
26
use Symfony \Component \Security \Http \EventListener \LoginThrottlingListener ;
27
27
use Symfony \Component \Security \Http \RateLimiter \DefaultLoginRateLimiter ;
28
28
@@ -61,12 +61,7 @@ public function testPreventsLoginWhenOverLocalThreshold()
61
61
62
62
for ($ i = 0 ; $ i < 3 ; ++$ i ) {
63
63
$ this ->listener ->checkPassport ($ this ->createCheckPassportEvent ($ passport ));
64
- }
65
-
66
- $ this ->listener ->onSuccessfulLogin ($ this ->createLoginSuccessfulEvent ($ passport ));
67
-
68
- for ($ i = 0 ; $ i < 3 ; ++$ i ) {
69
- $ this ->listener ->checkPassport ($ this ->createCheckPassportEvent ($ passport ));
64
+ $ this ->listener ->onFailedLogin ($ this ->createLoginFailedEvent ($ passport ));
70
65
}
71
66
72
67
$ this ->expectException (TooManyLoginAttemptsAuthenticationException::class);
@@ -82,6 +77,7 @@ public function testPreventsLoginWithMultipleCase()
82
77
83
78
for ($ i = 0 ; $ i < 3 ; ++$ i ) {
84
79
$ this ->listener ->checkPassport ($ this ->createCheckPassportEvent ($ passports [$ i % 3 ]));
80
+ $ this ->listener ->onFailedLogin ($ this ->createLoginFailedEvent ($ passports [$ i % 3 ]));
85
81
}
86
82
87
83
$ this ->expectException (TooManyLoginAttemptsAuthenticationException::class);
@@ -97,6 +93,7 @@ public function testPreventsLoginWhenOverGlobalThreshold()
97
93
98
94
for ($ i = 0 ; $ i < 6 ; ++$ i ) {
99
95
$ this ->listener ->checkPassport ($ this ->createCheckPassportEvent ($ passports [$ i % 2 ]));
96
+ $ this ->listener ->onFailedLogin ($ this ->createLoginFailedEvent ($ passports [$ i % 2 ]));
100
97
}
101
98
102
99
$ this ->expectException (TooManyLoginAttemptsAuthenticationException::class);
@@ -108,9 +105,9 @@ private function createPassport($username)
108
105
return new SelfValidatingPassport (new UserBadge ($ username ));
109
106
}
110
107
111
- private function createLoginSuccessfulEvent ($ passport )
108
+ private function createLoginFailedEvent ($ passport )
112
109
{
113
- return new LoginSuccessEvent ($ this ->createMock (AuthenticatorInterface ::class), $ passport , $ this ->createMock (TokenInterface ::class), $ this ->requestStack ->getCurrentRequest (), null , 'main ' );
110
+ return new LoginFailureEvent ($ this ->createMock (AuthenticationException ::class), $ this ->createMock (AuthenticatorInterface ::class), $ this ->requestStack ->getCurrentRequest (), null , 'main ' , $ passport );
114
111
}
115
112
116
113
private function createCheckPassportEvent ($ passport )
0 commit comments