Skip to content

Commit

Permalink
api: Return correct error on lock configuration check
Browse files Browse the repository at this point in the history
Closes #869.

Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Oct 30, 2023
1 parent 30b5025 commit 72ab84d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions api/handler/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (h *handler) GetObjectRetentionHandler(w http.ResponseWriter, r *http.Reque

func checkLockConfiguration(conf *data.ObjectLockConfiguration) error {
if conf.ObjectLockEnabled != "" && conf.ObjectLockEnabled != enabledValue {
return fmt.Errorf("invalid ObjectLockEnabled value: %s", conf.ObjectLockEnabled)
return s3errors.GetAPIError(s3errors.ErrMalformedXML)
}

if conf.Rule == nil || conf.Rule.DefaultRetention == nil {
Expand All @@ -287,15 +287,15 @@ func checkLockConfiguration(conf *data.ObjectLockConfiguration) error {

retention := conf.Rule.DefaultRetention
if retention.Mode != governanceMode && retention.Mode != complianceMode {
return fmt.Errorf("invalid Mode value: %s", retention.Mode)
return s3errors.GetAPIError(s3errors.ErrMalformedXML)
}

if retention.Days == 0 && retention.Years == 0 {
return fmt.Errorf("you must specify Days or Years")
if retention.Days <= 0 && retention.Years <= 0 {
return s3errors.GetAPIError(s3errors.ErrInvalidArgument)
}

if retention.Days != 0 && retention.Years != 0 {
return fmt.Errorf("you cannot specify Days and Years at the same time")
return s3errors.GetAPIError(s3errors.ErrInvalidArgument)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion api/handler/locking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestPutBucketLockConfigurationHandler(t *testing.T) {
{
name: "invalid configuration",
bucket: bktLockEnabled,
expectedError: s3errors.GetAPIError(s3errors.ErrInternalError),
expectedError: s3errors.GetAPIError(s3errors.ErrMalformedXML),
configuration: &data.ObjectLockConfiguration{ObjectLockEnabled: "dummy"},
},
{
Expand Down

0 comments on commit 72ab84d

Please sign in to comment.