Exemplo n.º 1
0
 public function testEncryptDecrypt()
 {
     $key = 'foobar';
     $data = 'very secret';
     $iv = Crypt::getiv();
     $encrypted = Crypt::encrypt($data, $key, $iv);
     $this->assertNotEquals($data, $encrypted);
     $decrypted = Crypt::decrypt($encrypted, $key, $iv);
     $this->assertEquals($data, $decrypted);
 }
Exemplo n.º 2
0
 public function testStorageCookie()
 {
     Conf::set('session_storage', '\\photon\\session\\storage\\Cookies');
     Conf::set('secret_key', 'dummy');
     // used to crypt/sign the cookies
     $req = \photon\test\HTTP::baseRequest();
     $mid = new \photon\session\Middleware();
     $this->assertEquals(false, $mid->process_request($req));
     $this->assertEquals(false, isset($req->session['foo']));
     $req->session['foo'] = 'bar';
     $this->assertEquals(true, isset($req->session['foo']));
     $this->assertEquals('bar', $req->session['foo']);
     unset($req->session['foo']);
     $this->assertEquals(null, $req->session['foo']);
     $this->assertEquals(false, isset($req->session['foo']));
     $req->session['foo'] = 'bar';
     unset($req->session['todelete']);
     $res = new \photon\http\Response('Hello!');
     $mid->process_response($req, $res);
     $this->assertEquals(true, isset($res->headers['Vary']));
     $this->assertEquals(true, isset($res->COOKIE['sid']));
     $this->assertEquals(true, isset($res->COOKIE['scs-foo']));
     $this->assertEquals(true, isset($res->COOKIE['scs-todelete']));
     $iv = $res->COOKIE['scsiv'];
     // Now we generate a new request with an iv to test the retrieval
     $req = \photon\test\HTTP::baseRequest();
     $req->COOKIE['scsiv'] = $iv;
     $req->COOKIE['scs-foo'] = \photon\crypto\Crypt::encrypt('bar', Conf::f('secret_key'), $iv);
     $this->assertEquals(false, $mid->process_request($req));
     $this->assertEquals('bar', $req->session['foo']);
 }
Exemplo n.º 3
0
 /**
  * Get a value from the storage.
  *
  * @required public function get($offset)
  */
 public function get($offset)
 {
     if (isset($this->deleted[$offset])) {
         return null;
     }
     if (isset($this->cache[$offset])) {
         return $this->cache[$offset];
     }
     if (strlen($this->iv) && isset($this->cookie['scs-' . $offset])) {
         return Crypt::decrypt($this->cookie['scs-' . $offset], Conf::f('secret_key'), $this->iv);
     }
     return null;
 }