Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'component-settings' into 1.3-misc

  • Loading branch information...
commit 0bc1126114b3c751dc442f807562ab4bcaf77276 2 parents 8960a01 + ff74a59
@markstory markstory authored
View
3  cake/libs/controller/components/auth.php
@@ -253,7 +253,7 @@ class AuthComponent extends Object {
* @return void
* @access public
*/
- function initialize(&$controller) {
+ function initialize(&$controller, $settings) {
$this->params = $controller->params;
$crud = array('create', 'read', 'update', 'delete');
$this->actionMap = array_merge($this->actionMap, array_combine($crud, $crud));
@@ -275,6 +275,7 @@ function initialize(&$controller) {
));
}
}
+ $this->_set($settings);
if (Configure::read() > 0) {
App::import('Debugger');
Debugger::checkSessionKey();
View
4 cake/libs/controller/components/request_handler.php
@@ -165,14 +165,16 @@ function __construct() {
* as the first item.
*
* @param object $controller A reference to the controller
+ * @param array $settings Array of settings to _set().
* @return void
* @see Router::parseExtensions()
* @access public
*/
- function initialize(&$controller) {
+ function initialize(&$controller, $settings = array()) {
if (isset($controller->params['url']['ext'])) {
$this->ext = $controller->params['url']['ext'];
}
+ $this->_set($settings);
}
/**
View
15 cake/libs/controller/components/security.php
@@ -169,9 +169,22 @@ class SecurityComponent extends Object {
var $_action = null;
/**
+ * Initialize the SecurityComponent
+ *
+ * @param object $controller Controller instance for the request
+ * @param array $settings Settings to set to the component
+ * @return void
+ * @access public
+ */
+ function initialize(&$controller, $settings = array()) {
+ $this->_set($settings);
+ }
+
+/**
* Component startup. All security checking happens here.
*
* @param object $controller Instantiating controller
+ * @return void
* @access public
*/
function startup(&$controller) {
@@ -342,7 +355,7 @@ function loginRequest($options = array()) {
if (strtolower($options['type']) == 'digest') {
$out[] = 'qop="auth"';
$out[] = 'nonce="' . uniqid("") . '"';
- $out[] = 'opaque="' . md5($options['realm']).'"';
+ $out[] = 'opaque="' . md5($options['realm']) . '"';
}
return $auth . ' ' . implode(',', $out);
View
55 cake/tests/cases/libs/controller/components/auth.test.php
@@ -1501,6 +1501,61 @@ function testInitializeAndRoutingPrefixes() {
}
/**
+ * test $settings in Controller::$components
+ *
+ * @access public
+ * @return void
+ */
+ function testComponentSettings() {
+ $this->Controller =& new AuthTestController();
+ $this->Controller->components = array(
+ 'Auth' => array(
+ 'fields' => array('username' => 'email', 'password' => 'password'),
+ 'loginAction' => array('controller' => 'people', 'action' => 'login'),
+ 'userModel' => 'AuthUserCustomField',
+ 'sessionKey' => 'AltAuth'
+ )
+ );
+ $this->Controller->Component->init($this->Controller);
+ $this->Controller->Component->initialize($this->Controller);
+ Router::reload();
+
+ $this->AuthUserCustomField =& new AuthUserCustomField();
+ $user = array(
+ 'id' => 1, 'email' => 'harking@example.com',
+ 'password' => Security::hash(Configure::read('Security.salt') . 'cake'
+ ));
+ $user = $this->AuthUserCustomField->save($user, false);
+
+ Router::connect('/', array('controller' => 'people', 'action' => 'login'));
+ $url = '/';
+ $this->Controller->params = Router::parse($url);
+ Router::setRequestInfo(array($this->Controller->passedArgs, array(
+ 'base' => null, 'here' => $url, 'webroot' => '/', 'passedArgs' => array(),
+ 'argSeparator' => ':', 'namedArgs' => array()
+ )));
+ $this->Controller->data['AuthUserCustomField'] = array('email' => 'harking@example.com', 'password' => 'cake');
+ $this->Controller->params['url']['url'] = substr($url, 1);
+ $this->Controller->Auth->startup($this->Controller);
+
+ $user = $this->Controller->Auth->user();
+ $this->assertTrue(!!$user);
+
+ $expected = array(
+ 'fields' => array('username' => 'email', 'password' => 'password'),
+ 'loginAction' => array('controller' => 'people', 'action' => 'login'),
+ 'logoutRedirect' => array('controller' => 'people', 'action' => 'login'),
+ 'userModel' => 'AuthUserCustomField',
+ 'sessionKey' => 'AltAuth.AuthUserCustomField'
+ );
+ $this->assertEqual($expected['fields'], $this->Controller->Auth->fields);
+ $this->assertEqual($expected['loginAction'], $this->Controller->Auth->loginAction);
+ $this->assertEqual($expected['logoutRedirect'], $this->Controller->Auth->logoutRedirect);
+ $this->assertEqual($expected['userModel'], $this->Controller->Auth->userModel);
+ $this->assertEqual($expected['sessionKey'], $this->Controller->Auth->sessionKey);
+ }
+
+/**
* test that logout deletes the session variables. and returns the correct url
*
* @return void
View
15 cake/tests/cases/libs/controller/components/cookie.test.php
@@ -94,6 +94,21 @@ function end() {
}
/**
+ * test that initialize sets settings from components array
+ *
+ * @return void
+ */
+ function testInitialize() {
+ $settings = array(
+ 'time' => '5 days',
+ 'path' => '/'
+ );
+ $this->Controller->Cookie->initialize($this->Controller, $settings);
+ $this->assertEqual($this->Controller->Cookie->time, $settings['time']);
+ $this->assertEqual($this->Controller->Cookie->path, $settings['path']);
+ }
+
+/**
* testCookieName
*
* @access public
View
6 cake/tests/cases/libs/controller/components/request_handler.test.php
@@ -186,6 +186,12 @@ function testInitializeCallback() {
$this->Controller->params['url']['ext'] = 'rss';
$this->RequestHandler->initialize($this->Controller);
$this->assertEqual($this->RequestHandler->ext, 'rss');
+
+ $settings = array(
+ 'ajaxLayout' => 'test_ajax'
+ );
+ $this->RequestHandler->initialize($this->Controller, $settings);
+ $this->assertEqual($this->RequestHandler->ajaxLayout, 'test_ajax');
}
/**
View
29 cake/tests/cases/libs/controller/components/security.test.php
@@ -143,7 +143,7 @@ class SecurityComponentTest extends CakeTestCase {
* @access public
* @return void
*/
- function setUp() {
+ function startTest() {
$this->Controller =& new SecurityTestController();
$this->Controller->Component->init($this->Controller);
$this->Controller->Security =& $this->Controller->TestSecurity;
@@ -158,7 +158,7 @@ function setUp() {
* @access public
* @return void
*/
- function tearDown() {
+ function endTest() {
Configure::write('Security.salt', $this->oldSalt);
$this->Controller->Session->delete('_Token');
unset($this->Controller->Security);
@@ -167,6 +167,31 @@ function tearDown() {
}
/**
+ * test that initalize can set properties.
+ *
+ * @return void
+ */
+ function testInitialize() {
+ $settings = array(
+ 'requirePost' => array('edit', 'update'),
+ 'requireSecure' => array('update_account'),
+ 'requireGet' => array('index'),
+ 'validatePost' => false,
+ 'loginUsers' => array(
+ 'mark' => 'password'
+ ),
+ 'requireLogin' => array('login'),
+ );
+ $this->Controller->Security->initialize($this->Controller, $settings);
+ $this->assertEqual($this->Controller->Security->requirePost, $settings['requirePost']);
+ $this->assertEqual($this->Controller->Security->requireSecure, $settings['requireSecure']);
+ $this->assertEqual($this->Controller->Security->requireGet, $settings['requireGet']);
+ $this->assertEqual($this->Controller->Security->validatePost, $settings['validatePost']);
+ $this->assertEqual($this->Controller->Security->loginUsers, $settings['loginUsers']);
+ $this->assertEqual($this->Controller->Security->requireLogin, $settings['requireLogin']);
+ }
+
+/**
* testStartup method
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.