From 4d91687ca5a7cfce6c29fee510eb6d5c0dbc70b4 Mon Sep 17 00:00:00 2001 From: Nicolas Humbert Date: Wed, 25 Oct 2023 13:28:03 +0200 Subject: [PATCH] CLDSRV-462 Expiration header is not compatible with legacy object md Before the Object Metadata refactor done around May 31, 2017 (https://github.com/scality/Cloudserver/commit/c22e44f63d571a6271af1f1a9c03266b9fd273ae), if no tags were set, the object tag was stored as undefined. After the commit, if no tags are set, the object tag is stored as an empty object '{}'. When the expiration response headers were implemented on https://github.com/scality/cloudserver/commit/812b09afeff5313ae3ec5e0adf99060b94c79b0d around Nov 22, 2021, the empty object was handled, but not the undefined tag logic, which made the expiration response headers not backward compatible. We need to address both cases: the undefined property and the empty object '{}'. --- lib/api/apiUtils/object/expirationHeaders.js | 6 ++++-- package.json | 2 +- tests/unit/api/apiUtils/expirationHeaders.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/api/apiUtils/object/expirationHeaders.js b/lib/api/apiUtils/object/expirationHeaders.js index a4c050435b..8a2bb9af63 100644 --- a/lib/api/apiUtils/object/expirationHeaders.js +++ b/lib/api/apiUtils/object/expirationHeaders.js @@ -37,8 +37,10 @@ const AMZ_ABORT_ID_HEADER = 'x-amz-abort-rule-id'; function _generateExpHeadersObjects(rules, params, datetime) { const tags = { - TagSet: Object.keys(params.tags) - .map(key => ({ Key: key, Value: params.tags[key] })), + TagSet: params.tags + ? Object.keys(params.tags) + .map(key => ({ Key: key, Value: params.tags[key] })) + : [], }; const objectInfo = { Key: params.key }; diff --git a/package.json b/package.json index d43341009a..8b79e537fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "s3", - "version": "7.10.31", + "version": "7.10.32", "description": "S3 connector", "main": "index.js", "engines": { diff --git a/tests/unit/api/apiUtils/expirationHeaders.js b/tests/unit/api/apiUtils/expirationHeaders.js index d1bc0ddaf5..41fa1af48c 100644 --- a/tests/unit/api/apiUtils/expirationHeaders.js +++ b/tests/unit/api/apiUtils/expirationHeaders.js @@ -103,6 +103,16 @@ describe('generateExpirationHeaders', () => { }, {}, ], + [ + 'should provide correct headers for compatibility with legacy objects missing the tags property', + { + lifecycleConfig: lifecycleExpirationDays, + objectParams: { key: 'object', date: objectDate }, + }, + { + 'x-amz-expiration': `expiry-date="${expectedDaysExpiryDate}", rule-id="test-days"`, + }, + ], [ 'should return correct headers for object (days)', {