From 6464d7561e7c9b8796455efe7c641611eee76976 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 1 Nov 2017 18:17:57 -0700 Subject: [PATCH] Add presignedPutObject test --- run/core/aws-sdk-php/quick-tests.php | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/run/core/aws-sdk-php/quick-tests.php b/run/core/aws-sdk-php/quick-tests.php index 9cbe62ea..8e3bf653 100644 --- a/run/core/aws-sdk-php/quick-tests.php +++ b/run/core/aws-sdk-php/quick-tests.php @@ -22,6 +22,7 @@ use Aws\Credentials; use Aws\Exception\AwsException; use GuzzleHttp\Psr7; +use GuzzleHttp\Client; // Constants const FILE_10KB = "datafile-10-kB"; @@ -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 = "03675ac53ff9cd1535ccc7dfcdfa2c458c5218371f418dc136f2d19ac1fbe8a5"; + + $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 Client(); + $body = "Hello, World"; + $res = $client->request('PUT', $presignedUrl, ['body' => $body]); + + if ($res->getStatusCode() != HTTP_OK) { + throw new Exception('presignedPutObject API failed for ' . + $bucket, $object); + } +} + /** * testBucketPolicy tests GET/PUT Bucket policy S3 APIs * @@ -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 {