diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-02-13 22:45:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-13 22:45:12 +0100 |
commit | d7495f89abbe8050fb22202b0a47b901cce6df28 (patch) | |
tree | 265f55daa81261547783818b4346c7bfc1bd7aa1 /tests | |
parent | cf091539a7018d20c50ebc97f77ace99e9e00297 (diff) | |
parent | 825200be0733e340e220ebae024040c7eb40d3a6 (diff) | |
download | nextcloud-server-d7495f89abbe8050fb22202b0a47b901cce6df28.tar.gz nextcloud-server-d7495f89abbe8050fb22202b0a47b901cce6df28.zip |
Merge pull request #14170 from nextcloud/feature/update-app-password-activity
Show more information on app password update
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings/Controller/AuthSettingsControllerTest.php | 98 |
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') |