Skip to content

Commit

Permalink
Refactoring the CookieTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Feb 27, 2017
1 parent a1f8d67 commit a4376f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Http/Cookie/CookieCryptTrait.php
Expand Up @@ -110,7 +110,7 @@ protected function _encrypt($value, $encrypt, $key = null)
$cipher = null;

if ($key === null) {
$key = $this->getCryptoKey();
$key = $this->getEncryptionKey();
}
if ($encrypt === 'rijndael') {
$cipher = Security::rijndael($value, $key, 'encrypt');
Expand Down Expand Up @@ -143,7 +143,7 @@ protected function checkCipher($encrypt)
/**
* Decrypts $value using public $type method in Security class
*
* @param array $values Values to decrypt
* @param string|array $values Values to decrypt
* @param string|bool $mode Encryption mode
* @param string|null $key Used as the security salt if specified.
* @return string|array Decrypted values
Expand Down
12 changes: 5 additions & 7 deletions tests/TestCase/Http/Cookie/CookieTest.php
Expand Up @@ -59,14 +59,12 @@ public function testValidateNameEmptyName()
*/
public function testDecrypt()
{
$encryptedCookieValue = 'Q2FrZQ==.N2Y1ODQ3ZDAzYzQzY2NkYTBlYTkwMmRkZjFmNGI3Mjk4ZWY5ZmExYTA4YmM2ZThjOWFhZWY1Njc4ZDZlMjE4Y/fhI6zv+siabYg0Cnm2j2P51Sghk7WsVxZr94g5fhmkLJ4ve7j54v9r5/vHSIHtog==';
$expected = 'Q2FrZQ==.N2Y1ODQ3ZDAzYzQzY2NkYTBlYTkwMmRkZjFmNGI3Mjk4ZWY5ZmExYTA4YmM2ZThjOWFhZWY1Njc4ZDZlMjE4Y/fhI6zv+siabYg0Cnm2j2P51Sghk7WsVxZr94g5fhmkLJ4ve7j54v9r5/vHSIHtog==';

$cookie = new Cookie('cakephp', $encryptedCookieValue);
$this->assertEquals($expected, $cookie->getValue());

$value = 'cakephp-rocks-and-is-awesome';
$cookie = new Cookie('cakephp', $value);
$cookie->encrypt($this->encryptionKey);
$this->assertTextStartsWith('Q2FrZQ==.', $cookie->getValue());
$cookie->decrypt($this->encryptionKey);
$this->assertEquals('cakephp-rocks-and-is-awesome', $cookie->getValue());
$this->assertSame($value, $cookie->getValue());
}

/**
Expand Down

0 comments on commit a4376f3

Please sign in to comment.