From 656ef3fcee757ecbf9c86ac5c8dfa23ad53fd1c0 Mon Sep 17 00:00:00 2001 From: Taylor McKinnon Date: Wed, 16 Aug 2023 14:22:43 -0700 Subject: [PATCH 1/2] bf(CLDSRV-413): improve backbeat route testing setup cleanup --- .../aws-node-sdk/lib/utility/bucket-util.js | 30 +++++++++++++++++++ .../raw-node/test/routes/routeBackbeat.js | 23 +++++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/tests/functional/aws-node-sdk/lib/utility/bucket-util.js b/tests/functional/aws-node-sdk/lib/utility/bucket-util.js index 0f4ba4a117..c5ae7952a7 100644 --- a/tests/functional/aws-node-sdk/lib/utility/bucket-util.js +++ b/tests/functional/aws-node-sdk/lib/utility/bucket-util.js @@ -14,6 +14,18 @@ class BucketUtility { }); } + bucketExists(bucketName) { + return this.s3 + .headBucket({ Bucket: bucketName }).promise() + .then(() => true) + .catch(err => { + if (err.code === 'NotFound') { + return false; + } + throw err; + }); + } + createOne(bucketName) { return this.s3 .createBucket({ Bucket: bucketName }).promise() @@ -121,6 +133,24 @@ class BucketUtility { return Promise.all(promises); } + emptyIfExists(bucketName) { + return this.bucketExists(bucketName) + .then(exists => { + if (exists) { + return this.empty(bucketName); + } + return undefined; + }); + } + + emptyManyIfExists(bucketNames) { + const promises = bucketNames.map( + bucketName => this.emptyIfExists(bucketName) + ); + + return Promise.all(promises); + } + getOwner() { return this.s3 .listBuckets().promise() diff --git a/tests/functional/raw-node/test/routes/routeBackbeat.js b/tests/functional/raw-node/test/routes/routeBackbeat.js index 3133c98eed..ec183ec24a 100644 --- a/tests/functional/raw-node/test/routes/routeBackbeat.js +++ b/tests/functional/raw-node/test/routes/routeBackbeat.js @@ -156,7 +156,8 @@ describeSkipIfAWS('backbeat routes', () => { bucketUtil = new BucketUtility( 'default', { signatureVersion: 'v4' }); s3 = bucketUtil.s3; - s3.createBucket({ Bucket: TEST_BUCKET }).promise() + bucketUtil.emptyManyIfExists([TEST_BUCKET, TEST_ENCRYPTED_BUCKET, NONVERSIONED_BUCKET]) + .then(() => s3.createBucket({ Bucket: TEST_BUCKET }).promise()) .then(() => s3.putBucketVersioning( { Bucket: TEST_BUCKET, @@ -190,15 +191,16 @@ describeSkipIfAWS('backbeat routes', () => { throw err; }); }); - after(done => { + + after(done => bucketUtil.empty(TEST_BUCKET) .then(() => s3.deleteBucket({ Bucket: TEST_BUCKET }).promise()) .then(() => bucketUtil.empty(TEST_ENCRYPTED_BUCKET)) .then(() => s3.deleteBucket({ Bucket: TEST_ENCRYPTED_BUCKET }).promise()) .then(() => s3.deleteBucket({ Bucket: NONVERSIONED_BUCKET }).promise()) - .then(() => done()); - }); + .then(() => done(), err => done(err)) + ); describe('null version', () => { const bucket = BUCKET_FOR_NULL_VERSION; @@ -219,12 +221,17 @@ describeSkipIfAWS('backbeat routes', () => { assert.strictEqual(StorageClass, 'STANDARD'); } - beforeEach(done => s3.createBucket({ Bucket: BUCKET_FOR_NULL_VERSION }, done)); - afterEach(done => { + beforeEach(done => + bucketUtil.emptyIfExists(BUCKET_FOR_NULL_VERSION) + .then(() => s3.createBucket({ Bucket: BUCKET_FOR_NULL_VERSION }).promise()) + .then(() => done(), err => done(err)) + ); + + afterEach(done => bucketUtil.empty(BUCKET_FOR_NULL_VERSION) .then(() => s3.deleteBucket({ Bucket: BUCKET_FOR_NULL_VERSION }).promise()) - .then(() => done()); - }); + .then(() => done(), err => done(err)) + ); it('should update metadata of a current null version', done => { let objMD; From 292604873598baf1468524ae7dcf1f55d01f4b67 Mon Sep 17 00:00:00 2001 From: Taylor McKinnon Date: Wed, 16 Aug 2023 14:24:07 -0700 Subject: [PATCH 2/2] bf(CLDSRV-413): Set isNull in objectMD fin backbeat putMetadata route for current null versions --- lib/routes/routeBackbeat.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/routes/routeBackbeat.js b/lib/routes/routeBackbeat.js index 565d12e31a..990a5d14c9 100644 --- a/lib/routes/routeBackbeat.js +++ b/lib/routes/routeBackbeat.js @@ -482,6 +482,11 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { // Retrieve the null version id from the object metadata. versionId = objMd && objMd.versionId; if (!versionId) { + // Set isNull in the object metadata to be written. + // Since metadata will generate a versionId for the null version, + // the flag is needed to allow cloudserver to know that the version + // is a null version and allow access to it using the "null" versionId. + omVal.isNull = true; if (versioning) { // If the null version does not have a version id, it is a current null version. // To update the metadata of a current version, versioning is set to false. @@ -501,7 +506,6 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { // In such scenarios, we generate a new null version and designate it as the master version. if (versioningConf && versioningConf.Status === 'Suspended') { versionId = ''; - omVal.isNull = true; } } }