test(unit): adjust testSSO scenario and test class

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2024-06-13 20:05:34 +02:00
parent 06c64fdbc6
commit 527bc5d984
No known key found for this signature in database
GPG key ID: 7424F1874854DF23
2 changed files with 67 additions and 5 deletions

View file

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @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 Test\AppFramework\Middleware\Security\Mock;
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
class PasswordConfirmationMiddlewareController extends \OCP\AppFramework\Controller {
public function testNoAnnotationNorAttribute() {
}
/**
* @TestAnnotation
*/
public function testDifferentAnnotation() {
}
/**
* @PasswordConfirmationRequired
*/
public function testAnnotation() {
}
/**
* @PasswordConfirmationRequired
*/
public function testAttribute() {
}
/**
* @PasswordConfirmationRequired
*/
public function testSSO() {
}
}

View file

@ -30,9 +30,11 @@ use OCP\AppFramework\Controller;
use OC\Authentication\Token\IProvider;
use OCP\AppFramework\Utility\ITimeFactory;
use OC\Authentication\Token\IToken;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserSession;
use Test\AppFramework\Middleware\Security\Mock\PasswordConfirmationMiddlewareController;
use Test\TestCase;
class PasswordConfirmationMiddlewareTest extends TestCase {
@ -47,7 +49,7 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
/** @var PasswordConfirmationMiddleware */
private $middleware;
/** @var Controller */
private $contoller;
private $controller;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory;
private IProvider|\PHPUnit\Framework\MockObject\MockObject $tokenProvider;
@ -57,7 +59,10 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->session = $this->createMock(ISession::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->user = $this->createMock(IUser::class);
$this->contoller = $this->createMock(Controller::class);
$this->controller = new PasswordConfirmationMiddlewareController(
'test',
$this->createMock(IRequest::class)
);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->tokenProvider = $this->createMock(IProvider::class);
@ -77,7 +82,7 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->userSession->expects($this->never())
->method($this->anything());
$this->middleware->beforeController($this->contoller, __FUNCTION__);
$this->middleware->beforeController($this->controller, __FUNCTION__);
}
/**
@ -90,7 +95,7 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$this->userSession->expects($this->never())
->method($this->anything());
$this->middleware->beforeController($this->contoller, __FUNCTION__);
$this->middleware->beforeController($this->controller, __FUNCTION__);
}
/**
@ -128,7 +133,7 @@ class PasswordConfirmationMiddlewareTest extends TestCase {
$thrown = false;
try {
$this->middleware->beforeController($this->contoller, __FUNCTION__);
$this->middleware->beforeController($this->controller, __FUNCTION__);
} catch (NotConfirmedException $e) {
$thrown = true;
}