public function doCreate()
 {
     $req = $this->newRequest('GET', new \peer\URL('http://localhost/'));
     $res = new \scriptlet\HttpScriptletResponse();
     $s = newinstance('scriptlet.xml.XMLScriptlet', array(), '{
   public function needsSession($request) { return TRUE; }
 }');
     $s->service($req, $res);
     $this->assertEquals(\peer\http\HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new \peer\URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals(sprintf('/xml/psessionid=%s/static', session_id()), $redirect->getPath());
     $this->assertEquals(array(), $redirect->getParams(), $redirect->getURL());
 }
예제 #2
0
 /**
  * Navigate to a given URL
  *
  * @param   string target
  * @param   string params
  * @param   string method
  * @throws  unittest.AssertionFailedError  
  */
 public function navigateTo($target, $params = null, $method = HttpConstants::GET)
 {
     if (strstr($target, '://')) {
         $url = new \peer\URL($target);
         $this->conn = $this->getConnection(sprintf('%s://%s%s/', $url->getScheme(), $url->getHost(), -1 === $url->getPort(-1) ? '' : ':' . $url->getPort()));
         $params ? $url->setParams($params) : '';
         $this->beginAt($url->getPath(), $url->getParams(), $method);
     } else {
         if ('' !== $target && '/' === $target[0]) {
             $this->beginAt($target, $params, $method);
         } else {
             $base = $this->getBase();
             $this->beginAt(substr($base, 0, strrpos($base, '/')) . '/' . $target, $params, $method);
         }
     }
 }
 public function handleSessionInitializationError()
 {
     $req = $this->newRequest('GET', new \peer\URL('http://localhost/?psessionid=MALFORMED'));
     $res = new \scriptlet\HttpScriptletResponse();
     $s = newinstance('scriptlet.HttpScriptlet', array(), '{
   public function needsSession($request) { return TRUE; }
   public function handleSessionInitialization($request) {
     if (!preg_match("/^a-f0-9$/", $request->getSessionId())) { 
       throw new IllegalArgumentException("Invalid characters in session id");
     }
     parent::handleSessionInitialization($request);
   }
   public function handleSessionInitializationError($request, $response) {
     $request->getURL()->addParam("relogin", 1);
     return $request->session->initialize(NULL);
   } 
 }');
     $s->service($req, $res);
     $this->assertEquals(\peer\http\HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new \peer\URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals('/', $redirect->getPath());
     $this->assertEquals(session_id(), $redirect->getParam('psessionid'));
     $this->assertEquals('1', $redirect->getParam('relogin'));
 }