diff --git a/lib/routes/routeBackbeat.js b/lib/routes/routeBackbeat.js index 7f86524f8e..11d5d4c1db 100644 --- a/lib/routes/routeBackbeat.js +++ b/lib/routes/routeBackbeat.js @@ -509,6 +509,7 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { // Retrieve the null version id from the object metadata. versionId = objMd && objMd.versionId; if (!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. @@ -528,7 +529,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; } } } 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 2911dfdcce..eede136437 100644 --- a/tests/functional/aws-node-sdk/lib/utility/bucket-util.js +++ b/tests/functional/aws-node-sdk/lib/utility/bucket-util.js @@ -16,6 +16,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() @@ -123,6 +135,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/multipleBackend/routes/routeBackbeat.js b/tests/multipleBackend/routes/routeBackbeat.js index fa5ef1f745..5e2bdcd70a 100644 --- a/tests/multipleBackend/routes/routeBackbeat.js +++ b/tests/multipleBackend/routes/routeBackbeat.js @@ -261,7 +261,8 @@ describe('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, @@ -293,15 +294,16 @@ describe('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(() => bucketUtil.empty(NONVERSIONED_BUCKET)) .then(() => s3.deleteBucket({ Bucket: NONVERSIONED_BUCKET }).promise()) - .then(() => done()); - }); + .then(() => done(), err => done(err)) + ); describe('null version', () => { const bucket = BUCKET_FOR_NULL_VERSION; @@ -322,12 +324,17 @@ describe('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;