@@ -60,7 +60,9 @@ public function testAuthenticate()
60
60
// checkCredentials is called
61
61
$ authenticatorB ->expects ($ this ->once ())
62
62
->method ('checkCredentials ' )
63
- ->with ($ enteredCredentials , $ mockedUser );
63
+ ->with ($ enteredCredentials , $ mockedUser )
64
+ // authentication works!
65
+ ->will ($ this ->returnValue (true ));
64
66
$ authedToken = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\TokenInterface ' );
65
67
$ authenticatorB ->expects ($ this ->once ())
66
68
->method ('createAuthenticatedToken ' )
@@ -80,6 +82,39 @@ public function testAuthenticate()
80
82
$ this ->assertSame ($ authedToken , $ actualAuthedToken );
81
83
}
82
84
85
+ /**
86
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
87
+ */
88
+ public function testCheckCredentialsReturningNonTrueFailsAuthentication ()
89
+ {
90
+ $ providerKey = 'my_uncool_firewall ' ;
91
+
92
+ $ authenticator = $ this ->getMock ('Symfony\Component\Security\Guard\GuardAuthenticatorInterface ' );
93
+
94
+ // make sure the authenticator is used
95
+ $ this ->preAuthenticationToken ->expects ($ this ->any ())
96
+ ->method ('getGuardProviderKey ' )
97
+ // the 0 index, to match the only authenticator
98
+ ->will ($ this ->returnValue ('my_uncool_firewall_0 ' ));
99
+
100
+ $ this ->preAuthenticationToken ->expects ($ this ->atLeastOnce ())
101
+ ->method ('getCredentials ' )
102
+ ->will ($ this ->returnValue ('non-null-value ' ));
103
+
104
+ $ mockedUser = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
105
+ $ authenticator ->expects ($ this ->once ())
106
+ ->method ('getUser ' )
107
+ ->will ($ this ->returnValue ($ mockedUser ));
108
+ // checkCredentials is called
109
+ $ authenticator ->expects ($ this ->once ())
110
+ ->method ('checkCredentials ' )
111
+ // authentication fails :(
112
+ ->will ($ this ->returnValue (null ));
113
+
114
+ $ provider = new GuardAuthenticationProvider (array ($ authenticator ), $ this ->userProvider , $ providerKey , $ this ->userChecker );
115
+ $ provider ->authenticate ($ this ->preAuthenticationToken );
116
+ }
117
+
83
118
/**
84
119
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationExpiredException
85
120
*/
0 commit comments