Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Jun 1, 2018
1 parent 29c5f86 commit cca529a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public function convertToken(DefaultToken $defaultToken, string $token, $passwor
$defaultToken->getRemember()
);

$pkToken->setExpires($defaultToken->getExpires());
$pkToken->setId($defaultToken->getId());

return $this->mapper->update($pkToken);
Expand Down
34 changes: 33 additions & 1 deletion tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordlessTokenException;
use OC\Authentication\Token\DefaultToken;
use OC\Authentication\Token\PublicKeyToken;
use OC\Authentication\Token\PublicKeyTokenMapper;
use OC\Authentication\Token\PublicKeyTokenProvider;
Expand Down Expand Up @@ -357,7 +358,7 @@ public function testGetInvalidToken() {
$this->callback(function (string $token) {
return hash('sha512', 'unhashedToken'.'1f4h9s') === $token;
})
)->willThrowException(new InvalidTokenException());
)->willThrowException(new DoesNotExistException('nope'));

$this->tokenProvider->getToken('unhashedToken');
}
Expand Down Expand Up @@ -471,4 +472,35 @@ public function testRotateNoPassword() {
$this->assertNotSame($newPrivate, $oldPrivate);
$this->assertNull($new->getPassword());
}

public function testConvertToken() {
$defaultToken = new DefaultToken();
$defaultToken->setId(42);
$defaultToken->setPassword('oldPass');
$defaultToken->setExpires(1337);
$defaultToken->setToken('oldToken');
$defaultToken->setUid('uid');
$defaultToken->setLoginName('loginName');
$defaultToken->setLastActivity(999);
$defaultToken->setName('name');
$defaultToken->setRemember(IToken::REMEMBER);
$defaultToken->setType(IToken::PERMANENT_TOKEN);

$this->mapper->expects($this->once())
->method('update')
->willReturnArgument(0);

$newToken = $this->tokenProvider->convertToken($defaultToken, 'newToken', 'newPassword');

$this->assertSame(42, $newToken->getId());
$this->assertSame('newPassword', $this->tokenProvider->getPassword($newToken, 'newToken'));
$this->assertSame(1337, $newToken->getExpires());
$this->assertSame('uid', $newToken->getUID());
$this->assertSame('loginName', $newToken->getLoginName());
$this->assertSame(1313131, $newToken->getLastActivity());
$this->assertSame(1313131, $newToken->getLastCheck());
$this->assertSame('name', $newToken->getName());
$this->assertSame(IToken::REMEMBER, $newToken->getRemember());
$this->assertSame(IToken::PERMANENT_TOKEN, $newToken->getType());
}
}

0 comments on commit cca529a

Please sign in to comment.