Skip to content

Commit

Permalink
Merge pull request aws#684 from jeskew/fix/s3-multipart-checksum
Browse files Browse the repository at this point in the history
Use hex instead of base64 output for S3 SigV4 checksum
  • Loading branch information
jeremeamia committed Jul 11, 2015
2 parents c5ac2e4 + d34b5e6 commit fb6037d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/S3/MultipartUploader.php
Expand Up @@ -214,9 +214,9 @@ protected function getCompleteParams()
private function decorateWithHashes(Stream $stream, array &$data)
{
// Decorate source with a hashing stream
$hash = new PhpHash('sha256', ['base64' => true]);
$hash = new PhpHash('sha256');
return new HashingStream($stream, $hash, function ($result) use (&$data) {
$data['ContentSHA256'] = $result;
$data['ContentSHA256'] = bin2hex($result);
});
}
}
30 changes: 21 additions & 9 deletions tests/Integ/S3MultipartTest.php
Expand Up @@ -4,7 +4,6 @@
use Aws\Exception\MultipartUploadException;
use Aws\S3\BatchDelete;
use Aws\S3\MultipartUploader;
use Aws\Test\Integ\IntegUtils;
use GuzzleHttp\Psr7\NoSeekStream;
use GuzzleHttp\Psr7;

Expand All @@ -18,25 +17,26 @@ class S3Multipart extends \PHPUnit_Framework_TestCase
public static function setUpBeforeClass()
{
$client = self::getSdk()->createS3();
if (!$client->doesBucketExist(self::BUCKET)) {
$client->createBucket(['Bucket' => self::BUCKET]);
$client->waitUntil('BucketExists', ['Bucket' => self::BUCKET]);
if (!$client->doesBucketExist(self::getBucketName())) {
$client->createBucket(['Bucket' => self::getBucketName()]);
$client->waitUntil('BucketExists', ['Bucket' => self::getBucketName()]);
}
}

public static function tearDownAfterClass()
{
$client = self::getSdk()->createS3();
BatchDelete::fromListObjects($client, ['Bucket' => self::BUCKET])->delete();
$client->deleteBucket(['Bucket' => self::BUCKET]);
BatchDelete::fromListObjects($client, ['Bucket' => self::getBucketName()])->delete();
$client->deleteBucket(['Bucket' => self::getBucketName()]);
$client->waitUntil('BucketNotExists', ['Bucket' => self::getBucketName()]);
}

public function useCasesProvider()
{
return [
['SeekableSerialUpload', true, 1],
['NonSeekableSerialUpload', false, 3],
['SeekableConcurrentUpload', true, 1],
['NonSeekableSerialUpload', false, 1],
['SeekableConcurrentUpload', true, 3],
['NonSeekableConcurrentUpload', false, 3],
];
}
Expand All @@ -62,7 +62,7 @@ public function testMultipartUpload($key, $seekable, $concurrency)

// Create the uploader
$uploader = new MultipartUploader($client, $stream, [
'bucket' => self::BUCKET,
'bucket' => self::getBucketName(),
'key' => $key,
'concurrency' => $concurrency
]);
Expand All @@ -84,4 +84,16 @@ public function testMultipartUpload($key, $seekable, $concurrency)

@unlink($tmpFile);
}


private static function getBucketName()
{
static $bucketName;

if (empty($bucketName)) {
$bucketName = self::getResourcePrefix() . self::BUCKET;
}

return $bucketName;
}
}

0 comments on commit fb6037d

Please sign in to comment.