Permalink
Browse files

Don't throw exception when trying to encrypt falsey value.

  • Loading branch information...
ADmad committed Dec 15, 2013
1 parent bf96ea3 commit 8a666fb37e339627af2f9da492183619bcd8cff3
Showing with 18 additions and 9 deletions.
  1. +17 −6 lib/Cake/Test/Case/Utility/SecurityTest.php
  2. +1 −3 lib/Cake/Utility/Security.php
@@ -375,16 +375,27 @@ public function testEncryptInvalidKey() {
}
/**
- * 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));
}
/**
@@ -303,9 +303,7 @@ protected static function _crypt($password, $salt = false) {
*/
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');
}

0 comments on commit 8a666fb

Please sign in to comment.