Adding test to Auth.test to cover logged in user being denied on an action when there is no HTTP_REFERER set. Refs #5507.

Fixed tests that break when Routing.admin is not set.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7687 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-10-02 00:18:47 +00:00
parent 62184023d5
commit 915a1e119d
2 changed files with 83 additions and 62 deletions

View file

@ -558,6 +558,7 @@ class AuthTest extends CakeTestCase {
$this->assertFalse($result);
}
/**
* testAuthorizeCrud method
*
@ -619,6 +620,7 @@ class AuthTest extends CakeTestCase {
$this->Controller->Auth->startup($this->Controller);
$this->assertTrue($this->Controller->Session->check('Message.auth'));
}
/**
* testLoginRedirect method
*
@ -658,16 +660,34 @@ class AuthTest extends CakeTestCase {
$this->Controller->Session->del('Auth');
//empty referer no session
$_SERVER['HTTP_REFERER'] = false;
$_ENV['HTTP_REFERER'] = false;
putenv('HTTP_REFERER=');
$url = '/posts/view/1';
$this->Controller->Session->write('Auth', array('AuthUser' => array('id'=>'1', 'username'=>'nate')));
$this->Controller->testUrl = null;
$this->Controller->params = Router::parse($url);
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->authorize = 'controller';
$this->Controller->params['testControllerAuth'] = true;
$this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login');
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->startup($this->Controller);
$expected = Router::normalize('/');
$this->assertEqual($expected, $this->Controller->testUrl);
$this->Controller->Session->del('Auth');
$_SERVER['HTTP_REFERER'] = '/admin/';
$this->Controller->Session->write('Auth', array('AuthUser' => array('id'=>'1', 'username'=>'nate')));
$this->Controller->params['url']['url'] = 'auth_test/login';
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = 'auth_test/login';
$this->Controller->Auth->userModel = 'AuthUser';
$this->Controller->Auth->loginRedirect = false;
$this->Controller->Auth->startup($this->Controller);
@ -697,7 +717,6 @@ class AuthTest extends CakeTestCase {
$expected = Router::normalize('posts/view/1');
$this->assertEqual($expected, $this->Controller->Session->read('Auth.redirect'));
$_SERVER['HTTP_REFERER'] = $backup;
$this->Controller->Session->del('Auth');
}
@ -720,9 +739,7 @@ class AuthTest extends CakeTestCase {
$this->Controller->data['AuthUser']['password'] = '';
$this->Controller->params['url']['url'] = 'auth_test/login';
$this->Controller->Auth->initialize($this->Controller);
$this->Controller->Auth->loginAction = 'auth_test/login';
$this->Controller->Auth->userModel = 'AuthUser';
@ -845,9 +862,9 @@ class AuthTest extends CakeTestCase {
* @return void
*/
function testAdminRoute() {
Router::reload();
$admin = Configure::read('Routing.admin');
Configure::write('Routing.admin', 'admin');
Router::reload();
$url = '/admin/something';
$this->Controller->params = Router::parse($url);
@ -900,9 +917,9 @@ class AuthTest extends CakeTestCase {
* @return void
*/
function testLoginActionRedirect() {
Router::reload();
$admin = Configure::read('Routing.admin');
Configure::write('Routing.admin', 'admin');
Router::reload();
$url = '/admin/auth_test/login';
$this->Controller->params = Router::parse($url);

View file

@ -219,6 +219,9 @@ class ScaffoldViewTest extends CakeTestCase {
* @return void
*/
function testGetViewFilename() {
$_admin = Configure::read('Routing.admin');
Configure::write('Routing.admin', 'admin');
$this->Controller->action = 'index';
$ScaffoldView =& new TestScaffoldView($this->Controller);
$result = $ScaffoldView->testGetFilename('index');
@ -295,6 +298,7 @@ class ScaffoldViewTest extends CakeTestCase {
Configure::write('viewPaths', $_back['viewPaths']);
Configure::write('pluginPaths', $_back['pluginPaths']);
Configure::write('Routing.admin', $_admin);
}
/**