File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Tests/Authentication/Provider Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1818use Symfony \Component \Security \Core \Exception \AuthenticationException ;
1919use Symfony \Component \Security \Core \Exception \AuthenticationServiceException ;
2020use Symfony \Component \Security \Core \Exception \BadCredentialsException ;
21+ use Symfony \Component \Security \Core \Exception \CustomUserMessageAccountStatusException ;
2122use Symfony \Component \Security \Core \Exception \UsernameNotFoundException ;
2223use Symfony \Component \Security \Core \User \UserCheckerInterface ;
2324use Symfony \Component \Security \Core \User \UserInterface ;
@@ -80,8 +81,8 @@ public function authenticate(TokenInterface $token)
8081 $ this ->userChecker ->checkPreAuth ($ user );
8182 $ this ->checkAuthentication ($ user , $ token );
8283 $ this ->userChecker ->checkPostAuth ($ user );
83- } catch (AccountStatusException $ e ) {
84- if ($ this ->hideUserNotFoundExceptions ) {
84+ } catch (AccountStatusException | BadCredentialsException $ e ) {
85+ if ($ this ->hideUserNotFoundExceptions && ! $ e instanceof CustomUserMessageAccountStatusException ) {
8586 throw new BadCredentialsException ('Bad credentials. ' , 0 , $ e );
8687 }
8788
Original file line number Diff line number Diff line change @@ -68,6 +68,24 @@ public function testAuthenticateWhenUsernameIsNotFoundAndHideIsTrue()
6868 $ provider ->authenticate ($ this ->getSupportedToken ());
6969 }
7070
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+
7189 public function testAuthenticateWhenProviderDoesNotReturnAnUserInterface ()
7290 {
7391 $ this ->expectException (AuthenticationServiceException::class);
You can’t perform that action at this time.
0 commit comments