Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the Vanity configuration #11

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions build/vanity/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
# Vanity configuration
vanity:
name: AWS SDK for PHP
api:
stage: dev
exclude:
classes: /\n/
warn:
dependencies: true
inconsistencies: true
todo: true
ungrouped: true

warn:
dependencies: true
inconsistencies: true
todo: true
ungrouped: true

generator:
template:
comments:
facebook_app_id: "124113651073820"

meta:
windows_bgcolor: "#fff"

seo:
contributors: ["Michael Dowling", "Jeremy Lindblom"]
copyright_years: "2010-2012"
copyright_owner: "Amazon Web Services, Inc."
copyright_owner_url: http://aws.amazon.com
description: "With AWS SDK for PHP, developers get started using Amazon Web Services, including Amazon DynamoDB, Amazon S3, Amazon Glacier and Amazon CloudFront."
google_verification: XHghG81ulgiW-3EylGcF48sG28tBW5EH0bNUhgo_DrU
license_url: http://aws.amazon.com/apache2.0
locale: en-US

social_buttons:
facebook_app_id: "124113651073820"
facebook_page: https://www.facebook.com/pages/AWS-SDK-for-PHP/276240099155588
google_plus: true
twitter_username: AWSSDKforPHP

web_root: http://docs.amazonwebservices.com/aws-sdk-php-2/latest/
Binary file added build/vanity/static/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/vanity/static/favicon.ico
Binary file not shown.
Binary file added build/vanity/static/tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/vanity/static/windows-pinned-site.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion src/Aws/S3/BucketStyleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public function onCommandBeforeSend(Event $event)
{
$command = $event['command'];
$bucket = $command['Bucket'];
$key = $command['Key'];
$request = $command->getRequest();
$pathStyle = false;

// Set the key and bucket on the request
$request->getParams()->set('bucket', $bucket)->set('key', $command['key']);
$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)
Expand All @@ -54,6 +56,24 @@ public function onCommandBeforeSend(Event $event)
// Switch to virtual hosted bucket
$request->setHost($bucket . '.' . $request->getHost());
$request->setPath(str_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 ? ('/' . rawurlencode($key)) : '')
);
} else {
// Bucket style needs a trailing slash
$request->getParams()->set(
's3.resource',
'/' . rawurlencode($bucket) . ($key ? ('/' . rawurlencode($key)) : '/')
);
}
}
}
14 changes: 10 additions & 4 deletions src/Aws/S3/S3Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,17 @@ protected function createCanonicalizedAmzHeaders(RequestInterface $request)
*/
protected function createCanonicalizedResource(RequestInterface $request)
{
$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}" : '';
$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}" : '';
// if the bucket was path style, then ensure that the bucket wasn't duplicated in the resource
$buffer .= str_replace("/{$bucket}/{$bucket}", "/{$bucket}", $request->getPath());
}

$buffer .= $request->getPath();
// Remove double slashes
$buffer = str_replace('//', '/', $buffer);

// Add sub resource parameters
Expand Down
94 changes: 71 additions & 23 deletions tests/Aws/Tests/S3/Integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ public static function setUpBeforeClass()
$client = self::getServiceBuilder()->get('s3');
$bucket = self::getResourcePrefix() . '-s3-test';
self::log("Creating the {$bucket} bucket");
$client->createBucket(array(
'Bucket' => $bucket
));
$client->createBucket(array('Bucket' => $bucket));
// Create the bucket
self::log("Waiting for the bucket to exist");
$client->waitUntil('bucket_exists', $bucket);

sleep(5);
// Create the bucket
self::log("Getting owner id and display name");
$result = $client->listBuckets();
Expand All @@ -80,9 +78,15 @@ public static function tearDownAfterClass()
$clear = new ClearBucket($client, $bucket);
$clear->clear();
self::log("Deleting the {$bucket} bucket");
$client->deleteBucket(array(
'Bucket' => $bucket
));
$client->deleteBucket(array('Bucket' => $bucket));
self::log("Waiting for {$bucket} to not exist");
$client->waitUntil('bucket_not_exists', $bucket);
// Delete the other bucket
$bucket = self::getResourcePrefix() . '_path';
$clear = new ClearBucket($client, $bucket);
$clear->clear();
self::log("Deleting the {$bucket} bucket");
$client->deleteBucket(array('Bucket' => $bucket));
self::log("Waiting for {$bucket} to not exist");
$client->waitUntil('bucket_not_exists', $bucket);
}
Expand All @@ -91,20 +95,40 @@ public function setUp()
{
$this->bucket = self::getResourcePrefix() . '-s3-test';
$this->client = $this->getServiceBuilder()->get('s3', true);
//$this->client->addSubscriber(\Guzzle\Plugin\Log\LogPlugin::getDebugPlugin());
//$this->client->addSubscriber(\Guzzle\Plugin\Log\LogPlugin::getDebugPlugin());
$this->acp = AcpBuilder::newInstance()
->setOwner(self::$ownerId, self::$displayName)
->addGrantForGroup(Permission::READ, Group::AUTHENTICATED_USERS)
->addGrantForGroup(Permission::READ_ACP, Group::ALL_USERS)
->build();
}

