Skip to content

Commit

Permalink
Fixing broken tests refs #5687
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7986 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Jan 14, 2009
1 parent c0f767a commit ba42eb0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cake/libs/controller/components/auth.php
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
33 changes: 27 additions & 6 deletions cake/tests/cases/libs/controller/components/auth.test.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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));
}
/**
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand All @@ -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';
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ba42eb0

Please sign in to comment.