Skip to content

Commit

Permalink
Add tests for #3624
Browse files Browse the repository at this point in the history
The username of '0' should be accepted by FormAuthenticate.

Refs #3624
  • Loading branch information
markstory committed Jun 3, 2014
1 parent 88b3629 commit d1e4dfa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/Cake/Controller/Component/Auth/FormAuthenticate.php
@@ -1,7 +1,5 @@
<?php
/**
*
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -51,7 +49,7 @@ protected function _checkFields(CakeRequest $request, $model, $fields) {
}
foreach (array($fields['username'], $fields['password']) as $field) {
$value = $request->data($model . '.' . $field);
if (empty($value) && $value !== "0" || !is_string($value)) {
if (empty($value) && $value !== '0' || !is_string($value)) {
return false;
}
}
Expand Down
@@ -1,7 +1,5 @@
<?php
/**
* FormAuthenticateTest file
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -166,6 +164,13 @@ public function testAuthenticateFieldsAreNotString() {
));
$this->assertFalse($this->auth->authenticate($request, $this->response));

$request->data = array(
'User' => array(
'user' => array(),
'password' => 'my password'
));
$this->assertFalse($this->auth->authenticate($request, $this->response));

$request->data = array(
'User' => array(
'user' => 'mariano',
Expand Down Expand Up @@ -226,6 +231,30 @@ public function testAuthenticateScopeFail() {
$this->assertFalse($this->auth->authenticate($request, $this->response));
}

/**
* Test that username of 0 works.
*
* @return void
*/
public function testAuthenticateUsernameZero() {
$User = ClassRegistry::init('User');
$User->updateAll(array('user' => $User->getDataSource()->value('0')), array('user' => 'mariano'));

$request = new CakeRequest('posts/index', false);
$request->data = array('User' => array(
'user' => '0',
'password' => 'password'
));

$expected = array(
'id' => 1,
'user' => '0',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
);
$this->assertEquals($expected, $this->auth->authenticate($request, $this->response));
}

/**
* test a model in a plugin.
*
Expand Down

0 comments on commit d1e4dfa

Please sign in to comment.