From 661ea579070373a859b08907c7191069b9ee4b71 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 9 Feb 2022 22:17:41 +0100 Subject: [PATCH] restore: Add quotes some fields in x-amz-restore header (#14281) S3 spec returns x-amz-restore header in HEAD/GET object with the following format: ``` x-amz-restore: ongoing-request="false", expiry-date="Fri, 21 Dec 2012 00:00:00 GMT" ``` This commit adds quotes as the current code does not support it. It will also supports the old format saved in the disk (in xl.meta) for backward compatibility. --- cmd/bucket-lifecycle.go | 12 +++++------- cmd/bucket-lifecycle_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/bucket-lifecycle.go b/cmd/bucket-lifecycle.go index 421c5e2e9..6fdd3b2cb 100644 --- a/cmd/bucket-lifecycle.go +++ b/cmd/bucket-lifecycle.go @@ -693,9 +693,9 @@ func completedRestoreObj(expiry time.Time) restoreObjStatus { // String returns x-amz-restore compatible representation of r. func (r restoreObjStatus) String() string { if r.Ongoing() { - return "ongoing-request=true" + return `ongoing-request="true"` } - return fmt.Sprintf("ongoing-request=false, expiry-date=%s", r.expiry.Format(http.TimeFormat)) + return fmt.Sprintf(`ongoing-request="false", expiry-date="%s"`, r.expiry.Format(http.TimeFormat)) } // Expiry returns expiry of restored object and true if restore-object has completed. @@ -739,12 +739,11 @@ func parseRestoreObjStatus(restoreHdr string) (restoreObjStatus, error) { } switch progressTokens[1] { - case "true": + case "true", `"true"`: // true without double quotes is deprecated in Feb 2022 if len(tokens) == 1 { return ongoingRestoreObj(), nil } - - case "false": + case "false", `"false"`: // false without double quotes is deprecated in Feb 2022 if len(tokens) != 2 { return restoreObjStatus{}, errRestoreHDRMalformed } @@ -755,8 +754,7 @@ func parseRestoreObjStatus(restoreHdr string) (restoreObjStatus, error) { if strings.TrimSpace(expiryTokens[0]) != "expiry-date" { return restoreObjStatus{}, errRestoreHDRMalformed } - - expiry, err := time.Parse(http.TimeFormat, expiryTokens[1]) + expiry, err := time.Parse(http.TimeFormat, strings.Trim(expiryTokens[1], `"`)) if err != nil { return restoreObjStatus{}, errRestoreHDRMalformed } diff --git a/cmd/bucket-lifecycle_test.go b/cmd/bucket-lifecycle_test.go index 0577834d4..38bafee6b 100644 --- a/cmd/bucket-lifecycle_test.go +++ b/cmd/bucket-lifecycle_test.go @@ -36,7 +36,7 @@ func TestParseRestoreObjStatus(t *testing.T) { }{ { // valid: represents a restored object, 'pending' expiry. - restoreHdr: "ongoing-request=false, expiry-date=Fri, 21 Dec 2012 00:00:00 GMT", + restoreHdr: `ongoing-request="false", expiry-date="Fri, 21 Dec 2012 00:00:00 GMT"`, expectedStatus: restoreObjStatus{ ongoing: false, expiry: time.Date(2012, 12, 21, 0, 0, 0, 0, time.UTC), @@ -45,7 +45,7 @@ func TestParseRestoreObjStatus(t *testing.T) { }, { // valid: represents an ongoing restore object request. - restoreHdr: "ongoing-request=true", + restoreHdr: `ongoing-request="true"`, expectedStatus: restoreObjStatus{ ongoing: true, }, @@ -53,13 +53,13 @@ func TestParseRestoreObjStatus(t *testing.T) { }, { // invalid; ongoing restore object request can't have expiry set on it. - restoreHdr: "ongoing-request=true, expiry-date=Fri, 21 Dec 2012 00:00:00 GMT", + restoreHdr: `ongoing-request="true", expiry-date="Fri, 21 Dec 2012 00:00:00 GMT"`, expectedStatus: restoreObjStatus{}, expectedErr: errRestoreHDRMalformed, }, { // invalid; completed restore object request must have expiry set on it. - restoreHdr: "ongoing-request=false", + restoreHdr: `ongoing-request="false"`, expectedStatus: restoreObjStatus{}, expectedErr: errRestoreHDRMalformed, },