Skip to content

Commit

Permalink
#223 - updated the LoginController::doLoginAndRedirect() method to su…
Browse files Browse the repository at this point in the history
…pport redirecting to an absolute URL and added a unit test to cover it
  • Loading branch information
alphadevx committed Dec 29, 2017
1 parent 806b0bf commit 8f90bb8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Alpha/Controller/LoginController.php
Expand Up @@ -7,6 +7,7 @@
use Alpha\Util\Http\Request;
use Alpha\Util\Http\Response;
use Alpha\Util\Http\Session\SessionProviderFactory;
use Alpha\Util\Helper\Validator;
use Alpha\View\View;
use Alpha\View\PersonView;
use Alpha\Model\Person;
Expand Down Expand Up @@ -314,7 +315,10 @@ protected function doLoginAndRedirect($password)
self::$logger->action('Login');

$response = new Response(301);
if ($this->getNextJob() != '') {
if (Validator::isURL($this->getNextJob())) {
$response->redirect($this->getNextJob());
$this->clearUnitOfWorkAttributes();
} elseif ($this->getNextJob() != '') {
$response->redirect(FrontController::generateSecureURL('act='.$this->getNextJob()));
$this->clearUnitOfWorkAttributes();
} else {
Expand Down
21 changes: 21 additions & 0 deletions test/Alpha/Test/Controller/LoginControllerTest.php
Expand Up @@ -9,6 +9,7 @@
use Alpha\Util\Http\Session\SessionProviderFactory;
use Alpha\Model\Person;
use Alpha\Model\Rights;
use Alpha\Model\ActionLog;

/**
* Test cases for the LoginController class.
Expand Down Expand Up @@ -71,6 +72,9 @@ protected function setUp()
$rights->rebuildTable();
$rights->set('name', 'Standard');
$rights->save();

$log = new ActionLog();
$log->rebuildTable();
}

/**
Expand Down Expand Up @@ -167,6 +171,23 @@ public function testDoPOST()

$this->assertEquals(200, $response->getStatus(), 'Testing the doPOST with incorrect password');

$params = array(
'loginBut' => true,
'var1' => $securityParams[0],
'var2' => $securityParams[1],
'email' => 'logintest@test.com',
'password' => 'passwordTest',
);

$controller->setUnitOfWork(array('Alpha\Controller\LoginController','http://www.alphaframework.org/'));

$request = new Request(array('method' => 'POST', 'URI' => '/login', 'params' => $params));

$response = $front->process($request);

$this->assertEquals(301, $response->getStatus(), 'Testing the doPOST method can redirect to any URL via the unit of work next action field');
$this->assertEquals('http://www.alphaframework.org/', $response->getHeader('Location'), 'Testing the doPOST method can redirect to any URL via the unit of work next action field');

$params = array(
'resetBut' => true,
'var1' => $securityParams[0],
Expand Down

0 comments on commit 8f90bb8

Please sign in to comment.