summaryrefslogtreecommitdiffstats
path: root/apps/oauth2/tests/Controller/SettingsControllerTest.php
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-06-19 14:50:03 +0200
committerGitHub <noreply@github.com>2018-06-19 14:50:03 +0200
commitc3aea9cdf6d88895b1a1fc54ead9a2f0aa792cd3 (patch)
tree0293cac7af3ce4b54d9d66444896238f3113bd2c /apps/oauth2/tests/Controller/SettingsControllerTest.php
parent8646f01320f685de1a428b6e696c7ea691defffc (diff)
parentf520a6bceb1b7e04059e4d16478c509f8c740581 (diff)
downloadnextcloud-server-c3aea9cdf6d88895b1a1fc54ead9a2f0aa792cd3.tar.gz
nextcloud-server-c3aea9cdf6d88895b1a1fc54ead9a2f0aa792cd3.zip
Merge pull request #9830 from nextcloud/feature/noid/oauth_vue_redirect_validate
Migrate OAuth Admin settings to vue
Diffstat (limited to 'apps/oauth2/tests/Controller/SettingsControllerTest.php')
-rw-r--r--apps/oauth2/tests/Controller/SettingsControllerTest.php88
1 files changed, 65 insertions, 23 deletions
diff --git a/apps/oauth2/tests/Controller/SettingsControllerTest.php b/apps/oauth2/tests/Controller/SettingsControllerTest.php
index a6c036949ed..5dddbc65e4c 100644
--- a/apps/oauth2/tests/Controller/SettingsControllerTest.php
+++ b/apps/oauth2/tests/Controller/SettingsControllerTest.php
@@ -26,17 +26,14 @@ use OCA\OAuth2\Controller\SettingsController;
use OCA\OAuth2\Db\AccessTokenMapper;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
-use OCP\AppFramework\Http\RedirectResponse;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
-use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
use Test\TestCase;
class SettingsControllerTest extends TestCase {
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request;
- /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
- private $urlGenerator;
/** @var ClientMapper|\PHPUnit_Framework_MockObject_MockObject */
private $clientMapper;
/** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
@@ -52,7 +49,6 @@ class SettingsControllerTest extends TestCase {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->clientMapper = $this->createMock(ClientMapper::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->accessTokenMapper = $this->createMock(AccessTokenMapper::class);
@@ -61,7 +57,6 @@ class SettingsControllerTest extends TestCase {
$this->settingsController = new SettingsController(
'oauth2',
$this->request,
- $this->urlGenerator,
$this->clientMapper,
$this->secureRandom,
$this->accessTokenMapper,
@@ -90,27 +85,39 @@ class SettingsControllerTest extends TestCase {
$this->clientMapper
->expects($this->once())
->method('insert')
- ->with($client);
+ ->with($this->callback(function (Client $c) {
+ return $c->getName() === 'My Client Name' &&
+ $c->getRedirectUri() === 'https://example.com/' &&
+ $c->getSecret() === 'MySecret' &&
+ $c->getClientIdentifier() === 'MyClientIdentifier';
+ }))->will($this->returnCallback(function (Client $c) {
+ $c->setId(42);
+ return $c;
+ }));
- $this->urlGenerator
- ->expects($this->once())
- ->method('getAbsoluteURL')
- ->with('/index.php/settings/admin/security')
- ->willReturn('https://example.com/index.php/settings/admin/security');
+ $result = $this->settingsController->addClient('My Client Name', 'https://example.com/');
+ $this->assertInstanceOf(JSONResponse::class, $result);
+
+ $data = $result->getData();
- $expected = new RedirectResponse('https://example.com/index.php/settings/admin/security');
- $this->assertEquals($expected, $this->settingsController->addClient('My Client Name', 'https://example.com/'));
+ $this->assertEquals([
+ 'id' => 42,
+ 'name' => 'My Client Name',
+ 'redirectUri' => 'https://example.com/',
+ 'clientId' => 'MyClientIdentifier',
+ 'clientSecret' => 'MySecret',
+ ], $data);
}
public function testDeleteClient() {
$client = new Client();
+ $client->setId(123);
$client->setName('My Client Name');
$client->setRedirectUri('https://example.com/');
$client->setSecret('MySecret');
$client->setClientIdentifier('MyClientIdentifier');
$this->clientMapper
- ->expects($this->at(0))
->method('getByUid')
->with(123)
->willReturn($client);
@@ -123,17 +130,52 @@ class SettingsControllerTest extends TestCase {
->method('deleteByName')
->with('My Client Name');
$this->clientMapper
- ->expects($this->at(1))
->method('delete')
->with($client);
- $this->urlGenerator
- ->expects($this->once())
- ->method('getAbsoluteURL')
- ->with('/index.php/settings/admin/security')
- ->willReturn('https://example.com/index.php/settings/admin/security');
+ $result = $this->settingsController->deleteClient(123);
+ $this->assertInstanceOf(JSONResponse::class, $result);
+ $this->assertEquals([], $result->getData());
+ }
+
+ public function testGetClients() {
+ $client1 = new Client();
+ $client1->setId(123);
+ $client1->setName('My Client Name');
+ $client1->setRedirectUri('https://example.com/');
+ $client1->setSecret('MySecret');
+ $client1->setClientIdentifier('MyClientIdentifier');
+
+ $client2 = new Client();
+ $client2->setId(42);
+ $client2->setName('My Client Name2');
+ $client2->setRedirectUri('https://example.com/2');
+ $client2->setSecret('MySecret2');
+ $client2->setClientIdentifier('MyClientIdentifier2');
+
+ $this->clientMapper->method('getClients')
+ ->willReturn([$client1, $client2]);
+
+ $result = $this->settingsController->getClients();
+ $this->assertInstanceOf(JSONResponse::class, $result);
+
+ $data = $result->getData();
- $expected = new RedirectResponse('https://example.com/index.php/settings/admin/security');
- $this->assertEquals($expected, $this->settingsController->deleteClient(123));
+ $this->assertSame([
+ [
+ 'id' => 123,
+ 'name' => 'My Client Name',
+ 'redirectUri' => 'https://example.com/',
+ 'clientId' => 'MyClientIdentifier',
+ 'clientSecret' => 'MySecret',
+ ],
+ [
+ 'id' => 42,
+ 'name' => 'My Client Name2',
+ 'redirectUri' => 'https://example.com/2',
+ 'clientId' => 'MyClientIdentifier2',
+ 'clientSecret' => 'MySecret2',
+ ],
+ ], $data);
}
}