From 8e7f450494c7e64895207bb3271ad83fcc5bae46 Mon Sep 17 00:00:00 2001 From: Cristian Tovar Date: Thu, 20 Jul 2023 14:02:46 -0500 Subject: [PATCH] changes in deleteObject --- .../aws-node-sdk/test/object/deleteObject.js | 363 ++++++------------ tests/locationConfig/locationConfigTests.json | 174 +-------- 2 files changed, 129 insertions(+), 408 deletions(-) diff --git a/tests/functional/aws-node-sdk/test/object/deleteObject.js b/tests/functional/aws-node-sdk/test/object/deleteObject.js index 0c4a0d598c..399d90d439 100644 --- a/tests/functional/aws-node-sdk/test/object/deleteObject.js +++ b/tests/functional/aws-node-sdk/test/object/deleteObject.js @@ -95,169 +95,41 @@ describe('DELETE object', () => { }); }); - describe('with object lock', () => { + describe.only('with object lock', () => { const bucketName = 'testdeleteobjectlockbucket'; let versionIdOne; let versionIdTwo; - const retainDate = moment().add(10, 'days').toISOString(); - before(() => { - process.stdout.write('creating bucket\n'); - return s3.createBucket({ - Bucket: bucketName, - ObjectLockEnabledForBucket: true, - }).promise() - .catch(err => { - process.stdout.write(`Error creating bucket ${err}\n`); - throw err; - }) - .then(() => { - process.stdout.write('putting object\n'); - return s3.putObject({ - Bucket: bucketName, - Key: objectName, - }).promise(); - }) - .catch(err => { - process.stdout.write('Error putting object'); - throw err; - }) - .then(res => { - versionIdOne = res.VersionId; - process.stdout.write('putting object retention\n'); - return s3.putObjectRetention({ - Bucket: bucketName, - Key: objectName, - Retention: { - Mode: 'GOVERNANCE', - RetainUntilDate: retainDate, - }, - }).promise(); - }) - .catch(err => { - process.stdout.write('Err putting object retention\n'); - throw err; - }) - .then(() => { - process.stdout.write('putting object\n'); - return s3.putObject({ - Bucket: bucketName, - Key: objectNameTwo, - }).promise(); - }) - .catch(err => { - process.stdout.write(('Err putting second object\n')); - throw err; - }) - .then(res => { - versionIdTwo = res.VersionId; - process.stdout.write('putting object legal hold\n'); - return s3.putObjectLegalHold({ + [ + { bucketMode: 'GOVERNANCE', ratainDate: moment().add(5, 'days').toISOString(), putObjectLock: false }, + { bucketMode: 'COMPLIANCE', ratainDate: moment().add(5, 'days').toISOString(), putObjectLock: false }, + { bucketMode: 'GOVERNANCE', ratainDate: moment().add(90, 'days').toISOString(), putObjectLock: true }, + { bucketMode: 'COMPLIANCE', ratainDate: moment().add(90, 'days').toISOString(), putObjectLock: true }, + ].forEach((response) => { + before(() => { + process.stdout.write('creating bucket\n'); + return s3.createBucket({ Bucket: bucketName, - Key: objectNameTwo, - LegalHold: { - Status: 'ON', - }, - }).promise(); - }) - .catch(err => { - process.stdout.write('Err putting object legal hold\n'); - throw err; - }); - }); - - after(() => { - process.stdout.write('Emptying bucket\n'); - return bucketUtil.empty(bucketName) - .then(() => { - process.stdout.write('Deleting bucket\n'); - return bucketUtil.deleteOne(bucketName); - }) - .catch(err => { - process.stdout.write('Error in after\n'); - throw err; - }); - }); - - it('should put delete marker if no version id specified', done => { - s3.deleteObject({ - Bucket: bucketName, - Key: objectName, - }, err => { - assert.ifError(err); - done(); - }); - }); - - it('should not delete object version locked with object ' + - 'retention', done => { - s3.deleteObject({ - Bucket: bucketName, - Key: objectName, - VersionId: versionIdOne, - }, err => { - assert.strictEqual(err.code, 'AccessDenied'); - done(); - }); - }); - - it('should delete locked object version with GOVERNANCE ' + - 'retention mode and correct header', done => { - s3.deleteObject({ - Bucket: bucketName, - Key: objectName, - VersionId: versionIdOne, - BypassGovernanceRetention: true, - }, err => { - assert.ifError(err); - done(); - }); - }); - - it('should not delete object locked with legal hold', done => { - s3.deleteObject({ - Bucket: bucketName, - Key: objectNameTwo, - VersionId: versionIdTwo, - }, err => { - assert.strictEqual(err.code, 'AccessDenied'); - changeObjectLock( - [{ - bucket: bucketName, - key: objectNameTwo, - versionId: versionIdTwo, - }], '', done); - }); - }); - }); - - describe('with object lock and legal hold', () => { - const bucketName = 'testdeletelocklegalholdbucket'; - const objectName = 'key'; - let versionId; - before(() => { - process.stdout.write('creating bucket\n'); - return s3.createBucket({ - Bucket: bucketName, - ObjectLockEnabledForBucket: true, - }).promise() + ObjectLockEnabledForBucket: true, + }).promise() .catch(err => { process.stdout.write(`Error creating bucket ${err}\n`); throw err; }) .then(() => { process.stdout.write('putting object lock configuration\n'); - return s3.putObjectLockConfiguration({ - Bucket: bucketName, - ObjectLockConfiguration: { - ObjectLockEnabled: 'Enabled', - Rule: { - DefaultRetention: { - Mode: 'GOVERNANCE', - Days: 1, + return response.putObjectLock ? + s3.putObjectLockConfiguration({ + Bucket: bucketName, + ObjectLockConfiguration: { + ObjectLockEnabled: 'Enabled', + Rule: { + DefaultRetention: { + Mode: response.bucketMode, + Days: parseInt(response.ratainDate, 0), + }, }, }, - }, - }).promise(); + }).promise() : true; }) .catch(err => { process.stdout.write('Error putting object lock configuration\n'); @@ -275,11 +147,40 @@ describe('DELETE object', () => { throw err; }) .then(res => { - versionId = res.VersionId; + versionIdOne = res.VersionId; + process.stdout.write('putting object retention\n'); + return !response.putObjectLock ? + s3.putObjectRetention({ + Bucket: bucketName, + Key: objectName, + Retention: { + Mode: response.bucketMode, + RetainUntilDate: response.ratainDate, + }, + }).promise() + : true; + }) + .catch(err => { + process.stdout.write('Err putting object retention\n'); + throw err; + }) + .then(() => { + process.stdout.write('putting object\n'); + return s3.putObject({ + Bucket: bucketName, + Key: objectNameTwo, + }).promise(); + }) + .catch(err => { + process.stdout.write(('Err putting second object\n')); + throw err; + }) + .then(res => { + versionIdTwo = res.VersionId; process.stdout.write('putting object legal hold\n'); return s3.putObjectLegalHold({ Bucket: bucketName, - Key: objectName, + Key: objectNameTwo, LegalHold: { Status: 'ON', }, @@ -289,11 +190,11 @@ describe('DELETE object', () => { process.stdout.write('Err putting object legal hold\n'); throw err; }); - }); + }); - after(() => { - process.stdout.write('Emptying bucket\n'); - return bucketUtil.empty(bucketName) + after(() => { + process.stdout.write('Emptying bucket\n'); + return bucketUtil.empty(bucketName) .then(() => { process.stdout.write('Deleting bucket\n'); return bucketUtil.deleteOne(bucketName); @@ -302,93 +203,85 @@ describe('DELETE object', () => { process.stdout.write('Error in after\n'); throw err; }); - }); + }); - it('should not delete locked object version with GOVERNANCE ' + - 'retention mode and bypass header when object is legal-hold enabled', done => - s3.deleteObject({ - Bucket: bucketName, - Key: objectName, - VersionId: versionId, - BypassGovernanceRetention: true, - }, err => { - assert.strictEqual(err.code, 'AccessDenied'); - changeObjectLock( - [{ - bucket: bucketName, - key: objectName, - versionId, - }], '', done); - } - )); - }); + it('should put delete marker if no version id specified', done => { + s3.deleteObject({ + Bucket: bucketName, + Key: objectName, + }, err => { + assert.ifError(err); + done(); + }); + }); - describe('Try to delete an object version in COMPLIANCE', () => { - const bucketName = 'testdeletelocklegalholdbucket'; - const objectName = 'key'; - let versionId; - before(() => { - return s3.createBucket({ - Bucket: bucketName, - ObjectLockEnabledForBucket: true, - }).promise() - .catch(err => { - process.stdout.write(`Error creating bucket ${err}\n`); - throw err; - }).then(() => { - process.stdout.write('putting object lock configuration\n'); - return s3.putObjectLockConfiguration({ + it('should not delete object version locked with object ' + + 'retention', done => { + s3.deleteObject({ Bucket: bucketName, - ObjectLockConfiguration: { - ObjectLockEnabled: 'Enabled', - Rule: { - DefaultRetention: { - Mode: 'COMPLIANCE', - Days: 1, - }, - }, - }, - }).promise(); - }).catch(err => { - process.stdout.write('Error putting object lock configuration\n'); - throw err; - }).then(() => { - process.stdout.write('putting object\n'); - return s3.putObject({ + Key: objectName, + VersionId: versionIdOne, + }, err => { + assert.strictEqual(err.code, 'AccessDenied'); + done(); + }); + }); + + it(`should delete locked object version with ${response.bucketMode} ` + + 'retention mode and correct header', done => { + s3.deleteObject({ Bucket: bucketName, Key: objectName, - }).promise(); - }) - .catch(err => { - process.stdout.write('Error putting object'); - throw err; - }) - .then(res => { - process.stdout.write('get object versionId\n'); - versionId = res.VersionId; + VersionId: versionIdOne, + BypassGovernanceRetention: true, + }, err => { + assert.ifError(err); + done(); + }); }); - }); - after(() => { - process.stdout.write('Emptying bucket\n'); - return bucketUtil.empty(bucketName) - .then(() => { - process.stdout.write('Deleting bucket\n'); - return bucketUtil.deleteOne(bucketName); - }) - .catch(err => { - process.stdout.write('Error in after\n'); - throw err; + it('should not delete object locked with legal hold', done => { + s3.deleteObject({ + Bucket: bucketName, + Key: objectNameTwo, + VersionId: versionIdTwo, + }, err => { + assert.strictEqual(err.code, 'AccessDenied'); + changeObjectLock( + [{ + bucket: bucketName, + key: objectNameTwo, + versionId: versionIdTwo, + }], '', done); + }); }); - }); - it('delete object in COMPLIANCE mode', () => { - s3.deleteObject({ - Bucket: bucketName, - Key: objectName, - VersionId: versionId, - }, err => { - assert.ifError(err); + it(`should not delete locked object version with ${response.bucketMode} ` + + 'retention mode and bypass header when object is legal-hold enabled', done => + s3.deleteObject({ + Bucket: bucketName, + Key: objectName, + VersionId: versionIdOne, + BypassGovernanceRetention: true, + }, err => { + assert.strictEqual(err.code, 'AccessDenied'); + changeObjectLock( + [{ + bucket: bucketName, + key: objectName, + versionIdOne, + }], '', done); + } + )); + + it(`delete object in ${response.bucketMode} mode`, () => { + s3.deleteObject({ + Bucket: bucketName, + Key: objectName, + VersionId: versionIdOne, + }, err => { + assert.ifError(err); + }); }); }); }); diff --git a/tests/locationConfig/locationConfigTests.json b/tests/locationConfig/locationConfigTests.json index f63266fc20..c445da57b7 100644 --- a/tests/locationConfig/locationConfigTests.json +++ b/tests/locationConfig/locationConfigTests.json @@ -1,3 +1,4 @@ + { "us-east-1": { "type": "file", @@ -23,178 +24,5 @@ "type": "mem", "legacyAwsBehavior": false, "details": {} - }, - "awsbackendencryption": { - "type": "aws_s3", - "legacyAwsBehavior": true, - "details": { - "awsEndpoint": "s3.amazonaws.com", - "bucketName": "multitester555", - "bucketMatch": true, - "credentialsProfile": "default", - "serverSideEncryption": true - } - }, - "awsbackend": { - "type": "aws_s3", - "legacyAwsBehavior": true, - "details": { - "awsEndpoint": "s3.amazonaws.com", - "bucketName": "multitester555", - "bucketMatch": true, - "credentialsProfile": "default" - } - }, - "awsbackendmismatch": { - "type": "aws_s3", - "legacyAwsBehavior": true, - "details": { - "awsEndpoint": "s3.amazonaws.com", - "bucketName": "multitester555", - "bucketMatch": false, - "credentialsProfile": "default" - } - }, - "awsbackend2": { - "type": "aws_s3", - "legacyAwsBehavior": true, - "details": { - "awsEndpoint": "s3.amazonaws.com", - "bucketName": "multitester222", - "bucketMatch": true, - "credentialsProfile": "default_2" - } - }, - "azurebackend": { - "type": "azure", - "legacyAwsBehavior": true, - "details": { - "azureStorageEndpoint": "https://fakeaccountname.blob.core.fake.net/", - "azureStorageAccountName": "fakeaccountname", - "azureStorageAccessKey": "Fake00Key001", - "bucketMatch": true, - "azureContainerName": "s3test" - } - }, - "azurebackend2": { - "type": "azure", - "legacyAwsBehavior": true, - "details": { - "azureStorageEndpoint": "https://fakeaccountname2.blob.core.fake.net/", - "azureStorageAccountName": "fakeaccountname2", - "azureStorageAccessKey": "Fake00Key002", - "bucketMatch": true, - "azureContainerName": "s3test2" - } - }, - "azurebackendmismatch": { - "type": "azure", - "legacyAwsBehavior": true, - "details": { - "azureStorageEndpoint": "https://fakeaccountname.blob.core.fake.net/", - "azureStorageAccountName": "fakeaccountname", - "azureStorageAccessKey": "Fake00Key001", - "bucketMatch": false, - "azureContainerName": "s3test" - } - }, - "azurenonexistcontainer": { - "type": "azure", - "legacyAwsBehavior": true, - "details": { - "azureStorageEndpoint": "https://fakeaccountname.blob.core.fake.net/", - "azureStorageAccountName": "fakeaccountname", - "azureStorageAccessKey": "Fake00Key123", - "bucketMatch": true, - "azureContainerName": "s3createbucketonfly" - } - }, - "gcpbackend": { - "type": "gcp", - "legacyAwsBehavior": true, - "details": { - "gcpEndpoint": "storage.googleapis.com", - "bucketName": "zenko-gcp-bucket", - "mpuBucketName": "zenko-gcp-mpu", - "overflowBucketName": "zenko-gcp-overflow", - "bucketMatch": true, - "credentialsProfile": "google", - "serviceCredentials": { - "scopes": "https://www.googleapis.com/auth/cloud-platform", - "serviceEmail": "fake001", - "serviceKey": "fake001" - } - } - }, - "gcpbackend2": { - "type": "gcp", - "legacyAwsBehavior": true, - "details": { - "gcpEndpoint": "storage.googleapis.com", - "bucketName": "zenko-gcp-bucket-2", - "mpuBucketName": "zenko-gcp-mpu-2", - "overflowBucketName": "zenko-gcp-overflow", - "bucketMatch": true, - "credentialsProfile": "google_2", - "serviceCredentials": { - "scopes": "https://www.googleapis.com/auth/cloud-platform", - "serviceEmail": "fake002", - "serviceKey": "fake002" - } - } - }, - "gcpbackendmismatch": { - "type": "gcp", - "legacyAwsBehavior": true, - "details": { - "gcpEndpoint": "storage.googleapis.com", - "bucketName": "zenko-gcp-bucket", - "mpuBucketName": "zenko-gcp-mpu", - "overflowBucketName": "zenko-gcp-overflow", - "bucketMatch": false, - "credentialsProfile": "google", - "serviceCredentials": { - "scopes": "https://www.googleapis.com/auth/cloud-platform", - "serviceEmail": "fake001", - "serviceKey": "fake001" - } - } - }, - "gcpbackendproxy": { - "type": "gcp", - "legacyAwsBehavior": true, - "details": { - "proxy": "https://proxy.server", - "https": true, - "gcpEndpoint": "storage.googleapis.com", - "bucketName": "zenko-gcp-bucket", - "mpuBucketName": "zenko-gcp-mpu", - "overflowBucketName": "zenko-gcp-overflow", - "bucketMatch": false, - "credentialsProfile": "google", - "serviceCredentials": { - "scopes": "https://www.googleapis.com/auth/cloud-platform", - "serviceEmail": "fake001", - "serviceKey": "fake001" - } - } - }, - "gcpbackendnoproxy": { - "type": "gcp", - "legacyAwsBehavior": true, - "details": { - "https": false, - "gcpEndpoint": "storage.googleapis.com", - "bucketName": "zenko-gcp-bucket", - "mpuBucketName": "zenko-gcp-mpu", - "overflowBucketName": "zenko-gcp-overflow", - "bucketMatch": false, - "credentialsProfile": "google", - "serviceCredentials": { - "scopes": "https://www.googleapis.com/auth/cloud-platform", - "serviceEmail": "fake001", - "serviceKey": "fake001" - } - } } } \ No newline at end of file