[#534] Return error if bucket has no tag set
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
parent
01d95d8cf4
commit
c9c7379835
3 changed files with 74 additions and 1 deletions
|
@ -193,6 +193,7 @@ const (
|
|||
ErrInvalidRangeLength
|
||||
ErrRangeOutOfBounds
|
||||
ErrMissingContentRange
|
||||
ErrNoSuchTagSet
|
||||
|
||||
ErrMalformedJSON
|
||||
ErrInsecureClientRequest
|
||||
|
@ -1774,6 +1775,12 @@ var errorCodes = errorCodeMap{
|
|||
Description: "You have reached the quota limit.",
|
||||
HTTPStatusCode: http.StatusConflict,
|
||||
},
|
||||
ErrNoSuchTagSet: {
|
||||
ErrCode: ErrNoSuchTagSet,
|
||||
Code: "NoSuchTagSet",
|
||||
Description: "The TagSet does not exist",
|
||||
HTTPStatusCode: http.StatusNotFound,
|
||||
},
|
||||
// Add your error structure here.
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,12 @@ func (h *handler) GetBucketTaggingHandler(w http.ResponseWriter, r *http.Request
|
|||
|
||||
tagSet, err := h.obj.GetBucketTagging(ctx, bktInfo)
|
||||
if err != nil {
|
||||
h.logAndSendError(ctx, w, "could not get object tagging", reqInfo, err)
|
||||
h.logAndSendError(ctx, w, "could not get bucket tagging", reqInfo, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(tagSet) == 0 {
|
||||
h.logAndSendError(ctx, w, "empty bucket tag set", reqInfo, errors.GetAPIError(errors.ErrNoSuchTagSet))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package handler
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -112,3 +113,63 @@ func TestPutObjectTaggingCheckUniqueness(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBucketTagging(t *testing.T) {
|
||||
hc := prepareHandlerContext(t)
|
||||
bktName, tagKey, tagValue := "get-bucket-tagging", "key", "value"
|
||||
createBucket(hc, bktName)
|
||||
|
||||
getBucketTaggingErr(hc, bktName, apierr.GetAPIError(apierr.ErrNoSuchTagSet))
|
||||
putBucketTagging(hc, bktName, map[string]string{tagKey: tagValue})
|
||||
|
||||
tagSet := getBucketTagging(hc, bktName)
|
||||
require.Len(t, tagSet.TagSet, 1)
|
||||
require.Equal(t, tagKey, tagSet.TagSet[0].Key)
|
||||
require.Equal(t, tagValue, tagSet.TagSet[0].Value)
|
||||
|
||||
deleteBucketTagging(hc, bktName)
|
||||
getBucketTaggingErr(hc, bktName, apierr.GetAPIError(apierr.ErrNoSuchTagSet))
|
||||
}
|
||||
|
||||
func putBucketTagging(hc *handlerContext, bktName string, tags map[string]string) {
|
||||
body := &data.Tagging{
|
||||
TagSet: make([]data.Tag, 0, len(tags)),
|
||||
}
|
||||
|
||||
for key, val := range tags {
|
||||
body.TagSet = append(body.TagSet, data.Tag{
|
||||
Key: key,
|
||||
Value: val,
|
||||
})
|
||||
}
|
||||
|
||||
w, r := prepareTestRequest(hc, bktName, "", body)
|
||||
middleware.GetReqInfo(r.Context()).Tagging = body
|
||||
hc.Handler().PutBucketTaggingHandler(w, r)
|
||||
assertStatus(hc.t, w, http.StatusOK)
|
||||
}
|
||||
|
||||
func getBucketTagging(hc *handlerContext, bktName string) *data.Tagging {
|
||||
w := getBucketTaggingBase(hc, bktName)
|
||||
assertStatus(hc.t, w, http.StatusOK)
|
||||
res := &data.Tagging{}
|
||||
parseTestResponse(hc.t, w, res)
|
||||
return res
|
||||
}
|
||||
|
||||
func getBucketTaggingErr(hc *handlerContext, bktName string, err apierr.Error) {
|
||||
w := getBucketTaggingBase(hc, bktName)
|
||||
assertS3Error(hc.t, w, err)
|
||||
}
|
||||
|
||||
func getBucketTaggingBase(hc *handlerContext, bktName string) *httptest.ResponseRecorder {
|
||||
w, r := prepareTestRequest(hc, bktName, "", nil)
|
||||
hc.Handler().GetBucketTaggingHandler(w, r)
|
||||
return w
|
||||
}
|
||||
|
||||
func deleteBucketTagging(hc *handlerContext, bktName string) {
|
||||
w, r := prepareTestRequest(hc, bktName, "", nil)
|
||||
hc.Handler().DeleteBucketTaggingHandler(w, r)
|
||||
assertStatus(hc.t, w, http.StatusNoContent)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue