diff --git a/docker/compose/s3tests.conf b/docker/compose/s3tests.conf index 3b0629fcb..98c716d02 100644 --- a/docker/compose/s3tests.conf +++ b/docker/compose/s3tests.conf @@ -5,7 +5,7 @@ host = 127.0.0.1 # port set for rgw in vstart.sh -port = 8000 +port = 8333 ## say "False" to disable TLS is_secure = False diff --git a/weed/s3api/s3api_object_handlers_put.go b/weed/s3api/s3api_object_handlers_put.go index b534f9662..ec6f97e31 100644 --- a/weed/s3api/s3api_object_handlers_put.go +++ b/weed/s3api/s3api_object_handlers_put.go @@ -600,6 +600,10 @@ func mapValidationErrorToS3Error(err error) s3err.ErrorCode { // For malformed XML in request body, return MalformedXML // This matches the test expectations for invalid retention mode and legal hold status return s3err.ErrMalformedXML + case errors.Is(err, ErrInvalidRetentionPeriod): + // For invalid retention period (e.g., Days <= 0), return InvalidRetentionPeriod + // This matches the test expectations + return s3err.ErrInvalidRetentionPeriod // Validation error constants case errors.Is(err, ErrObjectLockConfigurationMissingEnabled): return s3err.ErrMalformedXML diff --git a/weed/s3api/s3api_object_retention.go b/weed/s3api/s3api_object_retention.go index ca4c38a27..deef7dee1 100644 --- a/weed/s3api/s3api_object_retention.go +++ b/weed/s3api/s3api_object_retention.go @@ -226,26 +226,38 @@ func validateDefaultRetention(retention *DefaultRetention) error { return ErrInvalidDefaultRetentionMode } - // Exactly one of Days or Years must be specified - if retention.Days == 0 && retention.Years == 0 { - return ErrDefaultRetentionMissingPeriod + // Check for invalid Years value (negative values are always invalid) + if retention.Years < 0 { + return ErrInvalidRetentionPeriod } - if retention.Days > 0 && retention.Years > 0 { - return ErrDefaultRetentionBothDaysAndYears + // Check for invalid Days value (negative values are invalid) + if retention.Days < 0 { + return ErrInvalidRetentionPeriod } - // Validate ranges - Days must be greater than 0 - if retention.Days <= 0 { + // Check for Days: 0 when Years is also 0 (this should return InvalidRetentionPeriod) + if retention.Days == 0 && retention.Years == 0 { return ErrInvalidRetentionPeriod } - if retention.Days > MaxRetentionDays { - return ErrDefaultRetentionDaysOutOfRange + // Check for both Days and Years being specified + if retention.Days > 0 && retention.Years > 0 { + return ErrDefaultRetentionBothDaysAndYears + } + + // Validate Days if specified + if retention.Days > 0 { + if retention.Days > MaxRetentionDays { + return ErrDefaultRetentionDaysOutOfRange + } } - if retention.Years < 0 || retention.Years > MaxRetentionYears { - return ErrDefaultRetentionYearsOutOfRange + // Validate Years if specified + if retention.Years > 0 { + if retention.Years > MaxRetentionYears { + return ErrDefaultRetentionYearsOutOfRange + } } return nil