Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-05-16 13:39:00 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2018-05-22 15:26:13 +0300
commit46aafe4f11e971e442baa3283906878ef5dae856 (patch)
tree662f8d10c88163b6cec9f70a79cf1b14a6f242fa /tests
parent8fcb7d4334526a30164db1d0c45b89f9f38614bd (diff)
Certain tokens can expire
However due to the nature of what we store in the token (encrypted passwords etc). We can't just delete the tokens because that would make the oauth refresh useless. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Authentication/Token/DefaultTokenProviderTest.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
index e2643d315ce..ccf654bcdfd 100644
--- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
@@ -25,6 +25,7 @@ namespace Test\Authentication\Token;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\DefaultToken;
use OC\Authentication\Token\DefaultTokenProvider;
+use OC\Authentication\Token\ExpiredTokenException;
use OC\Authentication\Token\IToken;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Mapper;
@@ -397,6 +398,63 @@ class DefaultTokenProviderTest extends TestCase {
$this->tokenProvider->renewSessionToken('oldId', 'newId');
}
+ public function testGetToken() {
+ $token = new DefaultToken();
+
+ $this->config->method('getSystemValue')
+ ->with('secret')
+ ->willReturn('mysecret');
+
+ $this->mapper->method('getToken')
+ ->with(
+ $this->callback(function ($token) {
+ return hash('sha512', 'unhashedTokenmysecret') === $token;
+ })
+ )->willReturn($token);
+
+ $this->assertSame($token, $this->tokenProvider->getToken('unhashedToken'));
+ }
+
+ public function testGetInvalidToken() {
+ $this->expectException(InvalidTokenException::class);
+
+ $this->config->method('getSystemValue')
+ ->with('secret')
+ ->willReturn('mysecret');
+
+ $this->mapper->method('getToken')
+ ->with(
+ $this->callback(function ($token) {
+ return hash('sha512', 'unhashedTokenmysecret') === $token;
+ })
+ )->willThrowException(new InvalidTokenException());
+
+ $this->tokenProvider->getToken('unhashedToken');
+ }
+
+ public function testGetExpiredToken() {
+ $token = new DefaultToken();
+ $token->setExpires(42);
+
+ $this->config->method('getSystemValue')
+ ->with('secret')
+ ->willReturn('mysecret');
+
+ $this->mapper->method('getToken')
+ ->with(
+ $this->callback(function ($token) {
+ return hash('sha512', 'unhashedTokenmysecret') === $token;
+ })
+ )->willReturn($token);
+
+ try {
+ $this->tokenProvider->getToken('unhashedToken');
+ } catch (ExpiredTokenException $e) {
+ $this->assertSame($token, $e->getToken());
+ }
+
+ }
+
public function testGetTokenById() {
$token = $this->createMock(DefaultToken::class);
@@ -419,6 +477,23 @@ class DefaultTokenProviderTest extends TestCase {
$this->tokenProvider->getTokenById(42);
}
+ public function testGetExpiredTokenById() {
+ $token = new DefaultToken();
+ $token->setExpires(42);
+
+ $this->mapper->expects($this->once())
+ ->method('getTokenById')
+ ->with($this->equalTo(42))
+ ->willReturn($token);
+
+ try {
+ $this->tokenProvider->getTokenById(42);
+ $this->fail();
+ } catch (ExpiredTokenException $e) {
+ $this->assertSame($token, $e->getToken());
+ }
+ }
+
public function testRotate() {
$token = new DefaultToken();
$token->setPassword('oldencryptedpassword');