aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Controller/TwoFactorChallengeControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core/Controller/TwoFactorChallengeControllerTest.php')
-rw-r--r--tests/Core/Controller/TwoFactorChallengeControllerTest.php62
1 files changed, 26 insertions, 36 deletions
diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php
index c937b925997..d9ea1ca263f 100644
--- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php
+++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.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\Controller;
@@ -36,7 +22,7 @@ use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
-use OCP\Template;
+use OCP\Template\ITemplate;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -82,14 +68,14 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->urlGenerator,
$this->logger,
])
- ->setMethods(['getLogoutUrl'])
+ ->onlyMethods(['getLogoutUrl'])
->getMock();
$this->controller->expects($this->any())
->method('getLogoutUrl')
->willReturn('logoutAttribute');
}
- public function testSelectChallenge() {
+ public function testSelectChallenge(): void {
$user = $this->getMockBuilder(IUser::class)->getMock();
$p1 = $this->createMock(IActivatableAtLogin::class);
$p1->method('getId')->willReturn('p1');
@@ -123,13 +109,13 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->selectChallenge('/some/url'));
}
- public function testShowChallenge() {
+ public function testShowChallenge(): void {
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
$provider->method('getId')->willReturn('myprovider');
$backupProvider = $this->createMock(IProvider::class);
$backupProvider->method('getId')->willReturn('backup_codes');
- $tmpl = $this->createMock(Template::class);
+ $tmpl = $this->createMock(ITemplate::class);
$providerSet = new ProviderSet([$provider, $backupProvider], true);
$this->userSession->expects($this->once())
@@ -174,7 +160,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->showChallenge('myprovider', '/re/dir/ect/url'));
}
- public function testShowInvalidChallenge() {
+ public function testShowInvalidChallenge(): void {
$user = $this->createMock(IUser::class);
$providerSet = new ProviderSet([], false);
@@ -195,7 +181,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->showChallenge('myprovider', 'redirect/url'));
}
- public function testSolveChallenge() {
+ public function testSolveChallenge(): void {
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
@@ -220,7 +206,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token'));
}
- public function testSolveValidChallengeAndRedirect() {
+ public function testSolveValidChallengeAndRedirect(): void {
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
@@ -245,7 +231,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', 'redirect%20url'));
}
- public function testSolveChallengeInvalidProvider() {
+ public function testSolveChallengeInvalidProvider(): void {
$user = $this->getMockBuilder(IUser::class)->getMock();
$this->userSession->expects($this->once())
@@ -265,7 +251,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token'));
}
- public function testSolveInvalidChallenge() {
+ public function testSolveInvalidChallenge(): void {
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
@@ -299,10 +285,10 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token', '/url'));
}
- public function testSolveChallengeTwoFactorException() {
+ public function testSolveChallengeTwoFactorException(): void {
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
- $exception = new TwoFactorException("2FA failed");
+ $exception = new TwoFactorException('2FA failed');
$this->userSession->expects($this->once())
->method('getUser')
@@ -315,13 +301,17 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->twoFactorManager->expects($this->once())
->method('verifyChallenge')
->with('myprovider', $user, 'token')
- ->will($this->throwException($exception));
+ ->willThrowException($exception);
+ $calls = [
+ ['two_factor_auth_error_message', '2FA failed'],
+ ['two_factor_auth_error', true],
+ ];
$this->session->expects($this->exactly(2))
->method('set')
- ->withConsecutive(
- ['two_factor_auth_error_message', '2FA failed'],
- ['two_factor_auth_error', true]
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('core.TwoFactorChallenge.showChallenge', [
@@ -367,7 +357,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
$this->assertEquals($expected, $response);
}
- public function testSetUpInvalidProvider() {
+ public function testSetUpInvalidProvider(): void {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->once())
->method('getUser')
@@ -413,7 +403,7 @@ class TwoFactorChallengeControllerTest extends TestCase {
->method('getLoginSetup')
->with($user)
->willReturn($loginSetup);
- $tmpl = $this->createMock(Template::class);
+ $tmpl = $this->createMock(ITemplate::class);
$loginSetup->expects($this->once())
->method('getBody')
->willReturn($tmpl);