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
diff options
context:
space:
mode:
authorSergej Nikolaev <kinolaev@gmail.com>2019-10-04 03:28:48 +0300
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-10-05 11:28:47 +0300
commit9aa992e60b63a80188a5bdf4106b746fd8fef19c (patch)
treee293463abb19c014c8a4b41e49a31056af173d80 /apps/settings/tests
parent87ad219dafd60b9b733a03a34404ab828b195cdb (diff)
fix updating and deleting authtokens
Signed-off-by: Sergej Nikolaev <kinolaev@gmail.com>
Diffstat (limited to 'apps/settings/tests')
-rw-r--r--apps/settings/tests/Controller/AuthSettingsControllerTest.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/apps/settings/tests/Controller/AuthSettingsControllerTest.php b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
index 88913b1f03f..40000e19171 100644
--- a/apps/settings/tests/Controller/AuthSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
@@ -23,6 +23,7 @@ namespace Test\Settings\Controller;
use OC\AppFramework\Http;
use OC\Authentication\Exceptions\InvalidTokenException;
+use OC\Authentication\Exceptions\ExpiredTokenException;
use OC\Authentication\Token\DefaultToken;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
@@ -188,6 +189,30 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals([], $this->controller->destroy($tokenId));
}
+ public function testDestroyExpired() {
+ $tokenId = 124;
+ $token = $this->createMock(DefaultToken::class);
+
+ $token->expects($this->exactly(2))
+ ->method('getId')
+ ->willReturn($tokenId);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn($this->uid);
+
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with($this->equalTo($tokenId))
+ ->willThrowException(new ExpiredTokenException($token));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('invalidateTokenById')
+ ->with($this->uid, $tokenId);
+
+ $this->assertSame([], $this->controller->destroy($tokenId));
+ }
+
public function testDestroyWrongUser() {
$tokenId = 124;
$token = $this->createMock(DefaultToken::class);
@@ -320,6 +345,26 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password'));
}
+ public function testUpdateExpired() {
+ $tokenId = 42;
+ $token = $this->createMock(DefaultToken::class);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn($this->uid);
+
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with($this->equalTo($tokenId))
+ ->willThrowException(new ExpiredTokenException($token));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($this->equalTo($token));
+
+ $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password'));
+ }
+
public function testUpdateTokenWrongUser() {
$tokenId = 42;
$token = $this->createMock(DefaultToken::class);