diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-05-17 09:51:47 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-05-17 09:52:06 +0200 |
commit | 2dcb4cfbd644babf0ee202b4489689d882ae1dd3 (patch) | |
tree | acb0f85eed9cae44dc47af99d243387100651f74 /tests | |
parent | e625164e85b3ab4be3a51b86f909564430cb388b (diff) | |
download | nextcloud-server-2dcb4cfbd644babf0ee202b4489689d882ae1dd3.tar.gz nextcloud-server-2dcb4cfbd644babf0ee202b4489689d882ae1dd3.zip |
Allow clients to delete their own apptoken
Fixes #15480
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/AppPasswordControllerTest.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/Core/Controller/AppPasswordControllerTest.php b/tests/Core/Controller/AppPasswordControllerTest.php index a66bcb3fc26..a7be7a90b09 100644 --- a/tests/Core/Controller/AppPasswordControllerTest.php +++ b/tests/Core/Controller/AppPasswordControllerTest.php @@ -24,9 +24,11 @@ declare(strict_types=1); namespace Tests\Core\Controller; +use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; use OC\Core\Controller\AppPasswordController; +use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\Authentication\Exceptions\CredentialsUnavailableException; use OCP\Authentication\Exceptions\PasswordUnavailableException; @@ -187,5 +189,60 @@ class AppPasswordControllerTest extends TestCase { $this->controller->getAppPassword(); } + public function testDeleteAppPasswordNoAppPassword() { + $this->session->method('exists') + ->with('app_password') + ->willReturn(false); + + $this->expectException(OCSForbiddenException::class); + + $this->controller->deleteAppPassword(); + } + + public function testDeleteAppPasswordFails() { + $this->session->method('exists') + ->with('app_password') + ->willReturn(true); + $this->session->method('get') + ->with('app_password') + ->willReturn('myAppPassword'); + + $this->tokenProvider->method('getToken') + ->with('myAppPassword') + ->willThrowException(new InvalidTokenException()); + + $this->expectException(OCSForbiddenException::class); + + $this->controller->deleteAppPassword(); + } + + public function testDeleteAppPasswordSuccess() { + $this->session->method('exists') + ->with('app_password') + ->willReturn(true); + $this->session->method('get') + ->with('app_password') + ->willReturn('myAppPassword'); + + $token = $this->createMock(IToken::class); + $this->tokenProvider->method('getToken') + ->with('myAppPassword') + ->willReturn($token); + + $token->method('getUID') + ->willReturn('myUID'); + $token->method('getId') + ->willReturn(42); + + $this->tokenProvider->expects($this->once()) + ->method('invalidateTokenById') + ->with( + 'myUID', + 42 + ); + $result = $this->controller->deleteAppPassword(); + + $this->assertEquals(new DataResponse(), $result); + } } |