Skip to content

Commit d62301d

Browse files
committed
feat: Added unit and integration test cases for posix bucket tagging related actions
1 parent da5b7d2 commit d62301d

File tree

6 files changed

+314
-10
lines changed

6 files changed

+314
-10
lines changed

backend/posix/posix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1777,15 +1777,15 @@ func (p *Posix) GetBucketTagging(_ context.Context, bucket string) (map[string]s
17771777
return nil, err
17781778
}
17791779

1780-
acl, err := xattr.Get(bucket, "user."+tagHdr)
1780+
acl, err := xattr.Get(bucket, proxyBucketAclKey)
17811781
if isNoAttr(err) {
17821782
return tags, nil
17831783
}
17841784
if err != nil {
17851785
return nil, fmt.Errorf("get tags: %w", err)
17861786
}
17871787

1788-
tags[aclkey] = string(acl)
1788+
tags[proxyAclKey] = string(acl)
17891789

17901790
return tags, nil
17911791
}

cmd/versitygw/test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,11 @@ func getAction(tf testFunc) func(*cli.Context) error {
268268
func extractIntTests() (commands []*cli.Command) {
269269
tests := integration.GetIntTests()
270270
for key, val := range tests {
271+
testKey := key
272+
testFunc := val
271273
commands = append(commands, &cli.Command{
272-
Name: key,
273-
Usage: fmt.Sprintf("Runs %v integration test", key),
274+
Name: testKey,
275+
Usage: fmt.Sprintf("Runs %v integration test", testKey),
274276
Action: func(ctx *cli.Context) error {
275277
opts := []integration.Option{
276278
integration.WithAccess(awsID),
@@ -283,7 +285,7 @@ func extractIntTests() (commands []*cli.Command) {
283285
}
284286

285287
s := integration.NewS3Conf(opts...)
286-
err := val(s)
288+
err := testFunc(s)
287289
return err
288290
},
289291
})

integration/group-tests.go

+28
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ func TestDeleteBucket(s *S3Conf) {
4646
DeleteBucket_success_status_code(s)
4747
}
4848

49+
func TestPutBucketTagging(s *S3Conf) {
50+
PutBucketTagging_non_existing_bucket(s)
51+
PutBucketTagging_long_tags(s)
52+
PutBucketTagging_success(s)
53+
}
54+
55+
func TestGetBucketTagging(s *S3Conf) {
56+
GetBucketTagging_non_existing_bucket(s)
57+
GetBucketTagging_success(s)
58+
}
59+
60+
func TestDeleteBucketTagging(s *S3Conf) {
61+
DeleteBucketTagging_non_existing_object(s)
62+
DeleteBucketTagging_success_status(s)
63+
DeleteBucketTagging_success(s)
64+
}
65+
4966
func TestPutObject(s *S3Conf) {
5067
PutObject_non_existing_bucket(s)
5168
PutObject_special_chars(s)
@@ -197,6 +214,9 @@ func TestFullFlow(s *S3Conf) {
197214
TestHeadBucket(s)
198215
TestListBuckets(s)
199216
TestDeleteBucket(s)
217+
TestPutBucketTagging(s)
218+
TestGetBucketTagging(s)
219+
TestDeleteBucketTagging(s)
200220
TestPutObject(s)
201221
TestHeadObject(s)
202222
TestGetObject(s)
@@ -259,6 +279,14 @@ func GetIntTests() IntTests {
259279
"DeleteBucket_non_existing_bucket": DeleteBucket_non_existing_bucket,
260280
"DeleteBucket_non_empty_bucket": DeleteBucket_non_empty_bucket,
261281
"DeleteBucket_success_status_code": DeleteBucket_success_status_code,
282+
"PutBucketTagging_non_existing_bucket": PutBucketTagging_non_existing_bucket,
283+
"PutBucketTagging_long_tags": PutBucketTagging_long_tags,
284+
"PutBucketTagging_success": PutBucketTagging_success,
285+
"GetBucketTagging_non_existing_bucket": GetBucketTagging_non_existing_bucket,
286+
"GetBucketTagging_success": GetBucketTagging_success,
287+
"DeleteBucketTagging_non_existing_object": DeleteBucketTagging_non_existing_object,
288+
"DeleteBucketTagging_success_status": DeleteBucketTagging_success_status,
289+
"DeleteBucketTagging_success": DeleteBucketTagging_success,
262290
"PutObject_non_existing_bucket": PutObject_non_existing_bucket,
263291
"PutObject_special_chars": PutObject_special_chars,
264292
"PutObject_invalid_long_tags": PutObject_invalid_long_tags,

integration/tests.go

+209
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,215 @@ func DeleteBucket_success_status_code(s *S3Conf) error {
10181018
return nil
10191019
}
10201020

1021+
func PutBucketTagging_non_existing_bucket(s *S3Conf) error {
1022+
testName := "PutBucketTagging_non_existing_bucket"
1023+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1024+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1025+
_, err := s3client.PutBucketTagging(ctx, &s3.PutBucketTaggingInput{
1026+
Bucket: getPtr(getBucketName()),
1027+
Tagging: &types.Tagging{TagSet: []types.Tag{}},
1028+
})
1029+
cancel()
1030+
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrNoSuchBucket)); err != nil {
1031+
return err
1032+
}
1033+
1034+
return nil
1035+
})
1036+
}
1037+
1038+
func PutBucketTagging_long_tags(s *S3Conf) error {
1039+
testName := "PutBucketTagging_long_tags"
1040+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1041+
tagging := types.Tagging{TagSet: []types.Tag{{Key: getPtr(genRandString(200)), Value: getPtr("val")}}}
1042+
1043+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1044+
_, err := s3client.PutBucketTagging(ctx, &s3.PutBucketTaggingInput{
1045+
Bucket: &bucket,
1046+
Tagging: &tagging})
1047+
cancel()
1048+
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidTag)); err != nil {
1049+
return err
1050+
}
1051+
1052+
tagging = types.Tagging{TagSet: []types.Tag{{Key: getPtr("key"), Value: getPtr(genRandString(300))}}}
1053+
1054+
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
1055+
_, err = s3client.PutBucketTagging(ctx, &s3.PutBucketTaggingInput{
1056+
Bucket: &bucket,
1057+
Tagging: &tagging})
1058+
cancel()
1059+
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrInvalidTag)); err != nil {
1060+
return err
1061+
}
1062+
1063+
return nil
1064+
})
1065+
}
1066+
1067+
func PutBucketTagging_success(s *S3Conf) error {
1068+
testName := "PutBucketTagging_success"
1069+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1070+
tagging := types.Tagging{TagSet: []types.Tag{{Key: getPtr("key1"), Value: getPtr("val2")}, {Key: getPtr("key2"), Value: getPtr("val2")}}}
1071+
1072+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1073+
_, err := s3client.PutBucketTagging(ctx, &s3.PutBucketTaggingInput{
1074+
Bucket: &bucket,
1075+
Tagging: &tagging})
1076+
cancel()
1077+
if err != nil {
1078+
return err
1079+
}
1080+
1081+
return nil
1082+
})
1083+
}
1084+
1085+
func GetBucketTagging_non_existing_bucket(s *S3Conf) error {
1086+
testName := "GetBucketTagging_non_existing_object"
1087+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1088+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1089+
_, err := s3client.GetBucketTagging(ctx, &s3.GetBucketTaggingInput{
1090+
Bucket: getPtr(getBucketName()),
1091+
})
1092+
cancel()
1093+
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrNoSuchBucket)); err != nil {
1094+
return err
1095+
}
1096+
return nil
1097+
})
1098+
}
1099+
1100+
func GetBucketTagging_success(s *S3Conf) error {
1101+
testName := "GetBucketTagging_success"
1102+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1103+
tagging := types.Tagging{TagSet: []types.Tag{{Key: getPtr("key1"), Value: getPtr("val2")}, {Key: getPtr("key2"), Value: getPtr("val2")}}}
1104+
1105+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1106+
_, err := s3client.PutBucketTagging(ctx, &s3.PutBucketTaggingInput{
1107+
Bucket: &bucket,
1108+
Tagging: &tagging})
1109+
cancel()
1110+
if err != nil {
1111+
return err
1112+
}
1113+
1114+
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
1115+
out, err := s3client.GetBucketTagging(ctx, &s3.GetBucketTaggingInput{
1116+
Bucket: &bucket,
1117+
})
1118+
cancel()
1119+
if err != nil {
1120+
return nil
1121+
}
1122+
1123+
if !areTagsSame(out.TagSet, tagging.TagSet) {
1124+
return fmt.Errorf("expected %v instead got %v", tagging.TagSet, out.TagSet)
1125+
}
1126+
1127+
return nil
1128+
})
1129+
}
1130+
1131+
func DeleteBucketTagging_non_existing_object(s *S3Conf) error {
1132+
testName := "DeleteBucketTagging_non_existing_object"
1133+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1134+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1135+
_, err := s3client.DeleteBucketTagging(ctx, &s3.DeleteBucketTaggingInput{
1136+
Bucket: getPtr(getBucketName()),
1137+
})
1138+
cancel()
1139+
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrNoSuchBucket)); err != nil {
1140+
return err
1141+
}
1142+
return nil
1143+
})
1144+
}
1145+
1146+
func DeleteBucketTagging_success_status(s *S3Conf) error {
1147+
testName := "DeleteBucketTagging_success_status"
1148+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1149+
tagging := types.Tagging{
1150+
TagSet: []types.Tag{
1151+
{
1152+
Key: getPtr("Hello"),
1153+
Value: getPtr("World"),
1154+
},
1155+
},
1156+
}
1157+
1158+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1159+
_, err := s3client.PutBucketTagging(ctx, &s3.PutBucketTaggingInput{
1160+
Bucket: &bucket,
1161+
Tagging: &tagging,
1162+
})
1163+
cancel()
1164+
if err != nil {
1165+
return err
1166+
}
1167+
1168+
req, err := createSignedReq(http.MethodDelete, s.endpoint, fmt.Sprintf("%v?tagging", bucket), s.awsID, s.awsSecret, "s3", s.awsRegion, nil, time.Now())
1169+
if err != nil {
1170+
return err
1171+
}
1172+
1173+
client := http.Client{
1174+
Timeout: shortTimeout,
1175+
}
1176+
1177+
resp, err := client.Do(req)
1178+
if err != nil {
1179+
return err
1180+
}
1181+
1182+
if resp.StatusCode != http.StatusNoContent {
1183+
return fmt.Errorf("expected response status to be %v, instead got %v", http.StatusNoContent, resp.StatusCode)
1184+
}
1185+
1186+
return nil
1187+
})
1188+
}
1189+
1190+
func DeleteBucketTagging_success(s *S3Conf) error {
1191+
testName := "DeleteBucketTagging_success"
1192+
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
1193+
tagging := types.Tagging{TagSet: []types.Tag{{Key: getPtr("key1"), Value: getPtr("val2")}, {Key: getPtr("key2"), Value: getPtr("val2")}}}
1194+
1195+
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
1196+
_, err := s3client.PutBucketTagging(ctx, &s3.PutBucketTaggingInput{
1197+
Bucket: &bucket,
1198+
Tagging: &tagging})
1199+
cancel()
1200+
if err != nil {
1201+
return err
1202+
}
1203+
1204+
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
1205+
_, err = s3client.DeleteBucketTagging(ctx, &s3.DeleteBucketTaggingInput{
1206+
Bucket: &bucket,
1207+
})
1208+
cancel()
1209+
if err != nil {
1210+
return nil
1211+
}
1212+
1213+
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
1214+
out, err := s3client.GetBucketTagging(ctx, &s3.GetBucketTaggingInput{
1215+
Bucket: &bucket,
1216+
})
1217+
cancel()
1218+
if err != nil {
1219+
return nil
1220+
}
1221+
1222+
if len(out.TagSet) > 0 {
1223+
return fmt.Errorf("expected empty tag set, instead got %v", out.TagSet)
1224+
}
1225+
1226+
return nil
1227+
})
1228+
}
1229+
10211230
func PutObject_non_existing_bucket(s *S3Conf) error {
10221231
testName := "PutObject_non_existing_bucket"
10231232
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {

s3api/controllers/base.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ func (c S3ApiController) DeleteBucket(ctx *fiber.Ctx) error {
752752
}
753753

754754
err := c.be.DeleteBucketTagging(ctx.Context(), bucket)
755-
return SendResponse(ctx, err, &MetaOpts{Logger: c.logger, Action: "DeleteBucketTagging", BucketOwner: parsedAcl.Owner})
755+
return SendResponse(ctx, err, &MetaOpts{Logger: c.logger, Action: "DeleteBucketTagging", BucketOwner: parsedAcl.Owner, Status: http.StatusNoContent})
756756
}
757757

758758
if err := auth.VerifyACL(parsedAcl, acct.Access, "WRITE", isRoot); err != nil {
@@ -762,7 +762,7 @@ func (c S3ApiController) DeleteBucket(ctx *fiber.Ctx) error {
762762
err := c.be.DeleteBucket(ctx.Context(), &s3.DeleteBucketInput{
763763
Bucket: &bucket,
764764
})
765-
return SendResponse(ctx, err, &MetaOpts{Logger: c.logger, Action: "DeleteBucket", BucketOwner: parsedAcl.Owner, Status: 204})
765+
return SendResponse(ctx, err, &MetaOpts{Logger: c.logger, Action: "DeleteBucket", BucketOwner: parsedAcl.Owner, Status: http.StatusNoContent})
766766
}
767767

768768
func (c S3ApiController) DeleteObjects(ctx *fiber.Ctx) error {

0 commit comments

Comments
 (0)