use OC\AppFramework\Http;
use OC\Authentication\Exceptions\ExpiredTokenException;
use OC\Authentication\Exceptions\InvalidTokenException;
-use OC\Authentication\Token\DefaultToken;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Authentication\Token\IWipeableToken;
+use OC\Authentication\Token\PublicKeyToken;
use OC\Authentication\Token\RemoteWipe;
use OCA\Settings\Controller\AuthSettingsController;
use OCP\Activity\IEvent;
public function testDestroy() {
$tokenId = 124;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$this->mockGetTokenById($tokenId, $token);
$this->mockActivityManager();
public function testDestroyExpired() {
$tokenId = 124;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$token->expects($this->exactly(2))
->method('getId')
public function testDestroyWrongUser() {
$tokenId = 124;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$this->mockGetTokenById($tokenId, $token);
*/
public function testUpdateRename(string $name, string $newName): void {
$tokenId = 42;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$this->mockGetTokenById($tokenId, $token);
$this->mockActivityManager();
*/
public function testUpdateFilesystemScope(bool $filesystem, bool $newFilesystem): void {
$tokenId = 42;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$this->mockGetTokenById($tokenId, $token);
$this->mockActivityManager();
public function testUpdateNoChange(): void {
$tokenId = 42;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$this->mockGetTokenById($tokenId, $token);
public function testUpdateExpired() {
$tokenId = 42;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$token->expects($this->once())
->method('getUID')
public function testUpdateTokenWrongUser() {
$tokenId = 42;
- $token = $this->createMock(DefaultToken::class);
+ $token = $this->createMock(PublicKeyToken::class);
$this->mockGetTokenById($tokenId, $token);
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordlessTokenException;
-use OC\Authentication\Token\DefaultToken;
-use OC\Authentication\Token\DefaultTokenProvider;
use OC\Authentication\Token\IToken;
use OC\Authentication\Token\Manager;
use OC\Authentication\Token\PublicKeyToken;
/** @var PublicKeyTokenProvider|MockObject */
private $publicKeyTokenProvider;
- /** @var DefaultTokenProvider|MockObject */
- private $defaultTokenProvider;
/** @var Manager */
private $manager;
parent::setUp();
$this->publicKeyTokenProvider = $this->createMock(PublicKeyTokenProvider::class);
- $this->defaultTokenProvider = $this->createMock(DefaultTokenProvider::class);
$this->manager = new Manager(
- $this->defaultTokenProvider,
$this->publicKeyTokenProvider
);
}
public function testGenerateToken() {
- $this->defaultTokenProvider->expects($this->never())
- ->method('generateToken');
-
$token = new PublicKeyToken();
$this->publicKeyTokenProvider->expects($this->once())
public function testGenerateConflictingToken() {
/** @var MockObject|UniqueConstraintViolationException $exception */
$exception = $this->createMock(UniqueConstraintViolationException::class);
- $this->defaultTokenProvider->expects($this->never())
- ->method('generateToken');
$token = new PublicKeyToken();
$token->setUid('uid');
public function tokenData(): array {
return [
- [new DefaultToken()],
[new PublicKeyToken()],
[$this->createMock(IToken::class)],
];
}
protected function setNoCall(IToken $token) {
- if (!($token instanceof DefaultToken)) {
- $this->defaultTokenProvider->expects($this->never())
- ->method($this->anything());
- }
-
if (!($token instanceof PublicKeyToken)) {
$this->publicKeyTokenProvider->expects($this->never())
->method($this->anything());
}
protected function setCall(IToken $token, string $function, $return = null) {
- if ($token instanceof DefaultToken) {
- $this->defaultTokenProvider->expects($this->once())
- ->method($function)
- ->with($token)
- ->willReturn($return);
- }
-
if ($token instanceof PublicKeyToken) {
$this->publicKeyTokenProvider->expects($this->once())
->method($function)
}
protected function setException(IToken $token) {
- if (!($token instanceof DefaultToken) && !($token instanceof PublicKeyToken)) {
+ if (!($token instanceof PublicKeyToken)) {
$this->expectException(InvalidTokenException::class);
}
}
}
public function testInvalidateTokens() {
- $this->defaultTokenProvider->expects($this->once())
- ->method('invalidateToken')
- ->with('token');
-
$this->publicKeyTokenProvider->expects($this->once())
->method('invalidateToken')
->with('token');
}
public function testInvalidateTokenById() {
- $this->defaultTokenProvider->expects($this->once())
- ->method('invalidateTokenById')
- ->with('uid', 42);
-
$this->publicKeyTokenProvider->expects($this->once())
->method('invalidateTokenById')
->with('uid', 42);
}
public function testInvalidateOldTokens() {
- $this->defaultTokenProvider->expects($this->once())
- ->method('invalidateOldTokens');
-
$this->publicKeyTokenProvider->expects($this->once())
->method('invalidateOldTokens');
}
public function testGetTokenByUser() {
- $t1 = new DefaultToken();
- $t2 = new DefaultToken();
- $t3 = new PublicKeyToken();
- $t4 = new PublicKeyToken();
-
- $this->defaultTokenProvider
- ->method('getTokenByUser')
- ->willReturn([$t1, $t2]);
+ $t1 = new PublicKeyToken();
+ $t2 = new PublicKeyToken();
$this->publicKeyTokenProvider
->method('getTokenByUser')
- ->willReturn([$t3, $t4]);
+ ->willReturn([$t1, $t2]);
$result = $this->manager->getTokenByUser('uid');
- $this->assertEquals([$t1, $t2, $t3, $t4], $result);
+ $this->assertEquals([$t1, $t2], $result);
}
public function testRenewSessionTokenPublicKey() {
- $this->defaultTokenProvider->expects($this->never())
- ->method($this->anything());
-
$this->publicKeyTokenProvider->expects($this->once())
->method('renewSessionToken')
->with('oldId', 'newId');
$this->manager->renewSessionToken('oldId', 'newId');
}
- public function testRenewSessionTokenDefault() {
- $this->publicKeyTokenProvider->expects($this->once())
- ->method('renewSessionToken')
- ->with('oldId', 'newId')
- ->willThrowException(new InvalidTokenException());
-
- $this->defaultTokenProvider->expects($this->once())
- ->method('renewSessionToken')
- ->with('oldId', 'newId');
-
- $this->manager->renewSessionToken('oldId', 'newId');
- }
-
public function testRenewSessionInvalid() {
$this->publicKeyTokenProvider->expects($this->once())
->method('renewSessionToken')
->with('oldId', 'newId')
->willThrowException(new InvalidTokenException());
- $this->defaultTokenProvider->expects($this->once())
- ->method('renewSessionToken')
- ->with('oldId', 'newId')
- ->willThrowException(new InvalidTokenException());
-
$this->expectException(InvalidTokenException::class);
$this->manager->renewSessionToken('oldId', 'newId');
}
->with(42)
->willReturn($token);
- $this->defaultTokenProvider->expects($this->never())
- ->method($this->anything());
-
-
- $this->assertSame($token, $this->manager->getTokenById(42));
- }
-
- public function testGetTokenByIdDefault() {
- $token = $this->createMock(IToken::class);
-
- $this->publicKeyTokenProvider->expects($this->once())
- ->method('getTokenById')
- ->with(42)
- ->willThrowException(new InvalidTokenException());
-
- $this->defaultTokenProvider->expects($this->once())
- ->method('getTokenById')
- ->with(42)
- ->willReturn($token);
-
$this->assertSame($token, $this->manager->getTokenById(42));
}
->with(42)
->willThrowException(new InvalidTokenException());
- $this->defaultTokenProvider->expects($this->once())
- ->method('getTokenById')
- ->with(42)
- ->willThrowException(new InvalidTokenException());
-
$this->expectException(InvalidTokenException::class);
$this->manager->getTokenById(42);
}
public function testGetTokenPublicKey() {
$token = new PublicKeyToken();
- $this->defaultTokenProvider->expects($this->never())
- ->method($this->anything());
-
$this->publicKeyTokenProvider
->method('getToken')
->with('tokenId')
}
public function testGetTokenInvalid() {
- $this->defaultTokenProvider
- ->method('getToken')
- ->with('tokenId')
- ->willThrowException(new InvalidTokenException());
-
$this->publicKeyTokenProvider
->method('getToken')
->with('tokenId')
$this->manager->getToken('tokenId');
}
- public function testGetTokenConvertPassword() {
- $oldToken = new DefaultToken();
- $newToken = new PublicKeyToken();
-
- $this->publicKeyTokenProvider
- ->method('getToken')
- ->with('tokenId')
- ->willThrowException(new InvalidTokenException());
-
- $this->defaultTokenProvider
- ->method('getToken')
- ->willReturn($oldToken);
-
- $this->defaultTokenProvider
- ->method('getPassword')
- ->with($oldToken, 'tokenId')
- ->willReturn('password');
-
- $this->publicKeyTokenProvider
- ->method('convertToken')
- ->with($oldToken, 'tokenId', 'password')
- ->willReturn($newToken);
-
- $this->assertSame($newToken, $this->manager->getToken('tokenId'));
- }
-
- public function testGetTokenConvertNoPassword() {
- $oldToken = new DefaultToken();
- $newToken = new PublicKeyToken();
-
- $this->publicKeyTokenProvider
- ->method('getToken')
- ->with('tokenId')
- ->willThrowException(new InvalidTokenException());
-
- $this->defaultTokenProvider
- ->method('getToken')
- ->willReturn($oldToken);
-
- $this->defaultTokenProvider
- ->method('getPassword')
- ->with($oldToken, 'tokenId')
- ->willThrowException(new PasswordlessTokenException());
-
- $this->publicKeyTokenProvider
- ->method('convertToken')
- ->with($oldToken, 'tokenId', null)
- ->willReturn($newToken);
-
- $this->assertSame($newToken, $this->manager->getToken('tokenId'));
- }
-
public function testRotateInvalid() {
$this->expectException(InvalidTokenException::class);
$this->manager->rotate($this->createMock(IToken::class), 'oldId', 'newId');
$this->assertSame($token, $this->manager->rotate($token, 'oldId', 'newId'));
}
- public function testRotateConvertPassword() {
- $oldToken = new DefaultToken();
- $newToken = new PublicKeyToken();
-
- $this->defaultTokenProvider
- ->method('getPassword')
- ->with($oldToken, 'oldId')
- ->willReturn('password');
-
- $this->publicKeyTokenProvider
- ->method('convertToken')
- ->with($oldToken, 'newId', 'password')
- ->willReturn($newToken);
-
- $this->assertSame($newToken, $this->manager->rotate($oldToken, 'oldId', 'newId'));
- }
-
- public function testRotateConvertNoPassword() {
- $oldToken = new DefaultToken();
- $newToken = new PublicKeyToken();
-
- $this->defaultTokenProvider
- ->method('getPassword')
- ->with($oldToken, 'oldId')
- ->willThrowException(new PasswordlessTokenException());
-
- $this->publicKeyTokenProvider
- ->method('convertToken')
- ->with($oldToken, 'newId', null)
- ->willReturn($newToken);
-
- $this->assertSame($newToken, $this->manager->rotate($oldToken, 'oldId', 'newId'));
- }
-
- public function testMarkPasswordInvalidDefault() {
- $token = $this->createMock(DefaultToken::class);
-
- $this->defaultTokenProvider->expects($this->once())
- ->method('markPasswordInvalid')
- ->with($token, 'tokenId');
- $this->publicKeyTokenProvider->expects($this->never())
- ->method($this->anything());
-
- $this->manager->markPasswordInvalid($token, 'tokenId');
- }
-
public function testMarkPasswordInvalidPublicKey() {
$token = $this->createMock(PublicKeyToken::class);
$this->publicKeyTokenProvider->expects($this->once())
->method('markPasswordInvalid')
->with($token, 'tokenId');
- $this->defaultTokenProvider->expects($this->never())
- ->method($this->anything());
$this->manager->markPasswordInvalid($token, 'tokenId');
}
}
public function testUpdatePasswords() {
- $this->defaultTokenProvider->expects($this->once())
- ->method('updatePasswords')
- ->with('uid', 'pass');
$this->publicKeyTokenProvider->expects($this->once())
->method('updatePasswords')
->with('uid', 'pass');