File tree 2 files changed +21
-2
lines changed
src/Symfony/Component/Security/Core
Tests/Authentication/Provider
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 18
18
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
19
19
use Symfony \Component \Security \Core \Exception \AuthenticationServiceException ;
20
20
use Symfony \Component \Security \Core \Exception \BadCredentialsException ;
21
+ use Symfony \Component \Security \Core \Exception \CustomUserMessageAccountStatusException ;
21
22
use Symfony \Component \Security \Core \Exception \UserNotFoundException ;
22
23
use Symfony \Component \Security \Core \User \UserCheckerInterface ;
23
24
use Symfony \Component \Security \Core \User \UserInterface ;
@@ -84,8 +85,8 @@ public function authenticate(TokenInterface $token)
84
85
$ this ->userChecker ->checkPreAuth ($ user );
85
86
$ this ->checkAuthentication ($ user , $ token );
86
87
$ this ->userChecker ->checkPostAuth ($ user );
87
- } catch (AccountStatusException $ e ) {
88
- if ($ this ->hideUserNotFoundExceptions ) {
88
+ } catch (AccountStatusException | BadCredentialsException $ e ) {
89
+ if ($ this ->hideUserNotFoundExceptions && ! $ e instanceof CustomUserMessageAccountStatusException ) {
89
90
throw new BadCredentialsException ('Bad credentials. ' , 0 , $ e );
90
91
}
91
92
Original file line number Diff line number Diff line change @@ -69,6 +69,24 @@ public function testAuthenticateWhenUsernameIsNotFoundAndHideIsTrue()
69
69
$ provider ->authenticate ($ this ->getSupportedToken ());
70
70
}
71
71
72
+ public function testAuthenticateWhenCredentialsAreInvalidAndHideIsTrue ()
73
+ {
74
+ $ provider = $ this ->getProvider ();
75
+ $ provider ->expects ($ this ->once ())
76
+ ->method ('retrieveUser ' )
77
+ ->willReturn ($ this ->createMock (UserInterface::class))
78
+ ;
79
+ $ provider ->expects ($ this ->once ())
80
+ ->method ('checkAuthentication ' )
81
+ ->willThrowException (new BadCredentialsException ())
82
+ ;
83
+
84
+ $ this ->expectException (BadCredentialsException::class);
85
+ $ this ->expectExceptionMessage ('Bad credentials. ' );
86
+
87
+ $ provider ->authenticate ($ this ->getSupportedToken ());
88
+ }
89
+
72
90
public function testAuthenticateWhenProviderDoesNotReturnAnUserInterface ()
73
91
{
74
92
$ this ->expectException (AuthenticationServiceException::class);
You can’t perform that action at this time.
0 commit comments