public function testSignsPathBucketsCorrectly()
{
try {
$client = self::getServiceBuilder()->get('s3');
$bucket = self::getResourcePrefix() . '_path';
self::log("Creating the {$bucket} bucket");
$client->createBucket(array('Bucket' => $bucket));
// Create the bucket
self::log("Waiting for the bucket to exist");
$client->waitUntil('bucket_exists', $bucket);
$this->client->putObject(array(
'Bucket' => $bucket,
'Key' => self::TEST_KEY,
'Body' => '123'
));
$this->client->waitUntil('bucket_exists', $bucket);
$this->client->getBucketLocation(array('Bucket' => $bucket));
} catch (\Aws\S3\Exception\SignatureDoesNotMatchException $e) {
echo $e->getResponse()->getRequest()->getParams()->get('aws.string_to_sign') . "\n";
echo $e->getResponse() . "\n";
throw $e;
}
}

public function testHeadBucket()
{
$result = $this->client->headBucket(array(
'Bucket' => $this->bucket
));
$result = $this->client->headBucket(array('Bucket' => $this->bucket));
$this->assertNotNull($result['RequestId']);
}

Expand Down Expand Up @@ -242,6 +266,7 @@ public function testGetBucketWebsite()
*/
public function testPutAndListObjects()
{
$this->client->waitUntil('bucket_exists', $this->bucket);
$command = $this->client->getCommand('PutObject', array(
'Bucket' => $this->bucket,
'Key' => self::TEST_KEY,
Expand Down Expand Up @@ -296,6 +321,21 @@ public function testPutAndListObjects()
$this->assertEquals('foo', $objects[0]['Key']);
}

/**
* @depends testPutAndListObjects
* @depends testSignsPathBucketsCorrectly
*/
public function testCanSendRawHttpRequests()
{
$this->client->waitUntil('bucket_exists', $this->bucket);
$this->assertEquals(200, $this->client->get('/')->send()->getStatusCode());
$this->assertEquals(200, $this->client->put('/' . $this->bucket . '/hello', array(), 'testing')->send()->getStatusCode());
$this->client->get('/' . self::getResourcePrefix() . '_path')->send();
$path = self::getResourcePrefix() . '_path/' . self::TEST_KEY;
$this->client->waitUntil('object_exists', $path);
$this->client->get("/{$path}")->send();
}

/**
* @depends testPutAndListObjects
*/
Expand Down Expand Up @@ -344,12 +384,20 @@ public function testGetObjectAcl()
public function testPutObjectsWithUtf8Keys()
{
self::log("Uploading an object with a UTF-8 key");
$this->client->waitUntil('bucket_exists', $this->bucket);
$key = 'åbc';
$this->client->putObject(array(
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => 'hi'
));

try {
$this->client->putObject(array(
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => 'hi'
));
} catch (\Aws\S3\Exception\SignatureDoesNotMatchException $e) {
echo $e->getResponse()->getRequest()->getParams()->get('aws.string_to_sign') . "\n";
echo $e->getResponse() . "\n";
throw $e;
}
$this->client->waitUntil('object_exists', "{$this->bucket}/{$key}");
}

Expand Down Expand Up @@ -377,13 +425,12 @@ public function testCopiesObjects()
*/
public function testMultipartUploads()
{
$this->client->waitUntil('bucket_exists', $this->bucket);
$this->log('Initiating an upload');
$result = $this->client->createMultipartUpload(array(
'Bucket' => $this->bucket,
'Key' => 'big',
'Metadata' => array(
'foo' => 'bar'
)
'Metadata' => array('foo' => 'bar')
));
$this->assertNotEmpty($result['UploadId']);
$this->assertNotEmpty($result['Key']);
Expand All @@ -394,15 +441,15 @@ public function testMultipartUploads()
$this->log('Getting uploads');
$command = $this->client->getCommand('ListMultipartUploads', array(
'Bucket' => $this->bucket,
'Key' => 'big',
'UploadId' => $uploadId
));
$result = $command->execute();
$this->assertEquals($this->bucket, $result['Bucket']);
$this->assertInternalType('array', $result['Uploads']);
$this->assertSame(false, $result['IsTruncated']);

$this->log('Aborting the upload');
sleep(2);
$this->client->waitUntil('bucket_exists', $this->bucket);
$command = $this->client->getCommand('AbortMultipartUpload', array(
'Bucket' => $this->bucket,
'Key' => 'big',
Expand All @@ -418,6 +465,7 @@ public function testMultipartUploads()
public function testPutBucketTagging()
{
self::log("Adding tags to a bucket");
$this->client->waitUntil('bucket_exists', $this->bucket);
$command = $this->client->getCommand('PutBucketTagging', array(
'Bucket' => $this->bucket,
'TagSet' => array(
Expand Down Expand Up @@ -482,7 +530,7 @@ public function testUsesTieredStorage()
self::log("Waiting until the object exists");
$this->client->waitUntil('object_exists', "{$this->bucket}/{$key}");
self::log("Moving the object to glacier by setting a lifecycle policy on the object");

$this->client->waitUntil('bucket_exists', $this->bucket);
$command = $this->client->getCommand('PutBucketLifecycle', array(
'Bucket' => $this->bucket,
'Rules' => array(
Expand Down