Created
July 18, 2013 03:16
-
-
Save shello/6026460 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function testSerializeAndDecryptWithStringExpires() | |
{ | |
$value = 'bar'; | |
$headers = new \Slim\Http\Headers(); | |
$settings = array( | |
'cookies.encrypt' => true, | |
'cookies.secret_key' => 'secret', | |
'cookies.cipher' => MCRYPT_RIJNDAEL_256, | |
'cookies.cipher_mode' => MCRYPT_MODE_CBC | |
); | |
$cookies = new \Slim\Http\Cookies(); | |
$cookies->set('foo', array( | |
'value' => $value, | |
'expires' => '1 hour' | |
)); | |
\Slim\Http\Util::serializeCookies($headers, $cookies, $settings); | |
$encrypted = $headers->get('Set-Cookie'); | |
$encrypted = strstr($encrypted, ';', true); | |
$encrypted = urldecode(substr(strstr($encrypted, '='), 1)); | |
$decrypted = \Slim\Http\Util::decodeSecureCookie( | |
$encrypted, | |
$settings['cookies.secret_key'], | |
$settings['cookies.cipher'], | |
$settings['cookies.cipher_mode'] | |
); | |
$this->assertEquals($value, $decrypted); | |
$this->assertTrue($value !== $encrypted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment