/**
  * @covers Guzzle\Aws\S3\SignS3RequestPlugin
  */
 public function testAddsAuthorizationHeaders()
 {
     $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
     $client = S3Client::factory(array('base_url' => $this->getServer()->getUrl(), 'access_key' => 'a', 'secret_key' => 's'));
     $request = $client->createRequest();
     $request->send();
     $this->assertTrue($request->hasHeader('Authorization') !== false);
     $this->assertContains('AWS a:', $request->getHeader('Authorization'));
 }
Exemplo n.º 2
0
 /**
  * @covers Guzzle\Aws\S3\DevPayPlugin
  */
 public function testAddsDevPayTokens()
 {
     $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
     $client = S3Client::factory(array('base_url' => $this->getServer()->getUrl(), 'access_key' => 'a', 'secret_key' => 's', 'devpay_user_token' => 'user', 'devpay_product_token' => 'product'));
     $request = $client->createRequest('GET');
     $request->send();
     $this->assertTrue($request->hasHeader('x-amz-security-token') !== false);
     $this->assertEquals('user, product', $request->getHeader('x-amz-security-token'));
 }
Exemplo n.º 3
0
 /**
  * @covers Guzzle\Aws\S3\S3Client::getEndpoints
  */
 public function testReturnsEndpoints()
 {
     $this->assertEquals(array('us-east-1' => 's3.amazonaws.com', 'us-west-1' => 's3-us-west-1.amazonaws.com', 'EU' => 's3-eu-west-1.amazonaws.com', 'ap-southeast-1' => 's3-ap-southeast-1.amazonaws.com', 'ap-northeast-1' => 's3-ap-northeast-1.amazonaws.com'), S3Client::getEndpoints());
 }
Exemplo n.º 4
0
 /**
  * Create a canonicalized Resource string for a signature.
  *
  * @param array $headers Associative array of request headers.
  * @param string $path Path part of the URL.
  *
  * @return string Returns a canonicalized resource string.
  */
 public function createCanonicalizedResource(array $headers, $path)
 {
     $subResource = '';
     $parts = parse_url($path);
     $path = $parts['path'];
     $needsEndingSlash = false;
     if (!empty($headers)) {
         $headers = array_change_key_case($headers, CASE_LOWER);
         if ($headers['host']) {
             $matches = array();
             $usesS3 = preg_match('/^([a-zA-Z0-9_\\-\\.]+)\\.(?:' . implode('|', array_map('preg_quote', S3Client::getEndpoints())) . ').*$/', $headers['host'], $matches);
             // If this is a CNAME, then just use the Host header
             $host = $usesS3 ? $matches[1] : str_replace(S3Client::getEndpoints(), '', $headers['host']);
             if ($host) {
                 if (preg_match('/^[A-Za-z0-9._\\-]+$/', $host)) {
                     $bucket = $host . '/';
                     if ($path && $path[0] == '/') {
                         $path = substr($path, 1);
                     }
                 } else {
                     $bucket = parse_url($host, PHP_URL_HOST);
                 }
                 $path = '/' . $bucket . $path;
             }
         }
     }
     // Add an ending slash to the bucket if it was omitted
     if (preg_match('/^\\/[A-Za-z0-9._\\-]+$/', $path)) {
         $path .= '/';
     }
     // Add the sub resource if a valid sub resource is present
     if (array_key_exists('query', $parts)) {
         $q = array();
         parse_str($parts['query'], $q);
         $subs = array();
         foreach ($q as $key => $value) {
             if (in_array($key, $this->subResources)) {
                 $subs[$key] = $value;
             }
         }
         if (count($subs)) {
             $subResource .= '?';
             ksort($subs);
             $first = true;
             foreach ($subs as $key => $value) {
                 if (!$first) {
                     $subResource .= '&';
                 }
                 $subResource .= $key;
                 if ($value) {
                     $subResource .= '=' . $value;
                 }
                 $first = false;
             }
             $needsEndingSlash = false;
         }
     }
     $result = ($path ? $path : '/') . $subResource;
     // @codeCoverageIgnoreStart
     if ($needsEndingSlash) {
         $result .= '/';
     }
     // @codeCoverageIgnoreEnd
     return $result;
 }