Example #1
0
 /**
  * @covers Guzzle\Http\Message\Request
  */
 public function testHoldsCookies()
 {
     $this->assertNull($this->request->getCookie('test'));
     // Set a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     // Multiple cookies by setting the Cookie header
     $this->request->setHeader('Cookie', '__utma=1.638370270.1344367610.1374365610.1944450276.2; __utmz=1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); hl=de; PHPSESSID=ak93pqashi5uubuoq8fjv60897');
     $this->assertEquals('1.638370270.1344367610.1374365610.1944450276.2', $this->request->getCookie('__utma'));
     $this->assertEquals('1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', $this->request->getCookie('__utmz'));
     $this->assertEquals('de', $this->request->getCookie('hl'));
     $this->assertEquals('ak93pqashi5uubuoq8fjv60897', $this->request->getCookie('PHPSESSID'));
     // Unset the cookies by setting the Cookie header to null
     $this->request->setHeader('Cookie', null);
     $this->assertNull($this->request->getCookie('test'));
     $this->request->removeHeader('Cookie');
     // Set and remove a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     $this->assertSame($this->request, $this->request->removeCookie('test'));
     $this->assertNull($this->request->getCookie('test'));
     // Remove the cookie header
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->request->removeHeader('Cookie');
     $this->assertEquals('', (string) $this->request->getHeader('Cookie'));
     // Remove a cookie value
     $this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
     $this->request->removeCookie('foo');
     $this->assertEquals(array('baz' => 'boo'), $this->request->getCookies());
     $this->request->addCookie('foo', 'bar');
     $this->assertEquals('baz=boo; foo=bar', (string) $this->request->getHeader('Cookie'));
 }
 private function fireRequest(GuzzleRequest $request, $cookie)
 {
     try {
         $response = $request->addCookie('authenticator', $cookie)->send();
         return $response->json();
     } catch (\Guzzle\Http\Exception\BadResponseException $client_error) {
         return $this->app->abort($client_error->getResponse()->getStatusCode(), $client_error->getResponse()->getReasonPhrase());
     }
 }
Example #3
0
 private function setRequestCookies(\Guzzle\Http\Message\Request $request)
 {
     if (!is_null($request->getCookies())) {
         foreach ($request->getCookies() as $name => $value) {
             $request->removeCookie($name);
         }
     }
     $cookieUrlMatcher = new \webignition\Cookie\UrlMatcher\UrlMatcher();
     foreach ($this->getConfiguration()->getCookies() as $cookie) {
         if ($cookieUrlMatcher->isMatch($cookie, $request->getUrl())) {
             $request->addCookie($cookie['name'], $cookie['value']);
         }
     }
 }
 /**
  * @param \Guzzle\Http\Message\Request $request
  */
 public function signRequest(Request $request)
 {
     $url = $request->getPath();
     if ('POST' == $request->getMethod() && $request instanceof EntityEnclosingRequest) {
         $body = (string) $request->getBody();
         $hash = $this->signature->generate($body);
     } else {
         $url .= '?' . $request->getQuery();
         $hash = $this->signature->generate($url);
     }
     $request->addCookie('acquia_solr_time', $this->signature->getRequestTime());
     $request->addCookie('acquia_solr_nonce', $this->signature->getNonce());
     $request->addCookie('acquia_solr_hmac', $hash . ';');
     // The timestamp should be current for each request.
     $this->signature->unsetRequestTime();
 }
Example #5
0
 /**
  * @covers Guzzle\Http\Message\Request
  */
 public function testHoldsCookies()
 {
     $this->assertNull($this->request->getCookie('test'));
     // Set a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     // Unset the cookies by setting the Cookie header to null
     $this->request->setHeader('Cookie', null);
     $this->assertNull($this->request->getCookie('test'));
     // Set and remove a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     $this->assertSame($this->request, $this->request->removeCookie('test'));
     $this->assertNull($this->request->getCookie('test'));
     // Remove the cookie header
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->request->removeHeader('Cookie');
     $this->assertEquals('', (string) $this->request->getHeader('Cookie'));
     // Remove a cookie value
     $this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
     $this->request->removeCookie('foo');
     $this->assertEquals(array('baz' => 'boo'), $this->request->getCookies());
 }
Example #6
0
 /**
  * @covers Guzzle\Http\Message\Request
  */
 public function testHoldsCookies()
 {
     $cookie = $this->request->getCookie();
     $this->assertInstanceOf('Guzzle\\Http\\Cookie', $this->request->getCookie());
     // Ensure that the cookie will not affect the request
     $this->assertNull($this->request->getCookie('test'));
     $cookie->set('test', 'abc');
     $this->assertNull($this->request->getCookie('test'));
     // Set a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     // Unset the cookies by setting the Cookie header to null
     $this->request->setHeader('Cookie', null);
     $this->assertNull($this->request->getCookie('test'));
     // Set and remove a cookie
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->assertEquals('abc', $this->request->getCookie('test'));
     $this->assertSame($this->request, $this->request->removeCookie('test'));
     $this->assertNull($this->request->getCookie('test'));
     // Remove the cookie header
     $this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
     $this->request->removeHeader('Cookie');
     $this->assertEquals('', (string) $this->request->getCookie());
     // Set the cookie using a cookie object
     $this->assertSame($this->request, $this->request->setCookie($cookie));
     $this->assertEquals($cookie->getAll(), $this->request->getCookie()->getAll());
     // Set the cookie using an array
     $this->assertSame($this->request, $this->request->setCookie(array('test' => 'def')));
     $this->assertEquals(array('test' => 'def'), $this->request->getCookie()->getAll());
     // Test using an invalid value
     try {
         $this->request->setCookie('a');
         $this->fail('Did not throw expected exception when passing invalid value');
     } catch (\InvalidArgumentException $e) {
     }
 }
 public static function requestWithJsonResponse(GuzzleRequest $request, Application $app, $cookie)
 {
     try {
         $response = $request->addCookie("authenticator", $cookie)->send();
         $headers = $response->getHeaders()->toArray();
         return $app->json(json_decode($response->getBody()), 200, $headers);
     } catch (\Guzzle\Http\Exception\BadResponseException $client_error) {
         return $app->abort($client_error->getResponse()->getStatusCode(), $client_error->getResponse()->getReasonPhrase());
     }
 }