Skip to content

Commit

Permalink
Skip two factor challenge in account module middleware
Browse files Browse the repository at this point in the history
Fixes issue with infinite redirect when trying to access the challenge
page.
  • Loading branch information
Vincent Petry committed Jul 25, 2018
1 parent cffb487 commit fb10062
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/Middleware/AccountModuleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\Authentication\IAccountModuleController;
use OCP\ILogger;
use OCP\IUserSession;
use OC\Core\Controller\TwoFactorChallengeController;

/**
* Class AccountModuleMiddleware
Expand Down Expand Up @@ -94,6 +95,11 @@ public function beforeController($controller, $methodName) {
return;
}

if ($controller instanceof TwoFactorChallengeController) {
// Don't block two factor challenge
return;
}

if ($this->session->isLoggedIn()) {
$user = $this->session->getUser();
if ($user === null) {
Expand Down
13 changes: 13 additions & 0 deletions tests/Core/Middleware/AccountModuleMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\IUser;
use OCP\IUserSession;
use Test\TestCase;
use OC\Core\Controller\TwoFactorChallengeController;

class AccountModuleMiddlewareTest extends TestCase {

Expand Down Expand Up @@ -102,6 +103,18 @@ public function testBeforeControllerAccountModuleController() {

$this->middleware->beforeController($controller, null);
}
public function testBeforeControllerSkipsTwoFactorChallengeController() {
$this->reflector->expects($this->once())
->method('hasAnnotation')
->with('PublicPage')
->will($this->returnValue(false));
$this->userSession->expects($this->never())
->method('isLoggedIn');

$controller = $this->createMock(TwoFactorChallengeController::class);

$this->middleware->beforeController($controller, null);
}

public function testBeforeControllerNotLoggedIn() {
$this->reflector->expects($this->once())
Expand Down

0 comments on commit fb10062

Please sign in to comment.