[#506] Deny bucket names with dot
All checks were successful
/ DCO (pull_request) Successful in 1m48s
/ Vulncheck (pull_request) Successful in 1m56s
/ Builds (pull_request) Successful in 1m41s
/ Lint (pull_request) Successful in 2m33s
/ Tests (pull_request) Successful in 1m39s

Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
Marina Biryukova 2024-10-08 12:44:00 +03:00
parent 9e5fb4be95
commit f3d0178999
2 changed files with 5 additions and 11 deletions

View file

@ -1011,18 +1011,12 @@ func checkBucketName(bucketName string) error {
return apierr.GetAPIError(apierr.ErrInvalidBucketName) return apierr.GetAPIError(apierr.ErrInvalidBucketName)
} }
labels := strings.Split(bucketName, ".") for i, r := range bucketName {
for _, label := range labels { if r == '.' || (!isAlphaNum(r) && r != '-') {
if len(label) == 0 {
return apierr.GetAPIError(apierr.ErrInvalidBucketName) return apierr.GetAPIError(apierr.ErrInvalidBucketName)
} }
for i, r := range label { if (i == 0 || i == len(bucketName)-1) && r == '-' {
if !isAlphaNum(r) && r != '-' { return apierr.GetAPIError(apierr.ErrInvalidBucketName)
return apierr.GetAPIError(apierr.ErrInvalidBucketName)
}
if (i == 0 || i == len(label)-1) && r == '-' {
return apierr.GetAPIError(apierr.ErrInvalidBucketName)
}
} }
} }

View file

@ -42,10 +42,10 @@ func TestCheckBucketName(t *testing.T) {
}{ }{
{name: "bucket"}, {name: "bucket"},
{name: "2bucket"}, {name: "2bucket"},
{name: "buc.ket"},
{name: "buc-ket"}, {name: "buc-ket"},
{name: "abc"}, {name: "abc"},
{name: "63aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, {name: "63aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
{name: "buc.ket", err: true},
{name: "buc.-ket", err: true}, {name: "buc.-ket", err: true},
{name: "bucket.", err: true}, {name: "bucket.", err: true},
{name: ".bucket", err: true}, {name: ".bucket", err: true},