mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-01 09:50:39 +01:00
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:
1 parent
9df2125bb0
commit
26783fbcb3
2 files changed
+24
-2
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user