diff --git a/weed/s3api/s3api_bucket_config.go b/weed/s3api/s3api_bucket_config.go index 6040a589bf..254b2adb83 100644 --- a/weed/s3api/s3api_bucket_config.go +++ b/weed/s3api/s3api_bucket_config.go @@ -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 } diff --git a/weed/s3api/s3api_bucket_cors_proto_test.go b/weed/s3api/s3api_bucket_cors_proto_test.go new file mode 100644 index 0000000000..30742049bf --- /dev/null +++ b/weed/s3api/s3api_bucket_cors_proto_test.go @@ -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) + } + } +}