From 646c3e2bb6d39c6ca8aa7ca756e87d580590ca86 Mon Sep 17 00:00:00 2001 From: KillianG Date: Wed, 5 Jul 2023 15:21:17 +0000 Subject: [PATCH] Adding functionnal testing and verfication for SSE and website redirect Issue: CLDSRV-408 --- lib/api/apiUtils/object/versioning.js | 20 +++++++++++---- lib/services.js | 5 ++++ .../aws-node-sdk/test/utils/init.js | 25 +++++++++++++++++++ tests/unit/api/apiUtils/versioning.js | 21 ++++++++-------- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/lib/api/apiUtils/object/versioning.js b/lib/api/apiUtils/object/versioning.js index d6ef368c72..069634f684 100644 --- a/lib/api/apiUtils/object/versioning.js +++ b/lib/api/apiUtils/object/versioning.js @@ -443,18 +443,28 @@ function preprocessingVersioningDelete(bucketName, bucketMD, objectMD, reqVersio */ function restoreMetadatas(objMD, metadataStoreParams) { /* eslint-disable no-param-reassign */ - const userMDNotToKeep = ['x-amz-meta-scal-s3-restore-attempt']; + const userMDToSkip = ['x-amz-meta-scal-s3-restore-attempt']; // We need to keep user metadata and tags Object.keys(objMD).forEach(key => { - if (key.startsWith('x-amz-meta-') && !userMDNotToKeep.includes(key)) { + if (key.startsWith('x-amz-meta-') && !userMDToSkip.includes(key)) { metadataStoreParams.metaHeaders[key] = objMD[key]; - } - if (key.startsWith('content-') && !userMDNotToKeep.includes(key)) { + } else if (key.startsWith('content-')) { metadataStoreParams[key] = objMD[key]; } }); - if (objMD.replicationInfo?.status === 'COMPLETED') { + if (objMD['x-amz-server-side-encryption']) { + metadataStoreParams.cipherBundle = { + algorithm: objMD['x-amz-server-side-encryption'], + masterKeyId: objMD['x-amz-server-side-encryption-aws-kms-key-id'] || objMD['x-amz-server-side-encryption-customer-algorithm'], + } + } + + if (objMD['x-amz-website-redirect-location']) { + metadataStoreParams.headers['x-amz-website-redirect-location'] = objMD['x-amz-website-redirect-location']; + } + + if (objMD.replicationInfo) { metadataStoreParams.replicationInfo = objMD.replicationInfo; } diff --git a/lib/services.js b/lib/services.js index bc88fc142a..65d2c7ea08 100644 --- a/lib/services.js +++ b/lib/services.js @@ -128,6 +128,11 @@ const services = { if (lastModifiedDate) { md.setLastModified(lastModifiedDate); } + + if (!cipherBundle && params.cipherBundle) { + cipherBundle = params.cipherBundle; + } + if (cipherBundle) { md.setAmzServerSideEncryption(cipherBundle.algorithm); // configuredMasterKeyId takes precedence diff --git a/tests/functional/aws-node-sdk/test/utils/init.js b/tests/functional/aws-node-sdk/test/utils/init.js index 9816cbfe60..5c4c38fd91 100644 --- a/tests/functional/aws-node-sdk/test/utils/init.js +++ b/tests/functional/aws-node-sdk/test/utils/init.js @@ -79,6 +79,31 @@ function fakeMetadataArchive(bucketName, objectName, versionId, archive, cb) { /* eslint-disable no-param-reassign */ objMD.dataStoreName = 'location-dmf-v1'; objMD.archive = archive; + objMD['x-amz-meta-custom-user-md'] = 'custom-md'; + objMD.tags = { tag1: 'value1', tag2: 'value2' }; + objMD["x-amz-server-side-encryption"] = "AES256"; + objMD["x-amz-server-side-encryption-aws-kms-key-id"] = "very-secret-key"; + objMD['x-amz-website-redirect-location'] = 'https://scality.com/' + objMD.replicationInfo = { + "status" : "PENDING", + "backends" : [ + { + "site" : "azure-normal", + "status" : "PENDING", + "dataStoreVersionId" : "" + } + ], + "content" : [ + "DATA", + "METADATA" + ], + "destination" : "arn:aws:s3:::versioned", + "storageClass" : "azure-normal", + "role" : "arn:aws:iam::root:role/s3-replication-role", + "storageType" : "azure", + "dataStoreVersionId" : "", + "isNFS" : null + }; /* eslint-enable no-param-reassign */ return metadata.putObjectMD(bucketName, objectName, objMD, { versionId: decodeVersionId(versionId) }, log, err => cb(err)); diff --git a/tests/unit/api/apiUtils/versioning.js b/tests/unit/api/apiUtils/versioning.js index c323628a89..64e4746ac4 100644 --- a/tests/unit/api/apiUtils/versioning.js +++ b/tests/unit/api/apiUtils/versioning.js @@ -639,16 +639,17 @@ describe('versioning helpers', () => { [ { description: 'Should update archive with restore infos', - objMD: { - 'versionId': '2345678', - 'creation-time': now, - 'last-modified': now, - 'originOp': 's3:PutObject', - archive: { - 'restoreRequestedDays': days, - 'restoreRequestedAt': now, - archiveInfo - } }, + objMD: { + 'versionId': '2345678', + 'creation-time': now, + 'last-modified': now, + 'originOp': 's3:PutObject', + archive: { + 'restoreRequestedDays': days, + 'restoreRequestedAt': now, + archiveInfo + } + }, expectedRes: { 'creationTime': now, 'lastModifiedDate': now,