|
1 | 1 | <?php |
| 2 | + |
2 | 3 | /** |
3 | 4 | * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> |
4 | 5 | * This file is licensed under the Affero General Public License version 3 or |
|
10 | 11 |
|
11 | 12 | use OC\AppFramework\Http\Request; |
12 | 13 | use OC\Authentication\Events\LoginFailed; |
| 14 | +use OC\Authentication\Exceptions\InvalidTokenException; |
13 | 15 | use OC\Authentication\Token\DefaultTokenMapper; |
14 | 16 | use OC\Authentication\Token\DefaultTokenProvider; |
15 | 17 | use OC\Authentication\Token\IProvider; |
@@ -489,16 +491,18 @@ public function testLogClientInWithTokenPassword() { |
489 | 491 | $manager = $this->createMock(Manager::class); |
490 | 492 | $session = $this->createMock(ISession::class); |
491 | 493 | $request = $this->createMock(IRequest::class); |
| 494 | + $token = $this->createMock(IToken::class); |
492 | 495 |
|
493 | 496 | /** @var \OC\User\Session $userSession */ |
494 | 497 | $userSession = $this->getMockBuilder(Session::class) |
495 | 498 | ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher]) |
496 | | - ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser']) |
| 499 | + ->onlyMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser']) |
497 | 500 | ->getMock(); |
498 | 501 |
|
499 | | - $userSession->expects($this->once()) |
500 | | - ->method('isTokenPassword') |
501 | | - ->willReturn(true); |
| 502 | + $this->tokenProvider->expects($this->once()) |
| 503 | + ->method('getToken') |
| 504 | + ->with('I-AM-AN-APP-PASSWORD') |
| 505 | + ->willReturn($token); |
502 | 506 | $userSession->expects($this->once()) |
503 | 507 | ->method('login') |
504 | 508 | ->with('john', 'I-AM-AN-APP-PASSWORD') |
@@ -1032,7 +1036,7 @@ public function testTryTokenLoginWithDisabledUser() { |
1032 | 1036 | ->method('getHeader') |
1033 | 1037 | ->with('Authorization') |
1034 | 1038 | ->willReturn('Bearer xxxxx'); |
1035 | | - $this->tokenProvider->expects($this->once()) |
| 1039 | + $this->tokenProvider->expects($this->atLeastOnce()) |
1036 | 1040 | ->method('getToken') |
1037 | 1041 | ->with('xxxxx') |
1038 | 1042 | ->willReturn($token); |
@@ -1478,16 +1482,18 @@ public function testLogClientInThrottlerUsername() { |
1478 | 1482 | $manager = $this->createMock(Manager::class); |
1479 | 1483 | $session = $this->createMock(ISession::class); |
1480 | 1484 | $request = $this->createMock(IRequest::class); |
| 1485 | + $token = $this->createMock(IToken::class); |
1481 | 1486 |
|
1482 | 1487 | /** @var Session $userSession */ |
1483 | 1488 | $userSession = $this->getMockBuilder(Session::class) |
1484 | 1489 | ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher]) |
1485 | | - ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser']) |
| 1490 | + ->onlyMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser']) |
1486 | 1491 | ->getMock(); |
1487 | 1492 |
|
1488 | | - $userSession->expects($this->once()) |
1489 | | - ->method('isTokenPassword') |
1490 | | - ->willReturn(true); |
| 1493 | + $this->tokenProvider->expects($this->once()) |
| 1494 | + ->method('getToken') |
| 1495 | + ->with('I-AM-AN-PASSWORD') |
| 1496 | + ->willReturn($token); |
1491 | 1497 | $userSession->expects($this->once()) |
1492 | 1498 | ->method('login') |
1493 | 1499 | ->with('john', 'I-AM-AN-PASSWORD') |
@@ -1528,12 +1534,13 @@ public function testLogClientInThrottlerEmail() { |
1528 | 1534 | /** @var Session $userSession */ |
1529 | 1535 | $userSession = $this->getMockBuilder(Session::class) |
1530 | 1536 | ->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher]) |
1531 | | - ->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser']) |
| 1537 | + ->onlyMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser']) |
1532 | 1538 | ->getMock(); |
1533 | 1539 |
|
1534 | | - $userSession->expects($this->once()) |
1535 | | - ->method('isTokenPassword') |
1536 | | - ->willReturn(true); |
| 1540 | + $this->tokenProvider->expects($this->once()) |
| 1541 | + ->method('getToken') |
| 1542 | + ->with('I-AM-AN-PASSWORD') |
| 1543 | + ->willThrowException(new InvalidTokenException()); |
1537 | 1544 | $userSession->expects($this->once()) |
1538 | 1545 | ->method('login') |
1539 | 1546 | ->with('john@foo.bar', 'I-AM-AN-PASSWORD') |
|
0 commit comments