Skip to content

Commit

Permalink
Removing call to RequestHandler as its just a pass through to the req…
Browse files Browse the repository at this point in the history
…uest object which is available in that scope. Updating the test cases to not use deprecated and non-existent things.
  • Loading branch information
markstory committed Sep 15, 2010
1 parent 97dd7c7 commit 0baaf68
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cake/libs/controller/components/auth.php
Expand Up @@ -377,7 +377,7 @@ public function startup(&$controller) {
return false;
} else {
if (!$this->user()) {
if (!$this->RequestHandler->isAjax()) {
if (!$request->is('ajax')) {
$this->Session->setFlash($this->authError, $this->flashElement, array(), 'auth');
if (!empty($request->query) && count($request->query) >= 2) {
$query = $request->query;
Expand Down
42 changes: 29 additions & 13 deletions cake/tests/cases/libs/controller/components/auth.test.php
Expand Up @@ -17,6 +17,7 @@
* @since CakePHP(tm) v 1.2.0.5347
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Core', 'Controller');
App::import('Component', array('Auth', 'Acl'));
App::import('Model', 'DbAcl');
App::import('Core', 'Xml');
Expand Down Expand Up @@ -493,8 +494,10 @@ function setUp() {
$request = new CakeRequest(null, false);

$this->Controller = new AuthTestController($request);
$this->Controller->Component->init($this->Controller);
$this->Controller->Component->initialize($this->Controller);
$this->Controller->Components->init($this->Controller);
$this->Controller->Components->trigger(
'initialize', array(&$this->Controller), array('triggerDisabled' => true)
);
$this->Controller->beforeFilter();

ClassRegistry::addObject('view', new View($this->Controller));
Expand Down Expand Up @@ -641,7 +644,6 @@ function testLogin() {
* @return void
*/
function testLoginActionNotSettingAuthRedirect() {
$_referer = $_SERVER['HTTP_REFERER'];
$_SERVER['HTTP_REFERER'] = '/pages/display/about';

$this->Controller->data = array();
Expand Down Expand Up @@ -1065,7 +1067,9 @@ function testLoginRedirect() {
);
$this->Controller->Session->delete('Auth');
$url = '/posts/index/29';
$this->Controller->request = Dispatcher::parseParams(new CakeRequest($url));
$this->Controller->request = new CakeRequest($url);
$this->Controller->request->addParams(Router::parse($url));

$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
Expand All @@ -1081,7 +1085,9 @@ function testLoginRedirect() {
);
$this->Controller->Session->delete('Auth');
$url = '/posts/index/29';
$this->Controller->request = Dispatcher::parseParams(new CakeRequest($url));
$this->Controller->request = new CakeRequest($url);
$this->Controller->request->addParams(Router::parse($url));

$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
Expand All @@ -1094,6 +1100,7 @@ function testLoginRedirect() {
$_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';
$this->Controller->Session->delete('Auth');
$url = '/posts/edit/1';
$this->Controller->request = new CakeRequest($url);
$this->Controller->request->addParams(Router::parse($url));
$this->Controller->request->query = array('url' => Router::normalize($url));
$this->Controller->Auth->initialize($this->Controller);
Expand All @@ -1107,6 +1114,7 @@ function testLoginRedirect() {
$_SERVER['HTTP_REFERER'] = 'http://webmail.example.com/view/message';
$this->Controller->Session->delete('Auth');
$url = '/AuthTest/login';
$this->Controller->request = new CakeRequest($url);
$this->Controller->request->addParams(Router::parse($url));
$this->Controller->request->query['url'] = Router::normalize($url);
$this->Controller->Auth->initialize($this->Controller);
Expand Down Expand Up @@ -1192,8 +1200,12 @@ function testInjection() {

$this->Controller->Session->delete($this->Controller->Auth->sessionKey);

$this->Controller->data['AuthUser']['username'] = 'nate';
$this->Controller->data['AuthUser']['password'] = 'cake1';
$this->Controller->request->data = array(
'AuthUser' => array(
'username' => 'nate',
'password' => 'cake1'
)
);
$this->Controller->request->query['url'] = 'auth_test/login';
$this->Controller->Auth->initialize($this->Controller);

Expand All @@ -1204,22 +1216,26 @@ function testInjection() {

$this->Controller->Session->delete($this->Controller->Auth->sessionKey);

$this->Controller->data['AuthUser']['username'] = '> n';
$this->Controller->data['AuthUser']['password'] = 'cake';
$this->Controller->request->data = array(
'AuthUser' => array(
'username' => '> n',
'password' => 'cake'
)
);
$this->Controller->Auth->initialize($this->Controller);

$this->Controller->Auth->startup($this->Controller);
$this->assertTrue(is_null($this->Controller->Auth->user()));

unset($this->Controller->data['AuthUser']['password']);
$this->Controller->data['AuthUser']['username'] = "1'1";
unset($this->Controller->request->data['AuthUser']['password']);
$this->Controller->request->data['AuthUser']['username'] = "1'1";
$this->Controller->Auth->initialize($this->Controller);

$this->Controller->Auth->startup($this->Controller);
$this->assertTrue(is_null($this->Controller->Auth->user()));

unset($this->Controller->data['AuthUser']['username']);
$this->Controller->data['AuthUser']['password'] = "1'1";
unset($this->Controller->request->data['AuthUser']['username']);
$this->Controller->request->data['AuthUser']['password'] = "1'1";
$this->Controller->Auth->initialize($this->Controller);

$this->Controller->Auth->startup($this->Controller);
Expand Down

0 comments on commit 0baaf68

Please sign in to comment.