Skip to content

Commit

Permalink
Adding test for host url redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Sep 8, 2016
1 parent cfadb8f commit ffa464d
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -23,8 +23,8 @@
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\ORM\TableRegistry;
use Cake\Routing\Route\InflectedRoute;
use Cake\Routing\Router;
use Cake\Routing\Route\InflectedRoute;
use Cake\TestSuite\TestCase;
use Cake\Utility\Security;
use TestApp\Controller\AuthTestController;
Expand Down Expand Up @@ -1326,10 +1326,10 @@ public function testRedirectSet()
public function testRedirectQueryStringRead()
{
$this->Auth->config('loginAction', ['controller' => 'users', 'action' => 'login']);
$this->Auth->request->query = ['redirect' => '/users/home'];
$this->Auth->request->query = ['redirect' => '/users/custom'];

$result = $this->Auth->redirectUrl();
$this->assertEquals('/users/home', $result);
$this->assertEquals('/users/custom', $result);
}

/**
Expand Down Expand Up @@ -1368,6 +1368,24 @@ public function testRedirectQueryStringReadEqualToLoginAction()
$this->assertEquals('/users/home', $result);
}

/**
* Tests that redirect does not return loginAction if that contains a host,
* instead loginRedirect should be used.
*
* @return void
*/
public function testRedirectQueryStringInvalid()
{
$this->Auth->config([
'loginAction' => ['controller' => 'users', 'action' => 'login'],
'loginRedirect' => ['controller' => 'users', 'action' => 'home']
]);
$this->Auth->request->query = ['redirect' => 'http://some.domain.example/users/login'];

$result = $this->Auth->redirectUrl();
$this->assertEquals('/users/home', $result);
}

/**
* test that the returned URL doesn't contain the base URL.
*
Expand Down

0 comments on commit ffa464d

Please sign in to comment.