|
|
@ -250,6 +250,11 @@ func testPutBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName string |
|
|
|
credentials credential, t *testing.T) { |
|
|
|
credentials credential, t *testing.T) { |
|
|
|
initBucketPolicies(obj) |
|
|
|
initBucketPolicies(obj) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bucketName1 := fmt.Sprintf("%s-1", bucketName) |
|
|
|
|
|
|
|
if err := obj.MakeBucket(bucketName1); err != nil { |
|
|
|
|
|
|
|
t.Fatal(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// template for constructing HTTP request body for PUT bucket policy.
|
|
|
|
// template for constructing HTTP request body for PUT bucket policy.
|
|
|
|
bucketPolicyTemplate := `{"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"AWS":["*"]},"Action":["s3:GetBucketLocation","s3:ListBucket"],"Resource":["arn:aws:s3:::%s"]},{"Sid":"","Effect":"Allow","Principal":{"AWS":["*"]},"Action":["s3:GetObject"],"Resource":["arn:aws:s3:::%s/this*"]}]}` |
|
|
|
bucketPolicyTemplate := `{"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"AWS":["*"]},"Action":["s3:GetBucketLocation","s3:ListBucket"],"Resource":["arn:aws:s3:::%s"]},{"Sid":"","Effect":"Allow","Principal":{"AWS":["*"]},"Action":["s3:GetObject"],"Resource":["arn:aws:s3:::%s/this*"]}]}` |
|
|
|
|
|
|
|
|
|
|
@ -327,7 +332,7 @@ func testPutBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName string |
|
|
|
// setting an invalid bucket policy.
|
|
|
|
// setting an invalid bucket policy.
|
|
|
|
// the bucket policy parser will fail.
|
|
|
|
// the bucket policy parser will fail.
|
|
|
|
{ |
|
|
|
{ |
|
|
|
bucketName: "non-existent-bucket", |
|
|
|
bucketName: bucketName, |
|
|
|
bucketPolicyReader: bytes.NewReader([]byte("dummy-policy")), |
|
|
|
bucketPolicyReader: bytes.NewReader([]byte("dummy-policy")), |
|
|
|
|
|
|
|
|
|
|
|
policyLen: len([]byte("dummy-policy")), |
|
|
|
policyLen: len([]byte("dummy-policy")), |
|
|
@ -339,7 +344,7 @@ func testPutBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName string |
|
|
|
// Different bucket name used in the HTTP request and the policy string.
|
|
|
|
// Different bucket name used in the HTTP request and the policy string.
|
|
|
|
// checkBucketPolicyResources should fail.
|
|
|
|
// checkBucketPolicyResources should fail.
|
|
|
|
{ |
|
|
|
{ |
|
|
|
bucketName: "different-bucket", |
|
|
|
bucketName: bucketName1, |
|
|
|
bucketPolicyReader: bytes.NewReader([]byte(fmt.Sprintf(bucketPolicyTemplate, bucketName, bucketName))), |
|
|
|
bucketPolicyReader: bytes.NewReader([]byte(fmt.Sprintf(bucketPolicyTemplate, bucketName, bucketName))), |
|
|
|
|
|
|
|
|
|
|
|
policyLen: len(fmt.Sprintf(bucketPolicyTemplate, bucketName, bucketName)), |
|
|
|
policyLen: len(fmt.Sprintf(bucketPolicyTemplate, bucketName, bucketName)), |
|
|
@ -358,7 +363,7 @@ func testPutBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName string |
|
|
|
policyLen: len(fmt.Sprintf(bucketPolicyTemplate, bucketName, bucketName)), |
|
|
|
policyLen: len(fmt.Sprintf(bucketPolicyTemplate, bucketName, bucketName)), |
|
|
|
accessKey: credentials.AccessKeyID, |
|
|
|
accessKey: credentials.AccessKeyID, |
|
|
|
secretKey: credentials.SecretAccessKey, |
|
|
|
secretKey: credentials.SecretAccessKey, |
|
|
|
expectedRespStatus: http.StatusInternalServerError, |
|
|
|
expectedRespStatus: http.StatusNotFound, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// Test case - 9.
|
|
|
|
// Test case - 9.
|
|
|
|
// invalid bucket name is used.
|
|
|
|
// invalid bucket name is used.
|
|
|
@ -527,7 +532,7 @@ func testGetBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName string |
|
|
|
accessKey: credentials.AccessKeyID, |
|
|
|
accessKey: credentials.AccessKeyID, |
|
|
|
secretKey: credentials.SecretAccessKey, |
|
|
|
secretKey: credentials.SecretAccessKey, |
|
|
|
expectedBucketPolicy: bucketPolicyTemplate, |
|
|
|
expectedBucketPolicy: bucketPolicyTemplate, |
|
|
|
expectedRespStatus: http.StatusInternalServerError, |
|
|
|
expectedRespStatus: http.StatusNotFound, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// Test case - 3.
|
|
|
|
// Test case - 3.
|
|
|
|
// Case with invalid bucket name.
|
|
|
|
// Case with invalid bucket name.
|
|
|
@ -736,7 +741,7 @@ func testDeleteBucketPolicyHandler(obj ObjectLayer, instanceType, bucketName str |
|
|
|
bucketName: "non-existent-bucket", |
|
|
|
bucketName: "non-existent-bucket", |
|
|
|
accessKey: credentials.AccessKeyID, |
|
|
|
accessKey: credentials.AccessKeyID, |
|
|
|
secretKey: credentials.SecretAccessKey, |
|
|
|
secretKey: credentials.SecretAccessKey, |
|
|
|
expectedRespStatus: http.StatusInternalServerError, |
|
|
|
expectedRespStatus: http.StatusNotFound, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// Test case - 3.
|
|
|
|
// Test case - 3.
|
|
|
|
// Case with invalid bucket name.
|
|
|
|
// Case with invalid bucket name.
|
|
|
|