public function testCanCompleteMultipartUpload()
 {
     $this->prepareTransfer();
     $model = $this->getMockBuilder('Guzzle\\Service\\Resource\\Model')->disableOriginalConstructor()->getMock();
     $command = $this->getMockBuilder('Guzzle\\Service\\Command\\OperationCommand')->disableOriginalConstructor()->getMock();
     $command->expects($this->any())->method('getResult')->will($this->returnValue($model));
     $this->client->expects($this->any())->method('getCommand')->will($this->returnValue($command));
     $this->assertInstanceOf('Guzzle\\Service\\Resource\\Model', $this->callProtectedMethod($this->transfer, 'complete'));
 }
Пример #2
0
 /**
  * Create a presigned URL with a command object that has x-amz-* headers.
  *
  * @depends testGetObjectWithSaveAs
  */
 public function testCreatePresignedUrlWithAcl()
 {
     $this->client->waitUntil('BucketExists', array('Bucket' => $this->bucket));
     $client = $this->client;
     $bucket = $this->bucket;
     $command = $client->getCommand('PutObject', array('Bucket' => $bucket, 'Key' => 'preput', 'ACL' => 'public-read', 'Content-Type' => 'plain/text', 'Body' => ''));
     $signedUrl = $command->createPresignedUrl('+10 minutes');
     $ch = curl_init($signedUrl);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: plain/text'));
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
     curl_setopt($ch, CURLOPT_POSTFIELDS, 'abc123');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_exec($ch);
 }
Пример #3
0
 /**
  * @depends testPutAndListObjects
  */
 public function testPreSignedUrlAllowsSpecialCharacters()
 {
     self::log('Uploading an object with a space in the key');
     $this->client->waitUntil('bucket_exists', array('Bucket' => $this->bucket));
     $key = 'foo baz bar!';
     $this->client->putObject(array('Bucket' => $this->bucket, 'Key' => $key, 'Body' => 'hi'));
     $this->client->waitUntil('object_exists', array('Bucket' => $this->bucket, 'Key' => $key));
     self::log('Creating an downloading using a pre-signed URL with command');
     $command = $this->client->getCommand('GetObject', array('Bucket' => $this->bucket, 'Key' => $key));
     $url = $command->createPresignedUrl('+100 minutes');
     self::log($url);
     $this->assertEquals('hi', file_get_contents($url));
     self::log('Creating an downloading using a pre-signed URL');
     $extra = urlencode("attachment; filename=\"{$key}\"");
     $request = $this->client->get("{$this->bucket}/{$key}?response-content-disposition={$extra}");
     $url = $this->client->createPresignedUrl($request, '+10 minutes');
     self::log($url);
     $client = new Client();
     $this->assertEquals('hi', file_get_contents($url));
     $this->assertEquals('hi', $client->get($url)->send()->getBody(true));
 }
 /**
  * Changes how buckets are referenced in the HTTP request
  *
  * @param Event $event Event emitted
  */
 public function onCommandAfterPrepare(Event $event)
 {
     $command = $event['command'];
     $bucket = $command['Bucket'];
     $request = $command->getRequest();
     $pathStyle = true;
     // Skip operations that do not need the bucket moved to the host.
     if (isset(self::$exclusions[$command->getName()])) {
         return;
     }
     if ($key = $command['Key']) {
         // Modify the command Key to account for the {/Key*} explosion into an array
         if (is_array($key)) {
             $command['Key'] = $key = implode('/', $key);
         }
     }
     // Set the key and bucket on the request
     $request->getParams()->set('bucket', $bucket)->set('key', $key);
     // Switch to virtual if PathStyle is disabled, or not a DNS compatible bucket name, or the scheme is
     // http, or the scheme is https and there are no dots in the host header (avoids SSL issues)
     if (!$pathStyle && !$command['PathStyle'] && $command->getClient()->isValidBucketName($bucket) && !($command->getRequest()->getScheme() == 'https' && strpos($bucket, '.'))) {
         // Switch to virtual hosted bucket
         $request->setHost($bucket . '.' . $request->getHost());
         $request->setPath(preg_replace("#^/{$bucket}#", '', $request->getPath()));
     } else {
         $pathStyle = true;
     }
     if (!$bucket) {
         $request->getParams()->set('s3.resource', '/');
     } elseif ($pathStyle) {
         // Path style does not need a trailing slash
         $request->getParams()->set('s3.resource', '/' . rawurlencode($bucket) . ($key ? '/' . S3Client::encodeKey($key) : ''));
     } else {
         // Bucket style needs a trailing slash
         $request->getParams()->set('s3.resource', '/' . rawurlencode($bucket) . ($key ? '/' . S3Client::encodeKey($key) : '/'));
     }
 }
Пример #5
0
 /**
  * Create a canonicalized resource for a request
  *
  * @param RequestInterface $request Request for the resource
  *
  * @return string
  */
 private function createCanonicalizedResource(RequestInterface $request)
 {
     $buffer = $request->getParams()->get('s3.resource');
     // When sending a raw HTTP request (e.g. $client->get())
     if (null === $buffer) {
         $bucket = $request->getParams()->get('bucket') ?: $this->parseBucketName($request);
         // Use any specified bucket name, the parsed bucket name, or no bucket name when interacting with GetService
         $buffer = $bucket ? "/{$bucket}" : '';
         // Remove encoding from the path and use the S3 specific encoding
         $path = S3Client::encodeKey(rawurldecode($request->getPath()));
         // if the bucket was path style, then ensure that the bucket wasn't duplicated in the resource
         $buffer .= preg_replace("#^/{$bucket}/{$bucket}#", "/{$bucket}", $path);
     }
     // Remove double slashes
     $buffer = str_replace('//', '/', $buffer);
     // Add sub resource parameters
     $query = $request->getQuery();
     $first = true;
     foreach ($this->signableQueryString as $key) {
         if ($query->hasKey($key)) {
             $value = $query[$key];
             $buffer .= $first ? '?' : '&';
             $first = false;
             $buffer .= $key;
             // Don't add values for empty sub-resources
             if ($value !== '' && $value !== false && $value !== null && $value !== QueryString::BLANK) {
                 $buffer .= "={$value}";
             }
         }
     }
     return $buffer;
 }
Пример #6
0
 public function testSignsPayload()
 {
     $this->client->putObject(array('Bucket' => $this->bucket, 'Key' => 'test2', 'Body' => 'testing...1234'));
     $this->client->deleteObject(array('Bucket' => $this->bucket, 'Key' => 'test2'));
 }
Пример #7
0
 public function no_testUsesSigV4SignatureInSpecificRegions()
 {
     $s3 = S3Client::factory(array(Options::REGION => 'cn-north-1'));
     $this->assertInstanceOf('Mss\\S3\\S3SignatureV4', $s3->getSignature());
 }