|
|
|
@ -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); |
|
|
|
|
|
|
|
|
@ -251,11 +262,90 @@ class AuthSettingsControllerTest extends TestCase { |
|
|
|
|
->method('getUID') |
|
|
|
|
->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') |
|
|
|
|