aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Controller/AuthSettingsControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/tests/Controller/AuthSettingsControllerTest.php')
-rw-r--r--apps/settings/tests/Controller/AuthSettingsControllerTest.php119
1 files changed, 39 insertions, 80 deletions
diff --git a/apps/settings/tests/Controller/AuthSettingsControllerTest.php b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
index b744b942e09..d195dbf83d3 100644
--- a/apps/settings/tests/Controller/AuthSettingsControllerTest.php
+++ b/apps/settings/tests/Controller/AuthSettingsControllerTest.php
@@ -1,31 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Fabrizio Steiner <fabrizio.steiner@gmail.com>
- * @author Greta Doci <gretadoci@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Sergej Nikolaev <kinolaev@gmail.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Settings\Controller;
@@ -51,24 +29,15 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class AuthSettingsControllerTest extends TestCase {
-
- /** @var AuthSettingsController */
- private $controller;
- /** @var IRequest|MockObject */
- private $request;
- /** @var IProvider|MockObject */
- private $tokenProvider;
- /** @var ISession|MockObject */
- private $session;
- /**@var IUserSession|MockObject */
- private $userSession;
- /** @var ISecureRandom|MockObject */
- private $secureRandom;
- /** @var IManager|MockObject */
- private $activityManager;
- /** @var RemoteWipe|MockObject */
- private $remoteWipe;
- private $uid = 'jane';
+ private IRequest&MockObject $request;
+ private IProvider&MockObject $tokenProvider;
+ private ISession&MockObject $session;
+ private IUserSession&MockObject $userSession;
+ private ISecureRandom&MockObject $secureRandom;
+ private IManager&MockObject $activityManager;
+ private RemoteWipe&MockObject $remoteWipe;
+ private string $uid = 'jane';
+ private AuthSettingsController $controller;
protected function setUp(): void {
parent::setUp();
@@ -80,7 +49,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->activityManager = $this->createMock(IManager::class);
$this->remoteWipe = $this->createMock(RemoteWipe::class);
- /** @var LoggerInterface|MockObject $logger */
+ /** @var LoggerInterface&MockObject $logger */
$logger = $this->createMock(LoggerInterface::class);
$this->controller = new AuthSettingsController(
@@ -97,7 +66,7 @@ class AuthSettingsControllerTest extends TestCase {
);
}
- public function testCreate() {
+ public function testCreate(): void {
$name = 'Nexus 4';
$sessionToken = $this->createMock(IToken::class);
$deviceToken = $this->createMock(IToken::class);
@@ -146,12 +115,12 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $response->getData());
}
- public function testCreateSessionNotAvailable() {
+ public function testCreateSessionNotAvailable(): void {
$name = 'personal phone';
$this->session->expects($this->once())
->method('getId')
- ->will($this->throwException(new SessionNotAvailableException()));
+ ->willThrowException(new SessionNotAvailableException());
$expected = new JSONResponse();
$expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
@@ -159,7 +128,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->create($name));
}
- public function testCreateInvalidToken() {
+ public function testCreateInvalidToken(): void {
$name = 'Company IPhone';
$this->session->expects($this->once())
@@ -168,7 +137,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('sessionid')
- ->will($this->throwException(new InvalidTokenException()));
+ ->willThrowException(new InvalidTokenException());
$expected = new JSONResponse();
$expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
@@ -176,7 +145,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->create($name));
}
- public function testDestroy() {
+ public function testDestroy(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -198,7 +167,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals([], $this->controller->destroy($tokenId));
}
- public function testDestroyExpired() {
+ public function testDestroyExpired(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -222,7 +191,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame([], $this->controller->destroy($tokenId));
}
- public function testDestroyWrongUser() {
+ public function testDestroyWrongUser(): void {
$tokenId = 124;
$token = $this->createMock(PublicKeyToken::class);
@@ -237,19 +206,14 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function dataRenameToken(): array {
+ public static function dataRenameToken(): array {
return [
'App password => Other token name' => ['App password', 'Other token name'],
'Other token name => App password' => ['Other token name', 'App password'],
];
}
- /**
- * @dataProvider dataRenameToken
- *
- * @param string $name
- * @param string $newName
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRenameToken')]
public function testUpdateRename(string $name, string $newName): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -267,7 +231,7 @@ class AuthSettingsControllerTest extends TestCase {
$token->expects($this->once())
->method('getScopeAsArray')
- ->willReturn(['filesystem' => true]);
+ ->willReturn([IToken::SCOPE_FILESYSTEM => true]);
$token->expects($this->once())
->method('setName')
@@ -277,22 +241,17 @@ class AuthSettingsControllerTest extends TestCase {
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], $newName));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], $newName));
}
- public function dataUpdateFilesystemScope(): array {
+ public static function dataUpdateFilesystemScope(): array {
return [
'Grant filesystem access' => [false, true],
'Revoke filesystem access' => [true, false],
];
}
- /**
- * @dataProvider dataUpdateFilesystemScope
- *
- * @param bool $filesystem
- * @param bool $newFilesystem
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateFilesystemScope')]
public function testUpdateFilesystemScope(bool $filesystem, bool $newFilesystem): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -310,17 +269,17 @@ class AuthSettingsControllerTest extends TestCase {
$token->expects($this->once())
->method('getScopeAsArray')
- ->willReturn(['filesystem' => $filesystem]);
+ ->willReturn([IToken::SCOPE_FILESYSTEM => $filesystem]);
$token->expects($this->once())
->method('setScope')
- ->with($this->equalTo(['filesystem' => $newFilesystem]));
+ ->with($this->equalTo([IToken::SCOPE_FILESYSTEM => $newFilesystem]));
$this->tokenProvider->expects($this->once())
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => $newFilesystem], 'App password'));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => $newFilesystem], 'App password'));
}
public function testUpdateNoChange(): void {
@@ -339,7 +298,7 @@ class AuthSettingsControllerTest extends TestCase {
$token->expects($this->once())
->method('getScopeAsArray')
- ->willReturn(['filesystem' => true]);
+ ->willReturn([IToken::SCOPE_FILESYSTEM => true]);
$token->expects($this->never())
->method('setName');
@@ -351,10 +310,10 @@ class AuthSettingsControllerTest extends TestCase {
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password'));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
}
- public function testUpdateExpired() {
+ public function testUpdateExpired(): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -371,10 +330,10 @@ class AuthSettingsControllerTest extends TestCase {
->method('updateToken')
->with($this->equalTo($token));
- $this->assertSame([], $this->controller->update($tokenId, ['filesystem' => true], 'App password'));
+ $this->assertSame([], $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password'));
}
- public function testUpdateTokenWrongUser() {
+ public function testUpdateTokenWrongUser(): void {
$tokenId = 42;
$token = $this->createMock(PublicKeyToken::class);
@@ -389,12 +348,12 @@ class AuthSettingsControllerTest extends TestCase {
$this->tokenProvider->expects($this->never())
->method('updateToken');
- $response = $this->controller->update($tokenId, ['filesystem' => true], 'App password');
+ $response = $this->controller->update($tokenId, [IToken::SCOPE_FILESYSTEM => true], 'App password');
$this->assertSame([], $response->getData());
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}
- public function testUpdateTokenNonExisting() {
+ public function testUpdateTokenNonExisting(): void {
$this->tokenProvider->expects($this->once())
->method('getTokenById')
->with($this->equalTo(42))
@@ -403,7 +362,7 @@ class AuthSettingsControllerTest extends TestCase {
$this->tokenProvider->expects($this->never())
->method('updateToken');
- $response = $this->controller->update(42, ['filesystem' => true], 'App password');
+ $response = $this->controller->update(42, [IToken::SCOPE_FILESYSTEM => true], 'App password');
$this->assertSame([], $response->getData());
$this->assertSame(\OCP\AppFramework\Http::STATUS_NOT_FOUND, $response->getStatus());
}