rgw/admin: fix getbucketpolicy api

The request header in GetBucketPolicy(), was not passing policy in its
header, so the response received Bucket than the actual policy.

Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
This commit is contained in:
Jiffin Tony Thottan 2023-06-02 11:23:36 +05:30 committed by mergify[bot]
parent e486e4e653
commit 3051f22a4e
2 changed files with 13 additions and 2 deletions

View File

@ -113,13 +113,13 @@ func (api *API) GetBucketInfo(ctx context.Context, bucket Bucket) (Bucket, error
return ref, nil
}
// GetBucketPolicy - http://docs.ceph.com/docs/mimic/radosgw/adminops/#get-bucket-or-object-policy
// GetBucketPolicy - https://docs.ceph.com/en/latest/radosgw/adminops/#get-bucket-or-object-policy
func (api *API) GetBucketPolicy(ctx context.Context, bucket Bucket) (Policy, error) {
policy := true
bucket.Policy = &policy
// valid parameters not supported by go-ceph: object
body, err := api.call(ctx, http.MethodGet, "/bucket", valueToURLParams(bucket, []string{"bucket"}))
body, err := api.call(ctx, http.MethodGet, "/bucket?policy", valueToURLParams(bucket, []string{"bucket"}))
if err != nil {
return Policy{}, err
}

View File

@ -38,6 +38,17 @@ func (suite *RadosGWTestSuite) TestBucket() {
assert.NoError(suite.T(), err)
})
suite.T().Run("get policy non-existing bucket", func(t *testing.T) {
_, err := co.GetBucketPolicy(context.Background(), Bucket{Bucket: "foo"})
assert.Error(suite.T(), err)
assert.True(suite.T(), errors.Is(err, ErrNoSuchKey), err)
})
suite.T().Run("get policy existing bucket", func(t *testing.T) {
_, err := co.GetBucketPolicy(context.Background(), Bucket{Bucket: suite.bucketTestName})
assert.NoError(suite.T(), err)
})
suite.T().Run("remove bucket", func(t *testing.T) {
err := co.RemoveBucket(context.Background(), Bucket{Bucket: suite.bucketTestName})
assert.NoError(suite.T(), err)