Files
seaweedfs/weed/s3api/s3api_acl_malformed_acl_test.go
T
Nguyễn Lộc PhúcandClaude Opus 5.5 noreply@anthropic.com 827a3d2a99 fix(s3api): validate ACL grant Permission (#12938)
s3api: validate ACL grant Permission

Reject a grant whose Permission is missing or not one of the five S3
values with a new MalformedACLError, and skip grants without a
permission when building GetAcl responses instead of panicking.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
2026-11-24 15:26:11 -08:00

47 lines
1.8 KiB
Go

package s3api
import (
"testing"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
"github.com/stretchr/testify/require"
)
// TestInvalidGrantPermissionIsMalformedACL: an ACL whose grantees are all valid
// but whose grant permission is omitted or unknown is rejected with S3's
// MalformedACLError, the error S3 returns for an AccessControlPolicy that does
// not validate against its schema.
func TestInvalidGrantPermissionIsMalformedACL(t *testing.T) {
for granteeName, grantee := range validGrantees() {
for _, permission := range invalidGrantPermissions {
t.Run(granteeName+"/"+describePermission(permission), func(t *testing.T) {
result, code := ValidateAndTransferGrants(grantPermissionAccounts{}, []*s3.Grant{
{Grantee: grantee(), Permission: permission},
})
require.Equal(t, s3err.ErrMalformedACL, code)
require.Nil(t, result)
})
}
}
}
// TestExtractAclBodyWithInvalidPermissionIsMalformedACL is the request-level
// form: PutObjectAcl and PutBucketAcl answer such a body with MalformedACLError.
func TestExtractAclBodyWithInvalidPermissionIsMalformedACL(t *testing.T) {
bodies := map[string]string{
"omitted Permission element": aclRequestBody(""),
"empty Permission element": aclRequestBody("<Permission></Permission>"),
"lowercase value": aclRequestBody("<Permission>read</Permission>"),
"unknown value": aclRequestBody("<Permission>READ_WRITE</Permission>"),
"valid then unknown": aclRequestBody("<Permission>READ</Permission>", "<Permission>ALL</Permission>"),
}
for name, body := range bodies {
t.Run(name, func(t *testing.T) {
grants, code := extractAclFromBody(body)
require.Equal(t, s3err.ErrMalformedACL, code)
require.Nil(t, grants)
})
}
}