Added check in AuthComponent::hashPasswords() to ensure that data is an array. Tests Added.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7492 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-08-24 15:18:37 +00:00
parent ce8dccc1fc
commit 9895f6d39b
2 changed files with 37 additions and 1 deletions

View file

@ -793,7 +793,7 @@ class AuthComponent extends Object {
return $this->authenticate->hashPasswords($data);
}
if (isset($data[$this->userModel])) {
if (is_array($data) && isset($data[$this->userModel])) {
if (isset($data[$this->userModel][$this->fields['username']]) && isset($data[$this->userModel][$this->fields['password']])) {
$data[$this->userModel][$this->fields['password']] = $this->password($data[$this->userModel][$this->fields['password']]);
}

View file

@ -28,6 +28,8 @@
*/
App::import(array('controller' . DS . 'components' . DS .'auth', 'controller' . DS . 'components' . DS .'acl'));
App::import(array('controller'.DS.'components'.DS.'acl', 'model'.DS.'db_acl'));
App::import('Core', 'Xml');
Configure::write('Security.salt', 'JfIxfs2guVoUubWDYhG93b0qyJfIxfs2guwvniR2G0FgaC9mi');
/**
* Short description for class.
@ -765,6 +767,40 @@ class AuthTest extends CakeTestCase {
$this->Controller->Auth->startup($this->Controller);
$this->assertTrue(is_null($this->Controller->Auth->user()));
}
/**
* test Hashing of passwords
*
* @return void
**/
function testHashPasswords() {
$this->Controller->Auth->userModel = 'AuthUser';
$data['AuthUser']['password'] = 'superSecret';
$data['AuthUser']['username'] = 'superman@dailyplanet.com';
$return = $this->Controller->Auth->hashPasswords($data);
$expected = $data;
$expected['AuthUser']['password'] = Security::hash($expected['AuthUser']['password'], null, true);
$this->assertEqual($return, $expected);
$data['Wrong']['password'] = 'superSecret';
$data['Wrong']['username'] = 'superman@dailyplanet.com';
$data['AuthUser']['password'] = 'IcantTellYou';
$return = $this->Controller->Auth->hashPasswords($data);
$expected = $data;
$expected['AuthUser']['password'] = Security::hash($expected['AuthUser']['password'], null, true);
$this->assertEqual($return, $expected);
$xml = array(
'User' => array(
'username' => 'batman@batcave.com',
'password' => 'bruceWayne',
)
);
$data = new Xml($xml);
$return = $this->Controller->Auth->hashPasswords($data);
$expected = $data;
$this->assertEqual($return, $expected);
}
/**
* testCustomRoute method
*