From d8c0c67e2b509a55f62f8d87bbf501353c86c6b8 Mon Sep 17 00:00:00 2001 From: chartjes Date: Sat, 7 Jul 2007 21:24:21 +0000 Subject: [PATCH] Incomplete test for Auth component, committing so gwoo can work on it git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5387 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../libs/controller/components/auth.test.php | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 cake/tests/cases/libs/controller/components/auth.test.php diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php new file mode 100644 index 000000000..e5cdb4a81 --- /dev/null +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -0,0 +1,114 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.cake.tests.cases.libs.controller.components + * @since CakePHP(tm) v 1.2.0.5347 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +require_once LIBS . '/controller/components/auth.php'; + +class AuthTestUser extends CakeTestModel { + var $name = 'AuthTestUser'; +} + +class AuthTestController extends Controller { + var $name = 'AuthTest'; + var $uses = 'AuthTestUser'; + var $components = array('Auth', 'Acl'); + + function beforeFilter() { + $this->Auth->userModel('AuthTestUser'); + $this->Auth->logoutAction = 'login'; + $this->Auth->allow('logout'); + $this->Auth->authorize = 'controller'; + } + + function login() { + } + + function logout() { + $this->redirect($this->Auth->logout()); + } + + function add() { + } + + function redirect($url) { + return $url; + } + + function isAuthorized() { + return true; + } + + function parentNode() { + return true; + } + + function bindNode($object) { + return 'Roles/User'; + } +} + +loadModel('AuthTestUser'); + +class AuthTest extends CakeTestCase { + var $name = 'Auth'; + var $fixtures = array('auth_test_user', 'aco', 'aro', 'aros_aco'); + + function startCase() { + $this->Controller =& new AuthTestController(); + restore_error_handler(); + @$this->Controller->_initComponents(); + set_error_handler('simpleTestErrorHandler'); + $this->Controller->Auth->startup(&$this->Controller); + ClassRegistry::addObject('view', new View($this->Controller)); + $this->AuthTestUser = new AuthTestUser; + } + + function testNoAuth() { + $this->assertFalse($this->Controller->Auth->isAuthorized($this->Controller)); + } + + function testUserData() { + foreach ($this->AuthTestUser->findAll() as $key => $result) { + $result['AuthTestUser']['password'] = Security::hash(CAKE_SESSION_STRING . $result['AuthTestUser']['password']); + $this->AuthTestUser->save($result, false); + } + + $authTestUser = $this->AuthTestUser->read(); + $data['AuthTestUser']['username'] = $authTestUser['AuthTestUser']['username']; + $data['AuthTestUser']['password'] = $authTestUser['AuthTestUser']['password']; + $this->Controller->Auth->params['controller'] = 'AuthTest'; + $this->Controller->Auth->params['action'] = 'add'; + $this->Controller->Auth->Acl->Aro->create(1, null, 'chartjes'); + $this->Controller->Auth->Acl->Aro->create(0, null, 'Users'); + $this->Controller->Auth->Acl->Aro->setParent('Users', 1); + $this->Controller->Auth->Acl->Aco->create(0, null, '/Home/home'); + $this->Controller->Auth->Acl->allow('Users', 'Home/home'); + $this->assertTrue($this->Controller->Auth->isAuthorized($this->Controller, 'controller', 'AuthTestUser')); + + } +} +?>