Skip to content

Commit

Permalink
Adding functionnal testing and verfication for SSE and website redirect
Browse files Browse the repository at this point in the history
Issue: CLDSRV-408
  • Loading branch information
KillianG committed Jul 5, 2023
1 parent 4cdeeca commit 646c3e2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
20 changes: 15 additions & 5 deletions lib/api/apiUtils/object/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],

Check failure on line 459 in lib/api/apiUtils/object/versioning.js

View workflow job for this annotation

GitHub Actions / linting-coverage

This line has a length of 138. Maximum allowed is 120
}

Check failure on line 460 in lib/api/apiUtils/object/versioning.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Missing semicolon
}

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;
}

Expand Down
5 changes: 5 additions & 0 deletions lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ const services = {
if (lastModifiedDate) {
md.setLastModified(lastModifiedDate);
}

if (!cipherBundle && params.cipherBundle) {
cipherBundle = params.cipherBundle;

Check warning on line 133 in lib/services.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Assignment to function parameter 'cipherBundle'
}

if (cipherBundle) {
md.setAmzServerSideEncryption(cipherBundle.algorithm);
// configuredMasterKeyId takes precedence
Expand Down
25 changes: 25 additions & 0 deletions tests/functional/aws-node-sdk/test/utils/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check warning on line 84 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote

Check warning on line 84 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote
objMD["x-amz-server-side-encryption-aws-kms-key-id"] = "very-secret-key";

Check warning on line 85 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote

Check warning on line 85 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote
objMD['x-amz-website-redirect-location'] = 'https://scality.com/'

Check failure on line 86 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Missing semicolon
objMD.replicationInfo = {
"status" : "PENDING",

Check warning on line 88 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote

Check failure on line 88 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Extra space after key 'status'

Check warning on line 88 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote
"backends" : [

Check warning on line 89 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote

Check failure on line 89 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Extra space after key 'backends'
{
"site" : "azure-normal",

Check warning on line 91 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote

Check failure on line 91 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Extra space after key 'site'

Check warning on line 91 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Strings must use singlequote
"status" : "PENDING",

Check failure on line 92 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Extra space after key 'status'
"dataStoreVersionId" : ""

Check failure on line 93 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Extra space after key 'dataStoreVersionId'
}
],
"content" : [

Check failure on line 96 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Extra space after key 'content'
"DATA",
"METADATA"
],
"destination" : "arn:aws:s3:::versioned",

Check failure on line 100 in tests/functional/aws-node-sdk/test/utils/init.js

View workflow job for this annotation

GitHub Actions / linting-coverage

Extra space after key 'destination'
"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));
Expand Down
21 changes: 11 additions & 10 deletions tests/unit/api/apiUtils/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 646c3e2

Please sign in to comment.