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

36 lines
1.2 KiB
Go

package s3err
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestMalformedACLErrorMapping: ErrMalformedACL is S3's MalformedACLError, a
// 400 client error.
func TestMalformedACLErrorMapping(t *testing.T) {
apiError := GetAPIError(ErrMalformedACL)
assert.Equal(t, "MalformedACLError", apiError.Code)
assert.Equal(t, http.StatusBadRequest, apiError.HTTPStatusCode)
assert.NotEmpty(t, apiError.Description)
}
// TestMalformedACLErrorResponse: the error document a client receives carries
// the MalformedACLError code and the 400 status.
func TestMalformedACLErrorResponse(t *testing.T) {
req := httptest.NewRequest(http.MethodPut, "/bucket/object?acl", nil)
rr := httptest.NewRecorder()
WriteErrorResponse(rr, req, ErrMalformedACL)
require.Equal(t, http.StatusBadRequest, rr.Code)
assert.Contains(t, rr.Body.String(), "<Code>MalformedACLError</Code>")
}
// TestMalformedACLIsAppended: the new code is added after every existing one,
// so the numeric value of each existing ErrorCode stays the same.
func TestMalformedACLIsAppended(t *testing.T) {
assert.Equal(t, ErrNoSuchPublicAccessBlockConfiguration+1, ErrMalformedACL)
}