|
|
|
@ -10,6 +10,7 @@ use OCA\Files_External\Lib\Auth\Password\GlobalAuth; |
|
|
|
|
use OCA\Files_External\Lib\Auth\PublicKey\RSA; |
|
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
|
|
|
|
use OCP\IGroupManager; |
|
|
|
|
use OCP\IL10N; |
|
|
|
|
use OCP\IRequest; |
|
|
|
|
use OCP\IUser; |
|
|
|
|
use OCP\IUserSession; |
|
|
|
@ -28,6 +29,8 @@ class AjaxControllerTest extends TestCase { |
|
|
|
|
private $groupManager; |
|
|
|
|
/** @var AjaxController */ |
|
|
|
|
private $ajaxController; |
|
|
|
|
/** @var IL10N */ |
|
|
|
|
private $l10n; |
|
|
|
|
|
|
|
|
|
protected function setUp(): void { |
|
|
|
|
$this->request = $this->createMock(IRequest::class); |
|
|
|
@ -39,6 +42,7 @@ class AjaxControllerTest extends TestCase { |
|
|
|
|
->getMock(); |
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class); |
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class); |
|
|
|
|
$this->l10n = $this->createMock(IL10N::class); |
|
|
|
|
|
|
|
|
|
$this->ajaxController = new AjaxController( |
|
|
|
|
'files_external', |
|
|
|
@ -46,9 +50,19 @@ class AjaxControllerTest extends TestCase { |
|
|
|
|
$this->rsa, |
|
|
|
|
$this->globalAuth, |
|
|
|
|
$this->userSession, |
|
|
|
|
$this->groupManager |
|
|
|
|
$this->groupManager, |
|
|
|
|
$this->l10n, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$this->l10n->expects($this->any()) |
|
|
|
|
->method('t') |
|
|
|
|
->willReturnCallback(function ($string, $args) { |
|
|
|
|
if (!is_array($args)) { |
|
|
|
|
$args = [$args]; |
|
|
|
|
} |
|
|
|
|
return vsprintf($string, $args); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
parent::setUp(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -87,7 +101,9 @@ class AjaxControllerTest extends TestCase { |
|
|
|
|
->expects($this->never()) |
|
|
|
|
->method('saveAuth'); |
|
|
|
|
|
|
|
|
|
$this->assertSame(false, $this->ajaxController->saveGlobalCredentials('UidOfTestUser', 'test', 'password')); |
|
|
|
|
$response = $this->ajaxController->saveGlobalCredentials('UidOfTestUser', 'test', 'password'); |
|
|
|
|
$this->assertSame($response->getStatus(), 403); |
|
|
|
|
$this->assertSame('Permission denied', $response->getData()['message']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testSaveGlobalCredentialsAsAdminForSelf(): void { |
|
|
|
@ -105,7 +121,8 @@ class AjaxControllerTest extends TestCase { |
|
|
|
|
->method('saveAuth') |
|
|
|
|
->with('MyAdminUid', 'test', 'password'); |
|
|
|
|
|
|
|
|
|
$this->assertSame(true, $this->ajaxController->saveGlobalCredentials('MyAdminUid', 'test', 'password')); |
|
|
|
|
$response = $this->ajaxController->saveGlobalCredentials('MyAdminUid', 'test', 'password'); |
|
|
|
|
$this->assertSame($response->getStatus(), 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testSaveGlobalCredentialsAsNormalUserForSelf(): void { |
|
|
|
@ -120,7 +137,8 @@ class AjaxControllerTest extends TestCase { |
|
|
|
|
->method('saveAuth') |
|
|
|
|
->with('MyUserUid', 'test', 'password'); |
|
|
|
|
|
|
|
|
|
$this->assertSame(true, $this->ajaxController->saveGlobalCredentials('MyUserUid', 'test', 'password')); |
|
|
|
|
$response = $this->ajaxController->saveGlobalCredentials('MyUserUid', 'test', 'password'); |
|
|
|
|
$this->assertSame($response->getStatus(), 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testSaveGlobalCredentialsAsNormalUserForAnotherUser(): void { |
|
|
|
@ -135,6 +153,8 @@ class AjaxControllerTest extends TestCase { |
|
|
|
|
->expects($this->never()) |
|
|
|
|
->method('saveAuth'); |
|
|
|
|
|
|
|
|
|
$this->assertSame(false, $this->ajaxController->saveGlobalCredentials('AnotherUserUid', 'test', 'password')); |
|
|
|
|
$response = $this->ajaxController->saveGlobalCredentials('AnotherUserUid', 'test', 'password'); |
|
|
|
|
$this->assertSame($response->getStatus(), 403); |
|
|
|
|
$this->assertSame('Permission denied', $response->getData()['message']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|