s3: keep an unset CORS MaxAgeSeconds unset (#12272)

A rule without MaxAgeSeconds was stored as 0, so GetBucketCors returned
MaxAgeSeconds 0 and preflights sent Access-Control-Max-Age: 0. Store -1
for unset, which corsRuleFromProto already reads back as nil.
This commit is contained in:
Jay Hemnani authored and GitHub committed 2026-10-31 05:11:42 -07:00
1 parent 9df2125bb0
commit 26783fbcb3
2 files changed
+24 -2

No files matched your search

+2 -2
View File
@@ -860,10 +860,10 @@ func corsConfigFromProto(protoConfig *s3_pb.CORSConfiguration) *cors.CORSConfigu
}
}
// getMaxAgeSecondsValue safely extracts max age seconds value
// getMaxAgeSecondsValue safely extracts max age seconds value; -1 stores an unset MaxAgeSeconds
func getMaxAgeSecondsValue(maxAge *int) int {
if maxAge == nil {
return 0
return -1
}
return *maxAge
}
@@ -0,0 +1,22 @@
package s3api
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/s3api/cors"
)
func TestCorsRuleProtoRoundTripMaxAge(t *testing.T) {
unset := corsRuleFromProto(corsRuleToProto(cors.CORSRule{AllowedMethods: []string{"GET"}, AllowedOrigins: []string{"*"}}))
if unset.MaxAgeSeconds != nil {
t.Errorf("unset MaxAgeSeconds came back as %d", *unset.MaxAgeSeconds)
}
for _, age := range []int{0, 3000} {
age := age
got := corsRuleFromProto(corsRuleToProto(cors.CORSRule{AllowedMethods: []string{"GET"}, AllowedOrigins: []string{"*"}, MaxAgeSeconds: &age}))
if got.MaxAgeSeconds == nil || *got.MaxAgeSeconds != age {
t.Errorf("MaxAgeSeconds %d came back as %v", age, got.MaxAgeSeconds)
}
}
}