Browse Source

fix tests

pull/6997/head
chrislu 5 months ago
parent
commit
c5628b000b
  1. 2
      docker/compose/s3tests.conf
  2. 4
      weed/s3api/s3api_object_handlers_put.go
  3. 28
      weed/s3api/s3api_object_retention.go

2
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

4
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

28
weed/s3api/s3api_object_retention.go

@ -226,27 +226,39 @@ 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
}
// 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 {
// Validate Years if specified
if retention.Years > 0 {
if retention.Years > MaxRetentionYears {
return ErrDefaultRetentionYearsOutOfRange
}
}
return nil
}

Loading…
Cancel
Save