diff --git a/lib/Cake/Test/Case/Utility/SecurityTest.php b/lib/Cake/Test/Case/Utility/SecurityTest.php index 3fe83b27c..d0f6a11af 100644 --- a/lib/Cake/Test/Case/Utility/SecurityTest.php +++ b/lib/Cake/Test/Case/Utility/SecurityTest.php @@ -375,16 +375,27 @@ class SecurityTest extends CakeTestCase { } /** - * Test that empty data cause errors + * Test encrypting falsey data * - * @expectedException CakeException - * @expectedExceptionMessage The data to encrypt cannot be empty. * @return void */ - public function testEncryptInvalidData() { - $txt = ''; + public function testEncryptDecryptFalseyData() { $key = 'This is a key that is long enough to be ok.'; - Security::encrypt($txt, $key); + + $result = Security::encrypt('', $key); + $this->assertSame('', Security::decrypt($result, $key)); + + $result = Security::encrypt(false, $key); + $this->assertSame('', Security::decrypt($result, $key)); + + $result = Security::encrypt(null, $key); + $this->assertSame('', Security::decrypt($result, $key)); + + $result = Security::encrypt(0, $key); + $this->assertSame('0', Security::decrypt($result, $key)); + + $result = Security::encrypt('0', $key); + $this->assertSame('0', Security::decrypt($result, $key)); } /** diff --git a/lib/Cake/Utility/Security.php b/lib/Cake/Utility/Security.php index 30b5e111a..2a1bd2c56 100644 --- a/lib/Cake/Utility/Security.php +++ b/lib/Cake/Utility/Security.php @@ -303,9 +303,7 @@ class Security { */ public static function encrypt($plain, $key, $hmacSalt = null) { self::_checkKey($key, 'encrypt()'); - if (empty($plain)) { - throw new CakeException(__d('cake_dev', 'The data to encrypt cannot be empty.')); - } + if ($hmacSalt === null) { $hmacSalt = Configure::read('Security.salt'); }