diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index b299ec1009f..135b532df38 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -264,7 +264,8 @@ function initialize(&$controller) { function startup(&$controller) { $isErrorOrTests = ( strtolower($controller->name) == 'cakeerror' || - (strtolower($controller->name) == 'tests' && Configure::read() > 0) + (strtolower($controller->name) == 'tests' && Configure::read() > 0) || + !in_array($controller->params['action'], $controller->methods) ); if ($isErrorOrTests) { return true; @@ -283,7 +284,7 @@ function startup(&$controller) { $loginAction = Router::normalize($this->loginAction); $isAllowed = ( $this->allowedActions == array('*') || - in_array($controller->action, $this->allowedActions) + in_array($controller->params['action'], $this->allowedActions) ); if ($loginAction != $url && $isAllowed) { diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 54c38bce365..013f16f3716 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -451,6 +451,7 @@ function testLogin() { $this->Controller->data['AuthUser']['username'] = $authUser['AuthUser']['username']; $this->Controller->data['AuthUser']['password'] = 'cake'; + $this->Controller->params = Router::parse('auth_test/login'); $this->Controller->params['url']['url'] = 'auth_test/login'; $this->Controller->Auth->initialize($this->Controller); @@ -515,6 +516,7 @@ function testAuthorizeFalse() { $this->Controller->Session->write('Auth', $user); $this->Controller->Auth->userModel = 'AuthUser'; $this->Controller->Auth->authorize = false; + $this->Controller->params = Router::parse('auth_test/add'); $result = $this->Controller->Auth->startup($this->Controller); $this->assertTrue($result); @@ -534,6 +536,7 @@ function testAuthorizeController() { $this->Controller->Session->write('Auth', $user); $this->Controller->Auth->userModel = 'AuthUser'; $this->Controller->Auth->authorize = 'controller'; + $this->Controller->params = Router::parse('auth_test/add'); $result = $this->Controller->Auth->startup($this->Controller); $this->assertTrue($result); @@ -643,10 +646,10 @@ function testAllowDenyAll() { $this->Controller->Auth->allow('*'); $this->Controller->Auth->deny('add'); - $this->Controller->action = 'delete'; + $this->Controller->params['action'] = 'delete'; $this->assertTrue($this->Controller->Auth->startup($this->Controller)); - $this->Controller->action = 'add'; + $this->Controller->params['action'] = 'add'; $this->assertFalse($this->Controller->Auth->startup($this->Controller)); } /** @@ -668,6 +671,7 @@ function testLoginRedirect() { 'AuthUser' => array('id' => '1', 'username' => 'nate') )); + $this->Controller->params = Router::parse('users/login'); $this->Controller->params['url']['url'] = 'users/login'; $this->Controller->Auth->initialize($this->Controller); @@ -703,6 +707,8 @@ function testLoginRedirect() { ); $this->Controller->testUrl = null; $this->Controller->params = Router::parse($url); + array_push($this->Controller->methods, 'view', 'edit', 'index'); + $this->Controller->Auth->initialize($this->Controller); $this->Controller->Auth->authorize = 'controller'; $this->Controller->params['testControllerAuth'] = true; @@ -785,6 +791,19 @@ function testLoginRedirect() { $_SERVER['HTTP_REFERER'] = $backup; $this->Controller->Session->del('Auth'); } +/** + * Ensure that no redirect is performed when a 404 is reached + * And the user doesn't have a session. + * + * @return void + **/ + function testNoRedirectOn404() { + $this->Controller->Session->del('Auth'); + $this->Controller->Auth->initialize($this->Controller); + $this->Controller->params = Router::parse('auth_test/something_totally_wrong'); + $result = $this->Controller->Auth->startup($this->Controller); + $this->assertTrue($result, 'Auth redirected a missing action %s'); + } /** * testEmptyUsernameOrPassword method * @@ -803,6 +822,7 @@ function testEmptyUsernameOrPassword() { $this->Controller->data['AuthUser']['username'] = ''; $this->Controller->data['AuthUser']['password'] = ''; + $this->Controller->params = Router::parse('auth_test/login'); $this->Controller->params['url']['url'] = 'auth_test/login'; $this->Controller->Auth->initialize($this->Controller); $this->Controller->Auth->loginAction = 'auth_test/login'; @@ -827,6 +847,7 @@ function testInjection() { $this->Controller->data['AuthUser']['username'] = 'nate'; $this->Controller->data['AuthUser']['password'] = 'cake'; + $this->Controller->params = Router::parse('auth_test/login'); $this->Controller->params['url']['url'] = 'auth_test/login'; $this->Controller->Auth->initialize($this->Controller); @@ -862,7 +883,7 @@ function testInjection() { $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"; $this->Controller->Auth->initialize($this->Controller); @@ -953,13 +974,13 @@ function testAdminRoute() { Configure::write('Routing.admin', 'admin'); Router::reload(); - $url = '/admin/something'; + $url = '/admin/auth_test/add'; $this->Controller->params = Router::parse($url); $this->Controller->params['url']['url'] = ltrim($url, '/'); Router::setRequestInfo(array( array( - 'pass' => array(), 'action' => 'index', 'plugin' => null, - 'controller' => 'something', 'admin' => true, + 'pass' => array(), 'action' => 'add', 'plugin' => null, + 'controller' => 'auth_test', 'admin' => true, 'url' => array('url' => $this->Controller->params['url']['url']) ), array(