Files
seaweedfs/weed/s3api/auth_scrub_headers_test.go
T
Chris LuandClaude Opus 5.5 ff20c86caf s3api: canonicalize the scrubbed internal header names once
scrubInternalHeaders runs on every request, and Header.Del
canonicalized each of its nine names again; five are not in canonical
form, so each request allocated their canonical forms anew. Delete the
precomputed canonical keys instead: 775ns and 5 allocations down to
120ns and none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 16:26:56 -08:00

48 lines
1.3 KiB
Go

package s3api
import (
"net/http"
"testing"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
)
func TestScrubInternalHeadersDropsClientValues(t *testing.T) {
keys := []string{
s3_constants.SeaweedFSPrincipalHeader,
s3_constants.SeaweedFSSessionTokenHeader,
s3_constants.ExtObjectLockModeKey,
s3_constants.ExtRetentionUntilDateKey,
s3_constants.ExtLegalHoldKey,
s3_constants.ExtVersionIdKey,
s3_constants.SeaweedFSSSEKMSBaseIVHeader,
s3_constants.SeaweedFSSSES3BaseIVHeader,
s3_constants.SeaweedFSSSES3KeyDataHeader,
}
r, _ := http.NewRequest(http.MethodPut, "http://localhost/b/k", nil)
for _, key := range keys {
r.Header.Set(key, "client")
}
r.Header.Set("X-Amz-Date", "20261205T000000Z")
scrubInternalHeaders(r)
for _, key := range keys {
if got := r.Header.Get(key); got != "" {
t.Errorf("%s kept %q", key, got)
}
}
if r.Header.Get("X-Amz-Date") == "" {
t.Error("scrub dropped a client header")
}
}
func BenchmarkScrubInternalHeaders(b *testing.B) {
r, _ := http.NewRequest(http.MethodPut, "http://localhost/b/k", nil)
r.Header.Set("Authorization", "AWS4-HMAC-SHA256 Credential=x")
r.Header.Set("X-Amz-Date", "20261205T000000Z")
r.Header.Set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
scrubInternalHeaders(r)
}
}