Skip to content

Commit b19ac94

Browse files
author
Krishnan Parthasarathi
committed
Add test for re-created bucket and bucket policy
1 parent 8f01dab commit b19ac94

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

run/core/aws-sdk-php/quick-tests.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ function initSetup(S3Client $s3Client, $objects) {
373373
$stream->close();
374374
}
375375
}
376+
377+
// Create an empty bucket for bucket policy + delete tests
378+
$result = $s3Client->createBucket(['Bucket' => $GLOBALS['emptyBucket']]);
379+
if (getStatusCode($result) != HTTP_OK)
380+
throw new Exception("createBucket API failed for " . $bucket);
381+
376382
}
377383

378384

@@ -756,6 +762,22 @@ function testBucketPolicy($s3Client, $bucket) {
756762

757763
if ($result['Policy'] != $downloadPolicy)
758764
throw new Exception('bucket policy we got is not we set');
765+
766+
// Delete the bucket, make the bucket (again) and check if policy is none
767+
// Ref: https://github.com/minio/minio/issues/4714
768+
$result = $s3Client->deleteBucket(['Bucket' => $bucket]);
769+
if (getstatuscode($result) != HTTP_NOCONTENT)
770+
throw new Exception('deleteBucket API failed for ' .
771+
$bucket);
772+
773+
$result = $s3Client->createBucket(['Bucket' => $bucket]);
774+
if (getstatuscode($result) != HTTP_OK)
775+
throw new Exception('createBucket API failed for ' .
776+
$bucket);
777+
$params = [
778+
'404' => ['Bucket' => $bucket]
779+
];
780+
runExceptionalTests($s3Client, 'getBucketPolicy', 'getStatusCode', $params);
759781
}
760782

761783
/**
@@ -774,8 +796,10 @@ function cleanupSetup($s3Client, $objects) {
774796
$s3Client->deleteObject(['Bucket' => $bucket, 'Key' => $object]);
775797
}
776798

777-
// Delete the buckets
778-
foreach (array_keys($objects) as $bucket) {
799+
// Delete the buckets incl. emptyBucket
800+
$allBuckets = array_keys($objects);
801+
array_push($allBuckets, $GLOBALS['emptyBucket']);
802+
foreach ($allBuckets as $bucket) {
779803
// Delete the bucket
780804
$s3Client->deleteBucket(['Bucket' => $bucket]);
781805

@@ -837,6 +861,8 @@ function runTestFunction($myfunc, ...$args) {
837861
'version' => '2006-03-01'
838862
]);
839863

864+
// Used by initSetup
865+
$emptyBucket = randomName();
840866
$objects = [
841867
randomName() => 'obj1',
842868
randomName() => 'obj2',
@@ -858,7 +884,7 @@ function runTestFunction($myfunc, ...$args) {
858884
runTestFunction('testMultipartUpload', $s3Client, $firstBucket, $firstObject);
859885
runTestFunction('testMultipartUploadFailure', $s3Client, $firstBucket, $firstObject);
860886
runTestFunction('testAbortMultipartUpload', $s3Client, $firstBucket, $firstObject);
861-
runTestFunction('testBucketPolicy', $s3Client, $firstBucket);
887+
runTestFunction('testBucketPolicy', $s3Client, $emptyBucket);
862888
}
863889
finally {
864890
cleanupSetup($s3Client, $objects);

0 commit comments

Comments
 (0)