Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] redirect to default app after solving the 2FA challenge #1479

Merged
merged 2 commits into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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