mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-03 14:43:49 +02:00
Backup of current cakephp version
This commit is contained in:
parent
b8f82da6f8
commit
5a580df460
925 changed files with 238041 additions and 1 deletions
|
@ -0,0 +1,192 @@
|
|||
<?php
|
||||
/**
|
||||
* ActionsAuthorizeTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('ActionsAuthorize', 'Controller/Component/Auth');
|
||||
App::uses('ComponentCollection', 'Controller');
|
||||
App::uses('AclComponent', 'Controller/Component');
|
||||
App::uses('CakeRequest', 'Network');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
|
||||
class ActionsAuthorizeTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->controller = $this->getMock('Controller', array(), array(), '', false);
|
||||
$this->Acl = $this->getMock('AclComponent', array(), array(), '', false);
|
||||
$this->Collection = $this->getMock('ComponentCollection');
|
||||
|
||||
$this->auth = new ActionsAuthorize($this->Collection);
|
||||
$this->auth->settings['actionPath'] = '/controllers';
|
||||
}
|
||||
|
||||
/**
|
||||
* setup the mock acl.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _mockAcl() {
|
||||
$this->Collection->expects($this->any())
|
||||
->method('load')
|
||||
->with('Acl')
|
||||
->will($this->returnValue($this->Acl));
|
||||
}
|
||||
|
||||
/**
|
||||
* test failure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeFailure() {
|
||||
$user = array(
|
||||
'User' => array(
|
||||
'id' => 1,
|
||||
'user' => 'mariano'
|
||||
)
|
||||
);
|
||||
$request = new CakeRequest('/posts/index', false);
|
||||
$request->addParams(array(
|
||||
'plugin' => null,
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
));
|
||||
|
||||
$this->_mockAcl();
|
||||
|
||||
$this->Acl->expects($this->once())
|
||||
->method('check')
|
||||
->with($user, 'controllers/Posts/index')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->assertFalse($this->auth->authorize($user['User'], $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* test isAuthorized working.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeSuccess() {
|
||||
$user = array(
|
||||
'User' => array(
|
||||
'id' => 1,
|
||||
'user' => 'mariano'
|
||||
)
|
||||
);
|
||||
$request = new CakeRequest('/posts/index', false);
|
||||
$request->addParams(array(
|
||||
'plugin' => null,
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
));
|
||||
|
||||
$this->_mockAcl();
|
||||
|
||||
$this->Acl->expects($this->once())
|
||||
->method('check')
|
||||
->with($user, 'controllers/Posts/index')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->auth->authorize($user['User'], $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* testAuthorizeSettings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeSettings() {
|
||||
$request = new CakeRequest('/posts/index', false);
|
||||
$request->addParams(array(
|
||||
'plugin' => null,
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
));
|
||||
|
||||
$this->_mockAcl();
|
||||
|
||||
$this->auth->settings['userModel'] = 'TestPlugin.TestPluginAuthUser';
|
||||
$user = array(
|
||||
'id' => 1,
|
||||
'user' => 'mariano'
|
||||
);
|
||||
|
||||
$expected = array('TestPlugin.TestPluginAuthUser' => array('id' => 1, 'user' => 'mariano'));
|
||||
$this->Acl->expects($this->once())
|
||||
->method('check')
|
||||
->with($expected, 'controllers/Posts/index')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->auth->authorize($user, $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* test action()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testActionMethod() {
|
||||
$request = new CakeRequest('/posts/index', false);
|
||||
$request->addParams(array(
|
||||
'plugin' => null,
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
));
|
||||
|
||||
$result = $this->auth->action($request);
|
||||
$this->assertEquals('controllers/Posts/index', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that action() doesn't create double slashes anywhere.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testActionNoDoubleSlash() {
|
||||
$this->auth->settings['actionPath'] = '/controllers/';
|
||||
$request = array(
|
||||
'plugin' => null,
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
);
|
||||
$result = $this->auth->action($request);
|
||||
$this->assertEquals('controllers/Posts/index', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test action() and plugins
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testActionWithPlugin() {
|
||||
$request = new CakeRequest('/debug_kit/posts/index', false);
|
||||
$request->addParams(array(
|
||||
'plugin' => 'debug_kit',
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
));
|
||||
|
||||
$result = $this->auth->action($request);
|
||||
$this->assertEquals('controllers/DebugKit/Posts/index', $result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
/**
|
||||
* BasicAuthenticateTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('AuthComponent', 'Controller/Component');
|
||||
App::uses('BasicAuthenticate', 'Controller/Component/Auth');
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('CakeRequest', 'Network');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
|
||||
|
||||
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
|
||||
|
||||
/**
|
||||
* Test case for BasicAuthentication
|
||||
*
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
*/
|
||||
class BasicAuthenticateTest extends CakeTestCase {
|
||||
|
||||
public $fixtures = array('core.user', 'core.auth_user');
|
||||
|
||||
/**
|
||||
* setup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Collection = $this->getMock('ComponentCollection');
|
||||
$this->auth = new BasicAuthenticate($this->Collection, array(
|
||||
'fields' => array('username' => 'user', 'password' => 'password'),
|
||||
'userModel' => 'User',
|
||||
'realm' => 'localhost',
|
||||
'recursive' => 0
|
||||
));
|
||||
|
||||
$password = Security::hash('password', null, true);
|
||||
$User = ClassRegistry::init('User');
|
||||
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
|
||||
$this->response = $this->getMock('CakeResponse');
|
||||
}
|
||||
|
||||
/**
|
||||
* test applying settings in the constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor() {
|
||||
$object = new BasicAuthenticate($this->Collection, array(
|
||||
'userModel' => 'AuthUser',
|
||||
'fields' => array('username' => 'user', 'password' => 'password')
|
||||
));
|
||||
$this->assertEquals('AuthUser', $object->settings['userModel']);
|
||||
$this->assertEquals(array('username' => 'user', 'password' => 'password'), $object->settings['fields']);
|
||||
$this->assertEquals(env('SERVER_NAME'), $object->settings['realm']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateNoData() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
|
||||
$this->response->expects($this->once())
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Basic realm="localhost"');
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateNoUsername() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$_SERVER['PHP_AUTH_PW'] = 'foobar';
|
||||
|
||||
$this->response->expects($this->once())
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Basic realm="localhost"');
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateNoPassword() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$_SERVER['PHP_AUTH_USER'] = 'mariano';
|
||||
$_SERVER['PHP_AUTH_PW'] = null;
|
||||
|
||||
$this->response->expects($this->once())
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Basic realm="localhost"');
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateInjection() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$_SERVER['PHP_AUTH_USER'] = '> 1';
|
||||
$_SERVER['PHP_AUTH_PW'] = "' OR 1 = 1";
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that challenge headers are sent when no credentials are found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateChallenge() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$this->response->expects($this->at(0))
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Basic realm="localhost"');
|
||||
|
||||
$this->response->expects($this->at(1))
|
||||
->method('send');
|
||||
|
||||
$result = $this->auth->authenticate($request, $this->response);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test authenticate sucesss
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateSuccess() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$_SERVER['PHP_AUTH_USER'] = 'mariano';
|
||||
$_SERVER['PHP_AUTH_PW'] = 'password';
|
||||
|
||||
$result = $this->auth->authenticate($request, $this->response);
|
||||
$expected = array(
|
||||
'id' => 1,
|
||||
'user' => 'mariano',
|
||||
'created' => '2007-03-17 01:16:23',
|
||||
'updated' => '2007-03-17 01:18:31'
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test scope failure.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateFailReChallenge() {
|
||||
$this->auth->settings['scope'] = array('user' => 'nate');
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$_SERVER['PHP_AUTH_USER'] = 'mariano';
|
||||
$_SERVER['PHP_AUTH_PW'] = 'password';
|
||||
|
||||
$this->response->expects($this->at(0))
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Basic realm="localhost"');
|
||||
|
||||
$this->response->expects($this->at(1))
|
||||
->method('statusCode')
|
||||
->with(401);
|
||||
|
||||
$this->response->expects($this->at(2))
|
||||
->method('send');
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* ControllerAuthorizeTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('Controller', 'Controller');
|
||||
App::uses('ControllerAuthorize', 'Controller/Component/Auth');
|
||||
App::uses('CakeRequest', 'Network');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
|
||||
class ControllerAuthorizeTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->controller = $this->getMock('Controller', array('isAuthorized'), array(), '', false);
|
||||
$this->components = $this->getMock('ComponentCollection');
|
||||
$this->components->expects($this->any())
|
||||
->method('getController')
|
||||
->will($this->returnValue($this->controller));
|
||||
|
||||
$this->auth = new ControllerAuthorize($this->components);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error
|
||||
*/
|
||||
public function testControllerTypeError() {
|
||||
$this->auth->controller(new StdClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException CakeException
|
||||
*/
|
||||
public function testControllerErrorOnMissingMethod() {
|
||||
$this->auth->controller(new Controller());
|
||||
}
|
||||
|
||||
/**
|
||||
* test failure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeFailure() {
|
||||
$user = array();
|
||||
$request = new CakeRequest('/posts/index', false);
|
||||
$this->assertFalse($this->auth->authorize($user, $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* test isAuthorized working.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeSuccess() {
|
||||
$user = array('User' => array('username' => 'mark'));
|
||||
$request = new CakeRequest('/posts/index', false);
|
||||
|
||||
$this->controller->expects($this->once())
|
||||
->method('isAuthorized')
|
||||
->with($user)
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->auth->authorize($user, $request));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
/**
|
||||
* CrudAuthorizeTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('CrudAuthorize', 'Controller/Component/Auth');
|
||||
App::uses('ComponentCollection', 'Controller');
|
||||
App::uses('AclComponent', 'Controller/Component');
|
||||
App::uses('CakeRequest', 'Network');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
|
||||
class CrudAuthorizeTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
Configure::write('Routing.prefixes', array());
|
||||
|
||||
$this->Acl = $this->getMock('AclComponent', array(), array(), '', false);
|
||||
$this->Components = $this->getMock('ComponentCollection');
|
||||
|
||||
$this->auth = new CrudAuthorize($this->Components);
|
||||
}
|
||||
|
||||
/**
|
||||
* setup the mock acl.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _mockAcl() {
|
||||
$this->Components->expects($this->any())
|
||||
->method('load')
|
||||
->with('Acl')
|
||||
->will($this->returnValue($this->Acl));
|
||||
}
|
||||
|
||||
/**
|
||||
* test authorize() without a mapped action, ensure an error is generated.
|
||||
*
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeNoMappedAction() {
|
||||
$request = new CakeRequest('/posts/foobar', false);
|
||||
$request->addParams(array(
|
||||
'controller' => 'posts',
|
||||
'action' => 'foobar'
|
||||
));
|
||||
$user = array('User' => array('user' => 'mark'));
|
||||
|
||||
$this->auth->authorize($user, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* test check() passing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeCheckSuccess() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array(
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
));
|
||||
$user = array('User' => array('user' => 'mark'));
|
||||
|
||||
$this->_mockAcl();
|
||||
$this->Acl->expects($this->once())
|
||||
->method('check')
|
||||
->with($user, 'Posts', 'read')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($this->auth->authorize($user['User'], $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* test check() failing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorizeCheckFailure() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array(
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
));
|
||||
$user = array('User' => array('user' => 'mark'));
|
||||
|
||||
$this->_mockAcl();
|
||||
$this->Acl->expects($this->once())
|
||||
->method('check')
|
||||
->with($user, 'Posts', 'read')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->assertFalse($this->auth->authorize($user['User'], $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting actionMap
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMapActionsGet() {
|
||||
$result = $this->auth->mapActions();
|
||||
$expected = array(
|
||||
'create' => 'create',
|
||||
'read' => 'read',
|
||||
'update' => 'update',
|
||||
'delete' => 'delete',
|
||||
'index' => 'read',
|
||||
'add' => 'create',
|
||||
'edit' => 'update',
|
||||
'view' => 'read',
|
||||
'remove' => 'delete'
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test adding into mapActions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMapActionsSet() {
|
||||
$map = array(
|
||||
'create' => array('generate'),
|
||||
'read' => array('listing', 'show'),
|
||||
'update' => array('update'),
|
||||
'random' => 'custom'
|
||||
);
|
||||
$result = $this->auth->mapActions($map);
|
||||
$this->assertNull($result);
|
||||
|
||||
$result = $this->auth->mapActions();
|
||||
$expected = array(
|
||||
'add' => 'create',
|
||||
'create' => 'create',
|
||||
'read' => 'read',
|
||||
'index' => 'read',
|
||||
'add' => 'create',
|
||||
'edit' => 'update',
|
||||
'view' => 'read',
|
||||
'delete' => 'delete',
|
||||
'remove' => 'delete',
|
||||
'generate' => 'create',
|
||||
'listing' => 'read',
|
||||
'show' => 'read',
|
||||
'update' => 'update',
|
||||
'random' => 'custom',
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test prefix routes getting auto mapped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutoPrefixMapActions() {
|
||||
Configure::write('Routing.prefixes', array('admin', 'manager'));
|
||||
Router::reload();
|
||||
|
||||
$auth = new CrudAuthorize($this->Components);
|
||||
$this->assertTrue(isset($auth->settings['actionMap']['admin_index']));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,306 @@
|
|||
<?php
|
||||
/**
|
||||
* DigestAuthenticateTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('DigestAuthenticate', 'Controller/Component/Auth');
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('CakeRequest', 'Network');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
|
||||
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
|
||||
|
||||
/**
|
||||
* Test case for DigestAuthentication
|
||||
*
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
*/
|
||||
class DigestAuthenticateTest extends CakeTestCase {
|
||||
|
||||
public $fixtures = array('core.user', 'core.auth_user');
|
||||
|
||||
/**
|
||||
* setup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Collection = $this->getMock('ComponentCollection');
|
||||
$this->server = $_SERVER;
|
||||
$this->auth = new DigestAuthenticate($this->Collection, array(
|
||||
'fields' => array('username' => 'user', 'password' => 'password'),
|
||||
'userModel' => 'User',
|
||||
'realm' => 'localhost',
|
||||
'nonce' => 123,
|
||||
'opaque' => '123abc'
|
||||
));
|
||||
|
||||
$password = DigestAuthenticate::password('mariano', 'cake', 'localhost');
|
||||
$User = ClassRegistry::init('User');
|
||||
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$this->response = $this->getMock('CakeResponse');
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
$_SERVER = $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* test applying settings in the constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor() {
|
||||
$object = new DigestAuthenticate($this->Collection, array(
|
||||
'userModel' => 'AuthUser',
|
||||
'fields' => array('username' => 'user', 'password' => 'password'),
|
||||
'nonce' => 123456
|
||||
));
|
||||
$this->assertEquals('AuthUser', $object->settings['userModel']);
|
||||
$this->assertEquals(array('username' => 'user', 'password' => 'password'), $object->settings['fields']);
|
||||
$this->assertEquals(123456, $object->settings['nonce']);
|
||||
$this->assertEquals(env('SERVER_NAME'), $object->settings['realm']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateNoData() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
|
||||
$this->response->expects($this->once())
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateWrongUsername() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$_SERVER['PHP_AUTH_DIGEST'] = <<<DIGEST
|
||||
Digest username="incorrect_user",
|
||||
realm="localhost",
|
||||
nonce="123456",
|
||||
uri="/dir/index.html",
|
||||
qop=auth,
|
||||
nc=00000001,
|
||||
cnonce="0a4f113b",
|
||||
response="6629fae49393a05397450978507c4ef1",
|
||||
opaque="123abc"
|
||||
DIGEST;
|
||||
|
||||
$this->response->expects($this->at(0))
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
||||
|
||||
$this->response->expects($this->at(1))
|
||||
->method('statusCode')
|
||||
->with(401);
|
||||
|
||||
$this->response->expects($this->at(2))
|
||||
->method('send');
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that challenge headers are sent when no credentials are found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateChallenge() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$this->response->expects($this->at(0))
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
||||
|
||||
$this->response->expects($this->at(1))
|
||||
->method('statusCode')
|
||||
->with(401);
|
||||
|
||||
$this->response->expects($this->at(2))
|
||||
->method('send');
|
||||
|
||||
$result = $this->auth->authenticate($request, $this->response);
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test authenticate success
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateSuccess() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$_SERVER['PHP_AUTH_DIGEST'] = <<<DIGEST
|
||||
Digest username="mariano",
|
||||
realm="localhost",
|
||||
nonce="123",
|
||||
uri="/dir/index.html",
|
||||
qop=auth,
|
||||
nc=1,
|
||||
cnonce="123",
|
||||
response="06b257a54befa2ddfb9bfa134224aa29",
|
||||
opaque="123abc"
|
||||
DIGEST;
|
||||
|
||||
$result = $this->auth->authenticate($request, $this->response);
|
||||
$expected = array(
|
||||
'id' => 1,
|
||||
'user' => 'mariano',
|
||||
'created' => '2007-03-17 01:16:23',
|
||||
'updated' => '2007-03-17 01:18:31'
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test scope failure.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateFailReChallenge() {
|
||||
$this->auth->settings['scope'] = array('user' => 'nate');
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->addParams(array('pass' => array(), 'named' => array()));
|
||||
|
||||
$_SERVER['PHP_AUTH_DIGEST'] = <<<DIGEST
|
||||
Digest username="mariano",
|
||||
realm="localhost",
|
||||
nonce="123",
|
||||
uri="/dir/index.html",
|
||||
qop=auth,
|
||||
nc=1,
|
||||
cnonce="123",
|
||||
response="6629fae49393a05397450978507c4ef1",
|
||||
opaque="123abc"
|
||||
DIGEST;
|
||||
|
||||
$this->response->expects($this->at(0))
|
||||
->method('header')
|
||||
->with('WWW-Authenticate: Digest realm="localhost",qop="auth",nonce="123",opaque="123abc"');
|
||||
|
||||
$this->response->expects($this->at(1))
|
||||
->method('statusCode')
|
||||
->with(401);
|
||||
|
||||
$this->response->expects($this->at(2))
|
||||
->method('send');
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* testParseDigestAuthData method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParseAuthData() {
|
||||
$digest = <<<DIGEST
|
||||
Digest username="Mufasa",
|
||||
realm="testrealm@host.com",
|
||||
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
|
||||
uri="/dir/index.html",
|
||||
qop=auth,
|
||||
nc=00000001,
|
||||
cnonce="0a4f113b",
|
||||
response="6629fae49393a05397450978507c4ef1",
|
||||
opaque="5ccc069c403ebaf9f0171e9517f40e41"
|
||||
DIGEST;
|
||||
$expected = array(
|
||||
'username' => 'Mufasa',
|
||||
'realm' => 'testrealm@host.com',
|
||||
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
||||
'uri' => '/dir/index.html',
|
||||
'qop' => 'auth',
|
||||
'nc' => '00000001',
|
||||
'cnonce' => '0a4f113b',
|
||||
'response' => '6629fae49393a05397450978507c4ef1',
|
||||
'opaque' => '5ccc069c403ebaf9f0171e9517f40e41'
|
||||
);
|
||||
$result = $this->auth->parseAuthData($digest);
|
||||
$this->assertSame($expected, $result);
|
||||
|
||||
$result = $this->auth->parseAuthData('');
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test parsing digest information with email addresses
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testParseAuthEmailAddress() {
|
||||
$digest = <<<DIGEST
|
||||
Digest username="mark@example.com",
|
||||
realm="testrealm@host.com",
|
||||
nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
|
||||
uri="/dir/index.html",
|
||||
qop=auth,
|
||||
nc=00000001,
|
||||
cnonce="0a4f113b",
|
||||
response="6629fae49393a05397450978507c4ef1",
|
||||
opaque="5ccc069c403ebaf9f0171e9517f40e41"
|
||||
DIGEST;
|
||||
$expected = array(
|
||||
'username' => 'mark@example.com',
|
||||
'realm' => 'testrealm@host.com',
|
||||
'nonce' => 'dcd98b7102dd2f0e8b11d0f600bfb0c093',
|
||||
'uri' => '/dir/index.html',
|
||||
'qop' => 'auth',
|
||||
'nc' => '00000001',
|
||||
'cnonce' => '0a4f113b',
|
||||
'response' => '6629fae49393a05397450978507c4ef1',
|
||||
'opaque' => '5ccc069c403ebaf9f0171e9517f40e41'
|
||||
);
|
||||
$result = $this->auth->parseAuthData($digest);
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test password hashing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPassword() {
|
||||
$result = DigestAuthenticate::password('mark', 'password', 'localhost');
|
||||
$expected = md5('mark:localhost:password');
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
/**
|
||||
* FormAuthenticateTest file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
App::uses('AuthComponent', 'Controller/Component');
|
||||
App::uses('FormAuthenticate', 'Controller/Component/Auth');
|
||||
App::uses('AppModel', 'Model');
|
||||
App::uses('CakeRequest', 'Network');
|
||||
App::uses('CakeResponse', 'Network');
|
||||
|
||||
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
|
||||
|
||||
/**
|
||||
* Test case for FormAuthentication
|
||||
*
|
||||
* @package Cake.Test.Case.Controller.Component.Auth
|
||||
*/
|
||||
class FormAuthenticateTest extends CakeTestCase {
|
||||
|
||||
public $fixtures = array('core.user', 'core.auth_user');
|
||||
|
||||
/**
|
||||
* setup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->Collection = $this->getMock('ComponentCollection');
|
||||
$this->auth = new FormAuthenticate($this->Collection, array(
|
||||
'fields' => array('username' => 'user', 'password' => 'password'),
|
||||
'userModel' => 'User'
|
||||
));
|
||||
$password = Security::hash('password', null, true);
|
||||
$User = ClassRegistry::init('User');
|
||||
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
|
||||
$this->response = $this->getMock('CakeResponse');
|
||||
}
|
||||
|
||||
/**
|
||||
* test applying settings in the constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor() {
|
||||
$object = new FormAuthenticate($this->Collection, array(
|
||||
'userModel' => 'AuthUser',
|
||||
'fields' => array('username' => 'user', 'password' => 'password')
|
||||
));
|
||||
$this->assertEquals('AuthUser', $object->settings['userModel']);
|
||||
$this->assertEquals(array('username' => 'user', 'password' => 'password'), $object->settings['fields']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateNoData() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->data = array();
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateNoUsername() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->data = array('User' => array('password' => 'foobar'));
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateNoPassword() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->data = array('User' => array('user' => 'mariano'));
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test the authenticate method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateInjection() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->data = array(
|
||||
'User' => array(
|
||||
'user' => '> 1',
|
||||
'password' => "' OR 1 = 1"
|
||||
));
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test authenticate success
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateSuccess() {
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->data = array('User' => array(
|
||||
'user' => 'mariano',
|
||||
'password' => 'password'
|
||||
));
|
||||
$result = $this->auth->authenticate($request, $this->response);
|
||||
$expected = array(
|
||||
'id' => 1,
|
||||
'user' => 'mariano',
|
||||
'created' => '2007-03-17 01:16:23',
|
||||
'updated' => '2007-03-17 01:18:31'
|
||||
);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test scope failure.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthenticateScopeFail() {
|
||||
$this->auth->settings['scope'] = array('user' => 'nate');
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->data = array('User' => array(
|
||||
'user' => 'mariano',
|
||||
'password' => 'password'
|
||||
));
|
||||
|
||||
$this->assertFalse($this->auth->authenticate($request, $this->response));
|
||||
}
|
||||
|
||||
/**
|
||||
* test a model in a plugin.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPluginModel() {
|
||||
Cache::delete('object_map', '_cake_core_');
|
||||
App::build(array(
|
||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
||||
), App::RESET);
|
||||
CakePlugin::load('TestPlugin');
|
||||
|
||||
$PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser');
|
||||
$user['id'] = 1;
|
||||
$user['username'] = 'gwoo';
|
||||
$user['password'] = Security::hash(Configure::read('Security.salt') . 'cake');
|
||||
$PluginModel->save($user, false);
|
||||
|
||||
$this->auth->settings['userModel'] = 'TestPlugin.TestPluginAuthUser';
|
||||
$this->auth->settings['fields']['username'] = 'username';
|
||||
|
||||
$request = new CakeRequest('posts/index', false);
|
||||
$request->data = array('TestPluginAuthUser' => array(
|
||||
'username' => 'gwoo',
|
||||
'password' => 'cake'
|
||||
));
|
||||
|
||||
$result = $this->auth->authenticate($request, $this->response);
|
||||
$expected = array(
|
||||
'id' => 1,
|
||||
'username' => 'gwoo',
|
||||
'created' => '2007-03-17 01:16:23'
|
||||
);
|
||||
$this->assertEquals(self::date(), $result['updated']);
|
||||
unset($result['updated']);
|
||||
$this->assertEquals($expected, $result);
|
||||
CakePlugin::unload();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue