summaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Settings
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-01-28 20:48:18 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2020-01-29 15:57:59 +0100
commit34426a481faa5ff76317295305d7c6fad2c8534f (patch)
treea507b26f91562c0d5b9a0fee3ff6a9a6355b29ae /apps/settings/tests/Settings
parentedd37368fd101439d7c9a9683aeb39b3844945c3 (diff)
downloadnextcloud-server-34426a481faa5ff76317295305d7c6fad2c8534f.tar.gz
nextcloud-server-34426a481faa5ff76317295305d7c6fad2c8534f.zip
Move can create token logic
It makes sense to have this in the actual authtoken settings. As well. This is where it is used. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/settings/tests/Settings')
-rw-r--r--apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php136
-rw-r--r--apps/settings/tests/Settings/Personal/SecurityTest.php6
2 files changed, 136 insertions, 6 deletions
diff --git a/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
new file mode 100644
index 00000000000..6837fc101c4
--- /dev/null
+++ b/apps/settings/tests/Settings/Personal/Security/AuthtokensTest.php
@@ -0,0 +1,136 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Settings\Tests\Settings\Personal\Security;
+
+use OC\Authentication\Token\DefaultToken;
+use OC\Authentication\Token\IProvider as IAuthTokenProvider;
+use OCA\Settings\Personal\Security;
+use OCA\Settings\Personal\Security\Authtokens;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IInitialStateService;
+use OCP\ISession;
+use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class AuthtokensTest extends TestCase {
+
+ /** @var IAuthTokenProvider|MockObject */
+ private $authTokenProvider;
+
+ /** @var ISession|MockObject */
+ private $session;
+
+ /** @var IUserSession|MockObject */
+ private $userSession;
+
+ /** @var IInitialStateService|MockObject */
+ private $initialStateService;
+
+ /** @var string */
+ private $uid;
+
+ /** @var Security\Authtokens */
+ private $section;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->authTokenProvider = $this->createMock(IAuthTokenProvider::class);
+ $this->session = $this->createMock(ISession::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->initialStateService = $this->createMock(IInitialStateService::class);
+ $this->uid = 'test123';
+
+ $this->section = new Authtokens(
+ $this->authTokenProvider,
+ $this->session,
+ $this->userSession,
+ $this->initialStateService,
+ $this->uid
+ );
+ }
+
+ public function testGetForm() {
+ $token1 = new DefaultToken();
+ $token1->setId(100);
+ $token2 = new DefaultToken();
+ $token2->setId(200);
+ $tokens = [
+ $token1,
+ $token2,
+ ];
+ $sessionToken = new DefaultToken();
+ $sessionToken->setId(100);
+
+ $this->authTokenProvider->expects($this->once())
+ ->method('getTokenByUser')
+ ->with($this->uid)
+ ->willReturn($tokens);
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->willReturn('session123');
+ $this->authTokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('session123')
+ ->willReturn($sessionToken);
+ $this->initialStateService->expects($this->at(0))
+ ->method('provideInitialState')
+ ->with('settings', 'app_tokens', [
+ [
+ 'id' => 100,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => false,
+ 'current' => true,
+ 'scope' => ['filesystem' => true],
+ 'canRename' => false,
+ ],
+ [
+ 'id' => 200,
+ 'name' => null,
+ 'lastActivity' => 0,
+ 'type' => 0,
+ 'canDelete' => true,
+ 'scope' => ['filesystem' => true],
+ 'canRename' => true,
+ ],
+ ]);
+
+ $this->initialStateService->expects($this->at(1))
+ ->method('provideInitialState')
+ ->with('settings', 'can_create_app_token', true);
+
+ $form = $this->section->getForm();
+
+ $expected = new TemplateResponse('settings', 'settings/personal/security/authtokens');
+ $this->assertEquals($expected, $form);
+ }
+
+}
diff --git a/apps/settings/tests/Settings/Personal/SecurityTest.php b/apps/settings/tests/Settings/Personal/SecurityTest.php
index 5dfb911716f..bd087afa466 100644
--- a/apps/settings/tests/Settings/Personal/SecurityTest.php
+++ b/apps/settings/tests/Settings/Personal/SecurityTest.php
@@ -32,7 +32,6 @@ use OC\Authentication\TwoFactorAuth\ProviderLoader;
use OCA\Settings\Personal\Security;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
-use OCP\IInitialStateService;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
@@ -41,9 +40,6 @@ use Test\TestCase;
class SecurityTest extends TestCase {
- /** @var IInitialStateService|MockObject */
- private $initialStateService;
-
/** @var IUserManager|MockObject */
private $userManager;
@@ -65,7 +61,6 @@ class SecurityTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->initialStateService = $this->createMock(IInitialStateService::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->providerLoader = $this->createMock(ProviderLoader::class);
$this->userSession = $this->createMock(IUserSession::class);
@@ -73,7 +68,6 @@ class SecurityTest extends TestCase {
$this->uid = 'test123';
$this->section = new Security(
- $this->initialStateService,
$this->userManager,
$this->providerLoader,
$this->userSession,