Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.5' into 3.0
Browse files Browse the repository at this point in the history
Conflicts:
	Cake/Test/TestCase/Utility/SecurityTest.php
	Cake/Utility/Security.php
  • Loading branch information
lorenzo committed Dec 17, 2013
2 parents 0cf9bfd + b5d7628 commit 509c856
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cake/Controller/Component/CookieComponent.php
Expand Up @@ -488,7 +488,7 @@ protected function _encrypt($value) {
if (is_array($value)) {
$value = $this->_implode($value);
}
if (!$this->_encrypted || !$value) {
if (!$this->_encrypted) {
return $value;
}
$prefix = "Q2FrZQ==.";
Expand Down
10 changes: 7 additions & 3 deletions Cake/Test/TestCase/Controller/Component/CookieComponentTest.php
Expand Up @@ -175,11 +175,11 @@ public function testWriteSimple() {
}

/**
* test write() Encrypted data with null & empty string & boolean value
* test write() encrypted data with falsey value
*
* @return void
*/
public function testWriteWithNullEmptyString() {
public function testWriteWithFalseyValue() {
$this->Cookie->type('aes');
$this->Cookie->key = 'qSI232qs*&sXOw!adre@34SAv!@*(XSL#$%)asGb$@11~_+!@#HKis~#^';

Expand All @@ -201,7 +201,11 @@ public function testWriteWithNullEmptyString() {

$this->Cookie->write('Testing', '0');
$result = $this->Cookie->read('Testing');
$this->assertEquals('0', $result);
$this->assertSame('0', $result);

$this->Cookie->write('Testing', 0);
$result = $this->Cookie->read('Testing');
$this->assertSame(0, $result);
}

/**
Expand Down
23 changes: 17 additions & 6 deletions Cake/Test/TestCase/Utility/SecurityTest.php
Expand Up @@ -294,16 +294,27 @@ public function testEncryptInvalidKey() {
}

/**
* Test that empty data cause errors
* Test encrypting falsey data
*
* @expectedException Cake\Error\Exception
* @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));
}

/**
Expand Down
4 changes: 1 addition & 3 deletions Cake/Utility/Security.php
Expand Up @@ -238,9 +238,7 @@ protected static function _crypt($password, $salt = false) {
*/
public static function encrypt($plain, $key, $hmacSalt = null) {
self::_checkKey($key, 'encrypt()');
if (strlen($plain) === 0) {
throw new Error\Exception(__d('cake_dev', 'The data to encrypt cannot be empty.'));
}

if ($hmacSalt === null) {
$hmacSalt = Configure::read('Security.salt');
}
Expand Down

0 comments on commit 509c856

Please sign in to comment.