|
@@ 158-171 (lines=14) @@
|
| 155 |
|
/** |
| 156 |
|
* @test |
| 157 |
|
*/ |
| 158 |
|
public function authenticateWillReturnAuthenticatedToken() |
| 159 |
|
{ |
| 160 |
|
$jwtAuthenticationProvider = new JwtAuthenticationProvider($this->standardUserProviderMock, $this->keys); |
| 161 |
|
$authToken = new JwtAuthenticationToken([], self::TEST_TOKEN); |
| 162 |
|
|
| 163 |
|
/** @var \PHPUnit_Framework_MockObject_MockObject $mock */ |
| 164 |
|
$mock = $this->standardUserProviderMock; |
| 165 |
|
$mock |
| 166 |
|
->expects($this->once()) |
| 167 |
|
->method('loadUserByUsername') |
| 168 |
|
->willReturn(new User('john', 'hi there')); |
| 169 |
|
|
| 170 |
|
$this->assertInstanceOf(JwtAuthenticatedToken::class, $jwtAuthenticationProvider->authenticate($authToken)); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
/** |
| 174 |
|
* @test |
|
@@ 176-190 (lines=15) @@
|
| 173 |
|
/** |
| 174 |
|
* @test |
| 175 |
|
*/ |
| 176 |
|
public function authenticateTokenWillSetUserFetchedFromUserProviderOnToken() |
| 177 |
|
{ |
| 178 |
|
$jwtAuthenticationProvider = new JwtAuthenticationProvider($this->standardUserProviderMock, $this->keys); |
| 179 |
|
$authToken = new JwtAuthenticationToken([], self::TEST_TOKEN); |
| 180 |
|
|
| 181 |
|
/** @var \PHPUnit_Framework_MockObject_MockObject $mock */ |
| 182 |
|
$mock = $this->standardUserProviderMock; |
| 183 |
|
$mock |
| 184 |
|
->expects($this->once()) |
| 185 |
|
->method('loadUserByUsername') |
| 186 |
|
->with('john') |
| 187 |
|
->willReturn(new User('john', 'hi there')); |
| 188 |
|
|
| 189 |
|
$jwtAuthenticationProvider->authenticate($authToken); |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
/** |
| 193 |
|
* @test |
|
@@ 210-226 (lines=17) @@
|
| 207 |
|
* @test |
| 208 |
|
* @expectedException \UnexpectedValueException |
| 209 |
|
*/ |
| 210 |
|
public function authenticateTokenWillWillNotCallUserProviderWhenTokenStringInvalid() |
| 211 |
|
{ |
| 212 |
|
$jwtAuthenticationProvider = new JwtAuthenticationProvider($this->standardUserProviderMock, $this->keys); |
| 213 |
|
$authToken = new JwtAuthenticationToken([], 'invalid'); |
| 214 |
|
|
| 215 |
|
/** @var \PHPUnit_Framework_MockObject_MockObject $mock */ |
| 216 |
|
$mock = $this->standardUserProviderMock; |
| 217 |
|
$mock |
| 218 |
|
->expects($this->never()) |
| 219 |
|
->method('loadUserByUsername') |
| 220 |
|
->with('john') |
| 221 |
|
->willReturn(new User('john', 'hi there')); |
| 222 |
|
|
| 223 |
|
$this->expectException(BadCredentialsException::class); |
| 224 |
|
|
| 225 |
|
$jwtAuthenticationProvider->authenticate($authToken); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
/** |
| 229 |
|
* @test |