|  | 
| 1 |  | -<?php | 
|  | 1 | +<?php declare(strict_types=1); | 
|  | 2 | + | 
| 2 | 3 | /** | 
| 3 | 4 |  * @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl> | 
| 4 | 5 |  * | 
|  | 
| 23 | 24 | 
 | 
| 24 | 25 | namespace Test\Authentication\Token; | 
| 25 | 26 | 
 | 
|  | 27 | +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; | 
| 26 | 28 | use OC\Authentication\Exceptions\InvalidTokenException; | 
| 27 | 29 | use OC\Authentication\Exceptions\PasswordlessTokenException; | 
| 28 | 30 | use OC\Authentication\Token\DefaultToken; | 
| 29 | 31 | use OC\Authentication\Token\DefaultTokenProvider; | 
| 30 | 32 | use OC\Authentication\Token\Manager; | 
| 31 | 33 | use OC\Authentication\Token\PublicKeyToken; | 
| 32 |  | -use OC\Authentication\Token\PublicKeyTokenMapper; | 
| 33 | 34 | use OC\Authentication\Token\PublicKeyTokenProvider; | 
| 34 |  | -use OC\Authentication\Token\ExpiredTokenException; | 
| 35 | 35 | use OC\Authentication\Token\IToken; | 
| 36 |  | -use OCP\AppFramework\Db\DoesNotExistException; | 
| 37 |  | -use OCP\AppFramework\Utility\ITimeFactory; | 
| 38 |  | -use OCP\IConfig; | 
| 39 |  | -use OCP\ILogger; | 
| 40 |  | -use OCP\IUser; | 
| 41 |  | -use OCP\Security\ICrypto; | 
|  | 36 | +use PHPUnit\Framework\MockObject\MockObject; | 
| 42 | 37 | use Test\TestCase; | 
| 43 | 38 | 
 | 
| 44 | 39 | class ManagerTest extends TestCase { | 
| 45 | 40 | 
 | 
| 46 |  | -	/** @var PublicKeyTokenProvider|\PHPUnit_Framework_MockObject_MockObject */ | 
|  | 41 | +	/** @var PublicKeyTokenProvider|MockObject */ | 
| 47 | 42 | 	private $publicKeyTokenProvider; | 
| 48 |  | -	/** @var DefaultTokenProvider|\PHPUnit_Framework_MockObject_MockObject */ | 
|  | 43 | +	/** @var DefaultTokenProvider|MockObject */ | 
| 49 | 44 | 	private $defaultTokenProvider; | 
| 50 | 45 | 	/** @var Manager */ | 
| 51 | 46 | 	private $manager; | 
| @@ -92,6 +87,44 @@ public function testGenerateToken() { | 
| 92 | 87 | 		$this->assertSame($token, $actual); | 
| 93 | 88 | 	} | 
| 94 | 89 | 
 | 
|  | 90 | +	public function testGenerateConflictingToken() { | 
|  | 91 | +		/** @var MockObject|UniqueConstraintViolationException $exception */ | 
|  | 92 | +		$exception = $this->createMock(UniqueConstraintViolationException::class); | 
|  | 93 | +		$this->defaultTokenProvider->expects($this->never()) | 
|  | 94 | +			->method('generateToken'); | 
|  | 95 | + | 
|  | 96 | +		$token = new PublicKeyToken(); | 
|  | 97 | +		$token->setUid('uid'); | 
|  | 98 | + | 
|  | 99 | +		$this->publicKeyTokenProvider->expects($this->once()) | 
|  | 100 | +			->method('generateToken') | 
|  | 101 | +			->with( | 
|  | 102 | +				'token', | 
|  | 103 | +				'uid', | 
|  | 104 | +				'loginName', | 
|  | 105 | +				'password', | 
|  | 106 | +				'name', | 
|  | 107 | +				IToken::TEMPORARY_TOKEN, | 
|  | 108 | +				IToken::REMEMBER | 
|  | 109 | +			)->willThrowException($exception); | 
|  | 110 | +		$this->publicKeyTokenProvider->expects($this->once()) | 
|  | 111 | +			->method('getToken') | 
|  | 112 | +			->with('token') | 
|  | 113 | +			->willReturn($token); | 
|  | 114 | + | 
|  | 115 | +		$actual = $this->manager->generateToken( | 
|  | 116 | +			'token', | 
|  | 117 | +			'uid', | 
|  | 118 | +			'loginName', | 
|  | 119 | +			'password', | 
|  | 120 | +			'name', | 
|  | 121 | +			IToken::TEMPORARY_TOKEN, | 
|  | 122 | +			IToken::REMEMBER | 
|  | 123 | +		); | 
|  | 124 | + | 
|  | 125 | +		$this->assertSame($token, $actual); | 
|  | 126 | +	} | 
|  | 127 | + | 
| 95 | 128 | 	public function tokenData(): array { | 
| 96 | 129 | 		return [ | 
| 97 | 130 | 			[new DefaultToken()], | 
|  | 
0 commit comments