コード例 #1
0
ファイル: CookiesTest.php プロジェクト: Piggelinus/WP
 public function testSetWithArrayValue()
 {
     $now = time();
     $c = new \Slim\Http\Cookies();
     $c->set('foo', array('value' => 'bar', 'expires' => $now + 86400, 'domain' => '.example.com', 'path' => '/', 'secure' => true, 'httponly' => true));
     $this->assertAttributeEquals(array('foo' => array('value' => 'bar', 'expires' => $now + 86400, 'domain' => '.example.com', 'path' => '/', 'secure' => true, 'httponly' => true)), 'data', $c);
 }
コード例 #2
0
 /**
  * Test serializeCookies and decrypt with string expires
  *
  * In this test a cookie with a string typed value for 'expires' is set,
  * which should be parsed by `strtotime` to a timestamp when it's added to
  * the headers; this timestamp should then be correctly parsed, and the
  * value correctly decrypted, by `decodeSecureCookie`.
  */
 public function testSerializeCookiesAndDecryptWithStringExpires()
 {
     $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);
 }