Пример #1
0
 public function testOnRequestBeforeSend()
 {
     $request = new Request('GET', 'https://example.com');
     $event = new Event(['request' => $request]);
     $oauth = new OAuth('example');
     $oauth->onRequestBeforeSend($event);
     $this->assertTrue($request->getQuery()->hasKey('access_token'));
     $this->assertEquals('example', $request->getQuery()->get('access_token'));
 }
Пример #2
0
 /**
  * Testing the raw signature value before it's hashed.
  *
  * Signatures should match Ooyala's {@link http://support.ooyala.com/developers/documentation/tasks/api_signing_requests.html Signing Request Algorithm}.
  */
 public function testValidRawSignature()
 {
     $method = 'GET';
     $path = '/my/path';
     $key = '123';
     $secret = '456';
     // Purposely out of order to test sorting from the Response object query params.
     $queryParams = array('fake' => 'fake,param', 'another' => '123', 'key' => $key);
     $request = new Request($method, $path);
     foreach ($queryParams as $key => $val) {
         $request->getQuery()->set($key, $val);
         unset($key, $val);
     }
     $signature = new Signature($secret, $request);
     // Build expected signature by hand to simulate what \SheKnows\OoyalaApi\Signature::getRawSignature() does.
     // @see \SheKnows\OoyalaApi\Signature for more details.
     $expected = $secret . $method . $path;
     ksort($queryParams);
     // Sort manually, kind of makes for an ugly test :/
     foreach ($queryParams as $key => $val) {
         $expected .= "{$key}={$val}";
     }
     $this->assertEquals($expected, $signature->getRawSignature(), 'Raw signature should match {secret} + {HttpMethod} + {UriPath} + {ordered_query_params}');
     $this->assertEquals(43, strlen($signature), 'Hashed signature should be 43 characters in length.');
 }
Пример #3
0
 /**
  * Functio to set GET parameters onto the
  * request
  *
  * @param array $params Key value array of get params
  */
 public function setGetParameters($params = array())
 {
     $query = $this->request->getQuery();
     foreach ($params as $key => $val) {
         $query->add($key, $val);
     }
 }
 private function addQuery(Request $request, $timestamp, $nonce)
 {
     $query = $request->getQuery();
     $query->add(self::$keys['OAuthVersionKey'], self::$oAuthVersion);
     $query->add(self::$keys['OAuthTimestampKey'], $timestamp);
     $query->add(self::$keys['OAuthNonceKey'], $nonce);
     $query->add(self::$keys['OAuthSignatureMethodKey'], 'HMAC-SHA1');
     $query->add(self::$keys['OAuthConsumerKeyKey'], self::$consumer_key);
 }
 /**
  * @covers Aws\Common\Signature\AbstractSignature::getCanonicalizedQueryString
  * @dataProvider queryStringProvider
  */
 public function testCreatesCanonicalizedQueryString($headers, $string)
 {
     // Make the method publicly callable
     $method = new \ReflectionMethod('Aws\\Common\\Signature\\AbstractSignature', 'getCanonicalizedQueryString');
     $method->setAccessible(true);
     // Create a request and replace the headers with the test headers
     $request = new Request('GET', 'http://www.example.com');
     $request->getQuery()->replace($headers);
     $this->assertEquals($string, $method->invoke($this->signature, $request));
 }
Пример #6
0
 /**
  * @covers PusherSignature::signRequest
  */
 public function testAssertEmptyParametersAreStrippedWhenSignRequest()
 {
     $request = new HttpRequest('POST', '/apps/3/events');
     // We set variables in query to have always the same result
     $request->getQuery()->replace(array('key-with-value' => 'value', 'key-without-value' => ''));
     $this->pusherSignature->signRequest($request, $this->credentials);
     $queryParameters = $request->getQuery()->toArray();
     $this->assertArrayHasKey('key-with-value', $queryParameters);
     $this->assertArrayNotHasKey('key-without-value', $queryParameters);
 }
Пример #7
0
 /**
  * @covers Guzzle\Http\Message\Request::__clone
  */
 public function testClonedRequestsUseNewInternalState()
 {
     $p = new AsyncPlugin();
     $this->request->getEventDispatcher()->addSubscriber($p);
     $h = $this->request->getHeader('Host');
     $r = clone $this->request;
     $this->assertEquals(RequestInterface::STATE_NEW, $r->getState());
     $this->assertNotSame($r->getQuery(), $this->request->getQuery());
     $this->assertNotSame($r->getCurlOptions(), $this->request->getCurlOptions());
     $this->assertNotSame($r->getEventDispatcher(), $this->request->getEventDispatcher());
     $this->assertEquals($r->getHeaders(), $this->request->getHeaders());
     $this->assertNotSame($h, $r->getHeader('Host'));
     $this->assertNotSame($r->getParams(), $this->request->getParams());
     $this->assertTrue($this->request->getEventDispatcher()->hasListeners('request.sent'));
 }
Пример #8
0
 public function fromRequest(Request $request, $secretKey)
 {
     $method = strtolower($request->getMethod());
     switch ($method) {
         case 'post':
         case 'patch':
         case 'put':
         case 'delete':
             $body = (string) $request->getBody();
             break;
         default:
             $body = $request->getQuery(true);
     }
     return $this->generate($body, $secretKey);
 }
 /**
  * @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();
 }
Пример #10
0
 /**
  * @param \Guzzle\Http\Message\Request $request
  * @param string $apiKey
  *
  * @return \BigOven\BigOvenAuthPlugin
  */
 public function addApiKey(Request $request, $apiKey)
 {
     $request->getQuery()->set('api_key', $apiKey);
     return $this;
 }
Пример #11
0
 /**
  * @param GuzzleRequest $request
  */
 private function updateQueryParams(GuzzleRequest $request)
 {
     foreach ($this->queryParams as $name => $value) {
         $request->getQuery()->add($name, $value);
     }
 }
Пример #12
0
 /**
  * Prepare the query string before the API request.
  *
  * @param \Guzzle\Http\Message\Request $request
  * @param array                        $tricks
  *
  * @return \Guzzle\Http\Message\Request
  */
 protected function prepareQuery(GuzzleRequest $request, $tricks)
 {
     $threads = $this->getThreadsArray($tricks);
     $aggregator = $this->getQueryAggregator();
     $request->getQuery()->set('forum', $this->getConfig('forum'))->set('thread', $threads)->set('api_key', $this->getConfig('publicKey'))->setAggregator($aggregator);
     return $request;
 }
Пример #13
0
 public function getQueryString()
 {
     return (string) $this->_request->getQuery();
 }
Пример #14
0
 /**
  * Allow adapter to modify request before sending,
  * adding API key by default
  *
  * @param Request $request
  */
 protected function preprocessRequest(Request $request)
 {
     $request->getQuery()->add('key', $this->getApiKey());
 }
 public function getParamsToSign(\Guzzle\Http\Message\Request $request)
 {
     return $request->getQuery()->toArray();
 }