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