Skip to content

Commit

Permalink
Merge pull request #1479 from nextcloud/stable10-backport-1188
Browse files Browse the repository at this point in the history
[stable10] redirect to default app after solving the 2FA challenge
  • Loading branch information
LukasReschke committed Sep 28, 2016
2 parents 766abee + b824706 commit 3102afa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
6 changes: 4 additions & 2 deletions core/Controller/TwoFactorChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
namespace OC\Core\Controller;

use OC\Authentication\TwoFactorAuth\Manager;
use OC_User;
use OC_Util;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
Expand Down Expand Up @@ -67,7 +69,7 @@ public function __construct($appName, IRequest $request, Manager $twoFactorManag
* @return string
*/
protected function getLogoutAttribute() {
return \OC_User::getLogoutAttribute();
return OC_User::getLogoutAttribute();
}

/**
Expand Down Expand Up @@ -143,7 +145,7 @@ public function solveChallenge($challengeProviderId, $challenge, $redirect_url =
if (!is_null($redirect_url)) {
return new RedirectResponse($this->urlGenerator->getAbsoluteURL(urldecode($redirect_url)));
}
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index'));
return new RedirectResponse(OC_Util::getDefaultPageUrl());
}

$this->session->set('two_factor_auth_error', true);
Expand Down
26 changes: 11 additions & 15 deletions tests/Core/Controller/TwoFactorChallengeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class TwoFactorChallengeControllerTest extends TestCase {
protected function setUp() {
parent::setUp();

$this->request = $this->getMock('\OCP\IRequest');
$this->request = $this->getMockBuilder('\OCP\IRequest')->getMock();
$this->twoFactorManager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager')
->disableOriginalConstructor()
->getMock();
$this->userSession = $this->getMock('\OCP\IUserSession');
$this->session = $this->getMock('\OCP\ISession');
$this->urlGenerator = $this->getMock('\OCP\IURLGenerator');
$this->userSession = $this->getMockBuilder('\OCP\IUserSession')->getMock();
$this->session = $this->getMockBuilder('\OCP\ISession')->getMock();
$this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')->getMock();

$this->controller = $this->getMockBuilder('OC\Core\Controller\TwoFactorChallengeController')
->setConstructorArgs([
Expand All @@ -64,7 +64,7 @@ protected function setUp() {
}

public function testSelectChallenge() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$providers = [
'prov1',
'prov2',
Expand All @@ -88,7 +88,7 @@ public function testSelectChallenge() {
}

public function testShowChallenge() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$provider = $this->getMockBuilder('\OCP\Authentication\TwoFactorAuth\IProvider')
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -130,7 +130,7 @@ public function testShowChallenge() {
}

public function testShowInvalidChallenge() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();

$this->userSession->expects($this->once())
->method('getUser')
Expand All @@ -150,7 +150,7 @@ public function testShowInvalidChallenge() {
}

public function testSolveChallenge() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$provider = $this->getMockBuilder('\OCP\Authentication\TwoFactorAuth\IProvider')
->disableOriginalConstructor()
->getMock();
Expand All @@ -167,17 +167,13 @@ public function testSolveChallenge() {
->method('verifyChallenge')
->with('myprovider', $user, 'token')
->will($this->returnValue(true));
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('files.view.index')
->will($this->returnValue('files/index/url'));

$expected = new \OCP\AppFramework\Http\RedirectResponse('files/index/url');
$expected = new \OCP\AppFramework\Http\RedirectResponse(\OC_Util::getDefaultPageUrl());
$this->assertEquals($expected, $this->controller->solveChallenge('myprovider', 'token'));
}

public function testSolveChallengeInvalidProvider() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();

$this->userSession->expects($this->once())
->method('getUser')
Expand All @@ -197,7 +193,7 @@ public function testSolveChallengeInvalidProvider() {
}

public function testSolveInvalidChallenge() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$provider = $this->getMockBuilder('\OCP\Authentication\TwoFactorAuth\IProvider')
->disableOriginalConstructor()
->getMock();
Expand Down

0 comments on commit 3102afa

Please sign in to comment.