|
23 | 23 |
|
24 | 24 | use OC\AppFramework\Http; |
25 | 25 | use OC\Authentication\Exceptions\InvalidTokenException; |
| 26 | +use OC\Authentication\Exceptions\ExpiredTokenException; |
26 | 27 | use OC\Authentication\Token\DefaultToken; |
27 | 28 | use OC\Authentication\Token\IProvider; |
28 | 29 | use OC\Authentication\Token\IToken; |
@@ -188,6 +189,30 @@ public function testDestroy() { |
188 | 189 | $this->assertEquals([], $this->controller->destroy($tokenId)); |
189 | 190 | } |
190 | 191 |
|
| 192 | + public function testDestroyExpired() { |
| 193 | + $tokenId = 124; |
| 194 | + $token = $this->createMock(DefaultToken::class); |
| 195 | + |
| 196 | + $token->expects($this->exactly(2)) |
| 197 | + ->method('getId') |
| 198 | + ->willReturn($tokenId); |
| 199 | + |
| 200 | + $token->expects($this->once()) |
| 201 | + ->method('getUID') |
| 202 | + ->willReturn($this->uid); |
| 203 | + |
| 204 | + $this->tokenProvider->expects($this->once()) |
| 205 | + ->method('getTokenById') |
| 206 | + ->with($this->equalTo($tokenId)) |
| 207 | + ->willThrowException(new ExpiredTokenException($token)); |
| 208 | + |
| 209 | + $this->tokenProvider->expects($this->once()) |
| 210 | + ->method('invalidateTokenById') |
| 211 | + ->with($this->uid, $tokenId); |
| 212 | + |
| 213 | + $this->assertSame([], $this->controller->destroy($tokenId)); |
| 214 | + } |
| 215 | + |
191 | 216 | public function testDestroyWrongUser() { |
192 | 217 | $tokenId = 124; |
193 | 218 | $token = $this->createMock(DefaultToken::class); |
@@ -320,6 +345,26 @@ public function testUpdateNoChange(): void { |
320 | 345 | $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password')); |
321 | 346 | } |
322 | 347 |
|
| 348 | + public function testUpdateExpired() { |
| 349 | + $tokenId = 42; |
| 350 | + $token = $this->createMock(DefaultToken::class); |
| 351 | + |
| 352 | + $token->expects($this->once()) |
| 353 | + ->method('getUID') |
| 354 | + ->willReturn($this->uid); |
| 355 | + |
| 356 | + $this->tokenProvider->expects($this->once()) |
| 357 | + ->method('getTokenById') |
| 358 | + ->with($this->equalTo($tokenId)) |
| 359 | + ->willThrowException(new ExpiredTokenException($token)); |
| 360 | + |
| 361 | + $this->tokenProvider->expects($this->once()) |
| 362 | + ->method('updateToken') |
| 363 | + ->with($this->equalTo($token)); |
| 364 | + |
| 365 | + $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password')); |
| 366 | + } |
| 367 | + |
323 | 368 | public function testUpdateTokenWrongUser() { |
324 | 369 | $tokenId = 42; |
325 | 370 | $token = $this->createMock(DefaultToken::class); |
|
0 commit comments