Files
seaweedfs/weed/s3api/s3err/error_codes_regression_test.go
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

35 lines
1.1 KiB
Go

package s3err
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
// TestExistingACLErrorMappingsUnchanged pins the codes the ACL paths already
// return, and the last code before MalformedACLError was appended, so adding
// the new code cannot change what clients receive for them. It uses only codes
// that exist on master and passes there too.
func TestExistingACLErrorMappingsUnchanged(t *testing.T) {
cases := []struct {
code ErrorCode
s3Code string
status int
}{
{ErrInvalidRequest, "InvalidRequest", http.StatusBadRequest},
{ErrMalformedXML, "MalformedXML", http.StatusBadRequest},
{ErrAccessDenied, "AccessDenied", http.StatusForbidden},
{ErrNotImplemented, "NotImplemented", http.StatusNotImplemented},
{ErrAccessControlListNotSupported, "AccessControlListNotSupported", http.StatusBadRequest},
{ErrNoSuchPublicAccessBlockConfiguration, "NoSuchPublicAccessBlockConfiguration", http.StatusNotFound},
}
for _, tc := range cases {
t.Run(tc.s3Code, func(t *testing.T) {
apiError := GetAPIError(tc.code)
assert.Equal(t, tc.s3Code, apiError.Code)
assert.Equal(t, tc.status, apiError.HTTPStatusCode)
})
}
}