|  | 
| 34 | 34 | use OCP\Security\Bruteforce\IThrottler; | 
| 35 | 35 | use OCP\Security\ISecureRandom; | 
| 36 | 36 | use OCP\User\Events\PostLoginEvent; | 
|  | 37 | +use PHPUnit\Framework\ExpectationFailedException; | 
| 37 | 38 | use PHPUnit\Framework\MockObject\MockObject; | 
| 38 | 39 | use Psr\Log\LoggerInterface; | 
| 39 | 40 | use function array_diff; | 
| @@ -611,6 +612,45 @@ public function testTryTokenLoginSessionIdTokenNotFound(): void { | 
| 611 | 612 | 		self::assertFalse($loginResult); | 
| 612 | 613 | 	} | 
| 613 | 614 | 
 | 
|  | 615 | +	public function testTryTokenLoginNotAnAppPassword(): void { | 
|  | 616 | +		$request = $this->createMock(IRequest::class); | 
|  | 617 | +		$this->config->expects(self::once()) | 
|  | 618 | +			->method('getSystemValueString') | 
|  | 619 | +			->with('instanceid') | 
|  | 620 | +			->willReturn('abc123'); | 
|  | 621 | +		$request->method('getHeader')->with('Authorization')->willReturn(''); | 
|  | 622 | +		$request->method('getCookie')->with('abc123')->willReturn('abcde12345'); | 
|  | 623 | +		$this->session->expects(self::once()) | 
|  | 624 | +			->method('getId') | 
|  | 625 | +			->willReturn('abcde12345'); | 
|  | 626 | +		$dbToken = new PublicKeyToken(); | 
|  | 627 | +		$dbToken->setId(42); | 
|  | 628 | +		$dbToken->setUid('johnny'); | 
|  | 629 | +		$dbToken->setLoginName('johnny'); | 
|  | 630 | +		$dbToken->setLastCheck(0); | 
|  | 631 | +		$dbToken->setType(IToken::TEMPORARY_TOKEN); | 
|  | 632 | +		$dbToken->setRemember(IToken::REMEMBER); | 
|  | 633 | +		$this->tokenProvider->expects(self::any()) | 
|  | 634 | +			->method('getToken') | 
|  | 635 | +			->with('abcde12345') | 
|  | 636 | +			->willReturn($dbToken); | 
|  | 637 | +		$this->session->method('set') | 
|  | 638 | +			->willReturnCallback(function ($key, $value) { | 
|  | 639 | +				if ($key === 'app_password') { | 
|  | 640 | +					throw new ExpectationFailedException('app_password should not be set in session'); | 
|  | 641 | +				} | 
|  | 642 | +			}); | 
|  | 643 | +		$user = $this->createMock(IUser::class); | 
|  | 644 | +		$user->method('isEnabled')->willReturn(true); | 
|  | 645 | +		$this->manager->method('get') | 
|  | 646 | +			->with('johnny') | 
|  | 647 | +			->willReturn($user); | 
|  | 648 | + | 
|  | 649 | +		$loginResult = $this->userSession->tryTokenLogin($request); | 
|  | 650 | + | 
|  | 651 | +		self::assertTrue($loginResult); | 
|  | 652 | +	} | 
|  | 653 | + | 
| 614 | 654 | 	public function testRememberLoginValidToken(): void { | 
| 615 | 655 | 		$session = $this->createMock(Memory::class); | 
| 616 | 656 | 		$managerMethods = get_class_methods(Manager::class); | 
|  | 
0 commit comments