diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-10-02 11:50:41 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-10-02 19:50:54 +0200 |
commit | 19f84f7b5485e204014671d0439e8af5693acbb1 (patch) | |
tree | a386a3212106ceab6c07a98ee4a320f8b0012f37 /tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php | |
parent | d9febae5b2cbe2147c892030ca9d1b5db7304e9f (diff) | |
download | nextcloud-server-19f84f7b5485e204014671d0439e8af5693acbb1.tar.gz nextcloud-server-19f84f7b5485e204014671d0439e8af5693acbb1.zip |
Add tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php')
-rw-r--r-- | tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php index 681ad35c644..02ec62d3d77 100644 --- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php +++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php @@ -504,4 +504,76 @@ class PublicKeyTokenProviderTest extends TestCase { $this->assertSame(IToken::REMEMBER, $newToken->getRemember()); $this->assertSame(IToken::PERMANENT_TOKEN, $newToken->getType()); } + + public function testMarkPasswordInvalidInvalidToken() { + $token = $this->createMock(DefaultToken::class); + + $this->expectException(InvalidTokenException::class); + + $this->tokenProvider->markPasswordInvalid($token, 'tokenId'); + } + + public function testMarkPasswordInvalid() { + $token = $this->createMock(PublicKeyToken::class); + + $token->expects($this->once()) + ->method('setPasswordInvalid') + ->with(true); + $this->mapper->expects($this->once()) + ->method('update') + ->with($token); + + $this->tokenProvider->markPasswordInvalid($token, 'tokenId'); + } + + public function testUpdatePasswords() { + $uid = 'myUID'; + $token1 = $this->tokenProvider->generateToken( + 'foo', + $uid, + $uid, + 'bar', + 'random1', + IToken::PERMANENT_TOKEN, + IToken::REMEMBER); + $token2 = $this->tokenProvider->generateToken( + 'foobar', + $uid, + $uid, + 'bar', + 'random2', + IToken::PERMANENT_TOKEN, + IToken::REMEMBER); + + $this->mapper->expects($this->once()) + ->method('hasExpiredTokens') + ->with($uid) + ->willReturn(true); + $this->mapper->expects($this->once()) + ->method('getTokenByUser') + ->with($uid) + ->willReturn([$token1, $token2]); + $this->mapper->expects($this->exactly(2)) + ->method('update') + ->with($this->callback(function (PublicKeyToken $t) use ($token1, $token2) { + return $t === $token1 || $t === $token2; + })); + + $this->tokenProvider->updatePasswords($uid, 'bar2'); + } + + public function testUpdatePasswordsNotRequired() { + $uid = 'myUID'; + + $this->mapper->expects($this->once()) + ->method('hasExpiredTokens') + ->with($uid) + ->willReturn(false); + $this->mapper->expects($this->never()) + ->method('getTokenByUser'); + $this->mapper->expects($this->never()) + ->method('update'); + + $this->tokenProvider->updatePasswords($uid, 'bar2'); + } } |