summaryrefslogtreecommitdiffstats
path: root/tests/Settings
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2019-02-13 18:48:42 +0100
committerDaniel Kesselberg <mail@danielkesselberg.de>2019-02-13 20:57:54 +0100
commit825200be0733e340e220ebae024040c7eb40d3a6 (patch)
tree02324781390c78271ebfafcd053c733f8c24fa0d /tests/Settings
parent840f0c38fca7d8a82b4dde91be78e3af03876ed7 (diff)
downloadnextcloud-server-825200be0733e340e220ebae024040c7eb40d3a6.tar.gz
nextcloud-server-825200be0733e340e220ebae024040c7eb40d3a6.zip
Add test cases for rename / grant / revoke
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'tests/Settings')
-rw-r--r--tests/Settings/Controller/AuthSettingsControllerTest.php98
1 files changed, 94 insertions, 4 deletions
diff --git a/tests/Settings/Controller/AuthSettingsControllerTest.php b/tests/Settings/Controller/AuthSettingsControllerTest.php
index d0ed40f25b7..6b2df70251f 100644
--- a/tests/Settings/Controller/AuthSettingsControllerTest.php
+++ b/tests/Settings/Controller/AuthSettingsControllerTest.php
@@ -239,8 +239,19 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
+ public function dataRenameToken(): array {
+ return [
+ 'App password => Other token name' => ['App password', 'Other token name'],
+ 'Other token name => App password' => ['Other token name', 'App password'],
+ ];
+ }
- public function testUpdateToken() {
+ /**
+ * @dataProvider dataRenameToken
+ * @param string $name
+ * @param string $newName
+ */
+ public function testUpdateRename(string $name, string $newName): void {
$tokenId = 42;
$token = $this->createMock(DefaultToken::class);
@@ -252,10 +263,89 @@ class AuthSettingsControllerTest extends TestCase {
->willReturn('jane');
$token->expects($this->once())
+ ->method('getName')
+ ->willReturn($name);
+
+ $token->expects($this->once())
+ ->method('getScopeAsArray')
+ ->willReturn(['filesystem' => true]);
+
+ $token->expects($this->once())
+ ->method('setName')
+ ->with($this->equalTo($newName));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($this->equalTo($token));
+
+ $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], $newName));
+ }
+
+ public function dataUpdateFilesystemScope(): array {
+ return [
+ 'Grant filesystem access' => [false, true],
+ 'Revoke filesystem access' => [true, false],
+ ];
+ }
+
+ /**
+ * @dataProvider dataUpdateFilesystemScope
+ * @param bool $filesystem
+ * @param bool $newFilesystem
+ */
+ public function testUpdateFilesystemScope(bool $filesystem, bool $newFilesystem): void {
+ $tokenId = 42;
+ $token = $this->createMock(DefaultToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+ $this->mockActivityManager();
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('jane');
+
+ $token->expects($this->once())
+ ->method('getName')
+ ->willReturn('App password');
+
+ $token->expects($this->once())
+ ->method('getScopeAsArray')
+ ->willReturn(['filesystem' => $filesystem]);
+
+ $token->expects($this->once())
->method('setScope')
- ->with($this->equalTo([
- 'filesystem' => true
- ]));
+ ->with($this->equalTo(['filesystem' => $newFilesystem]));
+
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($this->equalTo($token));
+
+ $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => $newFilesystem], 'App password'));
+ }
+
+ public function testUpdateNoChange(): void {
+ $tokenId = 42;
+ $token = $this->createMock(DefaultToken::class);
+
+ $this->mockGetTokenById($tokenId, $token);
+
+ $token->expects($this->once())
+ ->method('getUID')
+ ->willReturn('jane');
+
+ $token->expects($this->once())
+ ->method('getName')
+ ->willReturn('App password');
+
+ $token->expects($this->once())
+ ->method('getScopeAsArray')
+ ->willReturn(['filesystem' => true]);
+
+ $token->expects($this->never())
+ ->method('setName');
+
+ $token->expects($this->never())
+ ->method('setScope');
$this->tokenProvider->expects($this->once())
->method('updateToken')