satellite/metainfo: fix bucket name validation

Change-Id: Ifa400ec855ee978ff001fa3736a8a4c1c53fd18c
This commit is contained in:
Michal Niewrzal 2023-07-03 13:23:00 +02:00 committed by Storj Robot
parent 6a3802de4f
commit 2c3464081f
2 changed files with 5 additions and 2 deletions

View File

@ -115,6 +115,7 @@ func TestBucketNameValidation(t *testing.T) {
"192.168.1.234", "testBUCKET",
"test/bucket",
"testbucket-64-0123456789012345678901234567890123456789012345abcd",
"test\\", "test%",
}
for _, name := range invalidNames {
_, err = metainfoClient.BeginObject(ctx, metaclient.BeginObjectParams{
@ -122,11 +123,13 @@ func TestBucketNameValidation(t *testing.T) {
EncryptedObjectKey: []byte("123"),
})
require.Error(t, err, "bucket name: %v", name)
require.True(t, errs2.IsRPC(err, rpcstatus.InvalidArgument))
_, err = metainfoClient.CreateBucket(ctx, metaclient.CreateBucketParams{
Name: []byte(name),
})
require.Error(t, err, "bucket name: %v", name)
require.True(t, errs2.IsRPC(err, rpcstatus.InvalidArgument))
}
})
}

View File

@ -284,8 +284,8 @@ func validateBucketLabel(label []byte) error {
return Error.New("bucket label must start with a lowercase letter or number")
}
if label[0] == '-' || label[len(label)-1] == '-' {
return Error.New("bucket label cannot start or end with a hyphen")
if !isLowerLetter(label[len(label)-1]) && !isDigit(label[len(label)-1]) {
return Error.New("bucket label must end with a lowercase letter or number")
}
for i := 1; i < len(label)-1; i++ {