|
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; |
@@ -177,6 +178,30 @@ public function testDestroy() { |
177 | 178 | $this->assertEquals([], $this->controller->destroy($tokenId)); |
178 | 179 | } |
179 | 180 |
|
| 181 | + public function testDestroyExpired() { |
| 182 | + $tokenId = 124; |
| 183 | + $token = $this->createMock(DefaultToken::class); |
| 184 | + |
| 185 | + $token->expects($this->exactly(2)) |
| 186 | + ->method('getId') |
| 187 | + ->willReturn($tokenId); |
| 188 | + |
| 189 | + $token->expects($this->once()) |
| 190 | + ->method('getUID') |
| 191 | + ->willReturn($this->uid); |
| 192 | + |
| 193 | + $this->tokenProvider->expects($this->once()) |
| 194 | + ->method('getTokenById') |
| 195 | + ->with($this->equalTo($tokenId)) |
| 196 | + ->willThrowException(new ExpiredTokenException($token)); |
| 197 | + |
| 198 | + $this->tokenProvider->expects($this->once()) |
| 199 | + ->method('invalidateTokenById') |
| 200 | + ->with($this->uid, $tokenId); |
| 201 | + |
| 202 | + $this->assertSame([], $this->controller->destroy($tokenId)); |
| 203 | + } |
| 204 | + |
180 | 205 | public function testDestroyWrongUser() { |
181 | 206 | $tokenId = 124; |
182 | 207 | $token = $this->createMock(DefaultToken::class); |
@@ -307,6 +332,26 @@ public function testUpdateNoChange(): void { |
307 | 332 | $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password')); |
308 | 333 | } |
309 | 334 |
|
| 335 | + public function testUpdateExpired() { |
| 336 | + $tokenId = 42; |
| 337 | + $token = $this->createMock(DefaultToken::class); |
| 338 | + |
| 339 | + $token->expects($this->once()) |
| 340 | + ->method('getUID') |
| 341 | + ->willReturn($this->uid); |
| 342 | + |
| 343 | + $this->tokenProvider->expects($this->once()) |
| 344 | + ->method('getTokenById') |
| 345 | + ->with($this->equalTo($tokenId)) |
| 346 | + ->willThrowException(new ExpiredTokenException($token)); |
| 347 | + |
| 348 | + $this->tokenProvider->expects($this->once()) |
| 349 | + ->method('updateToken') |
| 350 | + ->with($this->equalTo($token)); |
| 351 | + |
| 352 | + $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password')); |
| 353 | + } |
| 354 | + |
310 | 355 | public function testUpdateTokenWrongUser() { |
311 | 356 | $tokenId = 42; |
312 | 357 | $token = $this->createMock(DefaultToken::class); |
|
0 commit comments