|
32 | 32 | use OCP\Lockdown\ILockdownManager; |
33 | 33 | use OCP\Security\ISecureRandom; |
34 | 34 | use OCP\User\Events\PostLoginEvent; |
| 35 | +use PHPUnit\Framework\ExpectationFailedException; |
35 | 36 | use PHPUnit\Framework\MockObject\MockObject; |
36 | 37 | use Psr\Log\LoggerInterface; |
37 | 38 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
@@ -533,6 +534,45 @@ public function testTryTokenLoginSessionIdTokenNotFound(): void { |
533 | 534 | self::assertFalse($loginResult); |
534 | 535 | } |
535 | 536 |
|
| 537 | + public function testTryTokenLoginNotAnAppPassword(): void { |
| 538 | + $request = $this->createMock(IRequest::class); |
| 539 | + $this->config->expects(self::once()) |
| 540 | + ->method('getSystemValueString') |
| 541 | + ->with('instanceid') |
| 542 | + ->willReturn('abc123'); |
| 543 | + $request->method('getHeader')->with('Authorization')->willReturn(''); |
| 544 | + $request->method('getCookie')->with('abc123')->willReturn('abcde12345'); |
| 545 | + $this->session->expects(self::once()) |
| 546 | + ->method('getId') |
| 547 | + ->willReturn('abcde12345'); |
| 548 | + $dbToken = new PublicKeyToken(); |
| 549 | + $dbToken->setId(42); |
| 550 | + $dbToken->setUid('johnny'); |
| 551 | + $dbToken->setLoginName('johnny'); |
| 552 | + $dbToken->setLastCheck(0); |
| 553 | + $dbToken->setType(IToken::TEMPORARY_TOKEN); |
| 554 | + $dbToken->setRemember(IToken::REMEMBER); |
| 555 | + $this->tokenProvider->expects(self::any()) |
| 556 | + ->method('getToken') |
| 557 | + ->with('abcde12345') |
| 558 | + ->willReturn($dbToken); |
| 559 | + $this->session->method('set') |
| 560 | + ->willReturnCallback(function ($key, $value) { |
| 561 | + if ($key === 'app_password') { |
| 562 | + throw new ExpectationFailedException('app_password should not be set in session'); |
| 563 | + } |
| 564 | + }); |
| 565 | + $user = $this->createMock(IUser::class); |
| 566 | + $user->method('isEnabled')->willReturn(true); |
| 567 | + $this->manager->method('get') |
| 568 | + ->with('johnny') |
| 569 | + ->willReturn($user); |
| 570 | + |
| 571 | + $loginResult = $this->userSession->tryTokenLogin($request); |
| 572 | + |
| 573 | + self::assertTrue($loginResult); |
| 574 | + } |
| 575 | + |
536 | 576 | public function testRememberLoginValidToken() { |
537 | 577 | $session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock(); |
538 | 578 | $managerMethods = get_class_methods(Manager::class); |
|
0 commit comments