aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Middleware/TwoFactorMiddlewareTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core/Middleware/TwoFactorMiddlewareTest.php')
-rw-r--r--tests/Core/Middleware/TwoFactorMiddlewareTest.php66
1 files changed, 28 insertions, 38 deletions
diff --git a/tests/Core/Middleware/TwoFactorMiddlewareTest.php b/tests/Core/Middleware/TwoFactorMiddlewareTest.php
index fe1b53e3fa5..10afdd7c5e1 100644
--- a/tests/Core/Middleware/TwoFactorMiddlewareTest.php
+++ b/tests/Core/Middleware/TwoFactorMiddlewareTest.php
@@ -1,23 +1,9 @@
<?php
/**
- * @author Christoph Wurst <christoph@owncloud.com>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Core\Middleware;
@@ -96,7 +82,7 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->controller = $this->createMock(Controller::class);
}
- public function testBeforeControllerNotLoggedIn() {
+ public function testBeforeControllerNotLoggedIn(): void {
$this->userSession->expects($this->once())
->method('isLoggedIn')
->willReturn(false);
@@ -107,7 +93,7 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($this->controller, 'index');
}
- public function testBeforeSetupController() {
+ public function testBeforeSetupController(): void {
$user = $this->createMock(IUser::class);
$controller = $this->createMock(ALoginSetupController::class);
$this->userSession->expects($this->any())
@@ -122,7 +108,7 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($controller, 'create');
}
- public function testBeforeControllerNoTwoFactorCheckNeeded() {
+ public function testBeforeControllerNoTwoFactorCheckNeeded(): void {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->once())
@@ -140,7 +126,7 @@ class TwoFactorMiddlewareTest extends TestCase {
}
- public function testBeforeControllerTwoFactorAuthRequired() {
+ public function testBeforeControllerTwoFactorAuthRequired(): void {
$this->expectException(TwoFactorAuthRequiredException::class);
$user = $this->createMock(IUser::class);
@@ -164,7 +150,7 @@ class TwoFactorMiddlewareTest extends TestCase {
}
- public function testBeforeControllerUserAlreadyLoggedIn() {
+ public function testBeforeControllerUserAlreadyLoggedIn(): void {
$this->expectException(UserAlreadyLoggedInException::class);
$user = $this->createMock(IUser::class);
@@ -193,7 +179,7 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($twoFactorChallengeController, 'index');
}
- public function testAfterExceptionTwoFactorAuthRequired() {
+ public function testAfterExceptionTwoFactorAuthRequired(): void {
$ex = new TwoFactorAuthRequiredException();
$this->urlGenerator->expects($this->once())
@@ -205,7 +191,7 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->assertEquals($expected, $this->middleware->afterException($this->controller, 'index', $ex));
}
- public function testAfterException() {
+ public function testAfterException(): void {
$ex = new UserAlreadyLoggedInException();
$this->urlGenerator->expects($this->once())
@@ -217,7 +203,7 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->assertEquals($expected, $this->middleware->afterException($this->controller, 'index', $ex));
}
- public function testRequires2FASetupDoneAnnotated() {
+ public function testRequires2FASetupDoneAnnotated(): void {
$user = $this->createMock(IUser::class);
$this->reflector
@@ -248,23 +234,27 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($twoFactorChallengeController, 'index');
}
- public function dataRequires2FASetupDone() {
- $provider = $this->createMock(IProvider::class);
- $provider->method('getId')
- ->willReturn('2FAftw');
-
+ public static function dataRequires2FASetupDone(): array {
return [
- [[], false, false],
- [[], true, true],
- [[$provider], false, true],
- [[$provider], true, true],
+ [false, false, false],
+ [false, true, true],
+ [true, false, true],
+ [true, true, true],
];
}
- /**
- * @dataProvider dataRequires2FASetupDone
- */
- public function testRequires2FASetupDone(array $providers, bool $missingProviders, bool $expectEception) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRequires2FASetupDone')]
+ public function testRequires2FASetupDone(bool $hasProvider, bool $missingProviders, bool $expectEception): void {
+ if ($hasProvider) {
+ $provider = $this->createMock(IProvider::class);
+ $provider->method('getId')
+ ->willReturn('2FAftw');
+ $providers = [$provider];
+ } else {
+ $providers = [];
+ }
+
+
$user = $this->createMock(IUser::class);
$this->reflector