From d1e4dfac4713c24fbfb1deb17572f2da153caaab Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 2 Jun 2014 21:58:50 -0400 Subject: [PATCH] Add tests for #3624 The username of '0' should be accepted by FormAuthenticate. Refs #3624 --- .../Component/Auth/FormAuthenticate.php | 4 +-- .../Component/Auth/FormAuthenticateTest.php | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php index e37b4a70c..f1079b7ac 100644 --- a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php @@ -1,7 +1,5 @@ data($model . '.' . $field); - if (empty($value) && $value !== "0" || !is_string($value)) { + if (empty($value) && $value !== '0' || !is_string($value)) { return false; } } diff --git a/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php b/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php index 90f5797c9..a8a17b2b8 100644 --- a/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php +++ b/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php @@ -1,7 +1,5 @@ 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', @@ -226,6 +231,30 @@ class FormAuthenticateTest extends CakeTestCase { $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. *