Skip to content

Commit

Permalink
Add presignedPutObject test
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Nov 2, 2017
1 parent 27ac639 commit 2b7fe11
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions run/core/aws-sdk-php/quick-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Aws\Credentials;
use Aws\Exception\AwsException;
use GuzzleHttp\Psr7;
use GuzzleHttp;

// Constants
const FILE_10KB = "datafile-10-kB";
Expand Down Expand Up @@ -812,6 +813,40 @@ function testAnonDeleteObjects($s3Client, $params) {
}
}

/**
* testPresignedPut tests presigned PUT S3 API
*
* @param $s3Client AWS\S3\S3Client object
*
* @param $params associative array containing bucket and object name
*
* @return void
*/
function testPresignedPut($s3Client, $params) {
$bucket = $params['Bucket'];
$object = $params['Object'];
$sha256 = "8663bab6d124806b9727f89bb4ab9db4cbcc3862f6bbf22024dfa7212aa4ab7d";

$cmd = $s3Client->getCommand('PutObject', [
'Bucket' => $bucket,
'Key' => $object,
'ContentSHA256' => $sha256,
]);

$request = $s3Client->createPresignedRequest($cmd, '+20 minutes');
$presignedUrl = (string) $request->getUri();

// Create anonymous config object
$client = new GuzzleHttp\Client();
$body = "Hello, World";
$res = $client->request('PUT', $presignedUrl, $body);

if ($res->getStatusCode() != HTTP_OK) {
throw new Exception('presignedPutObject API failed for ' .
$bucket, $object);
}
}

/**
* testBucketPolicy tests GET/PUT Bucket policy S3 APIs
*
Expand Down Expand Up @@ -1084,6 +1119,7 @@ public function out($data) {
runTest($s3Client, 'testMultipartUpload', "createMultipartUpload ( array \$params = [] )", $testParams);
runTest($s3Client, 'testMultipartUploadFailure', "uploadPart ( array \$params = [] )", $testParams);
runTest($s3Client, 'testAbortMultipartUpload', "abortMultipartupload ( array \$params = [] )", $testParams);
runTest($s3Client, 'testPresignedPut', "presignedPut ( array \$params = [] )", $testParams);
runTest($s3Client, 'testBucketPolicy', "getBucketPolicy ( array \$params = [] )", ['Bucket' => $emptyBucket]);
}
finally {
Expand Down

0 comments on commit 2b7fe11

Please sign in to comment.