From ed247ae968da6e68ea559fbe80afd006360c9c43 Mon Sep 17 00:00:00 2001 From: Nicolas Humbert Date: Tue, 11 Jul 2023 16:43:00 -0400 Subject: [PATCH] CLDSRV-412 Test null version in Lifecycle list of non-current versions --- tests/functional/backbeat/listDeleteMarker.js | 208 ++++++++++++++++++ tests/functional/backbeat/listNullVersion.js | 82 +++++++ 2 files changed, 290 insertions(+) create mode 100644 tests/functional/backbeat/listDeleteMarker.js diff --git a/tests/functional/backbeat/listDeleteMarker.js b/tests/functional/backbeat/listDeleteMarker.js new file mode 100644 index 0000000000..2d604c4d8e --- /dev/null +++ b/tests/functional/backbeat/listDeleteMarker.js @@ -0,0 +1,208 @@ +const assert = require('assert'); +const async = require('async'); +const BucketUtility = require('../aws-node-sdk/lib/utility/bucket-util'); +const { removeAllVersions } = require('../aws-node-sdk/lib/utility/versioning-util'); +const { makeBackbeatRequest, runIfMongoV1 } = require('./utils'); + +const credentials = { + accessKey: 'accessKey1', + secretKey: 'verySecretKey1', +}; + +runIfMongoV1('listLifecycle with non-current delete marker', () => { + let bucketUtil; + let s3; + let expectedVersionId; + let expectedDMVersionId; + const testBucket = 'bucket-for-list-lifecycle-noncurrent-dm-tests'; + const keyName = 'key0'; + + before(done => { + bucketUtil = new BucketUtility('account1', { signatureVersion: 'v4' }); + s3 = bucketUtil.s3; + + return async.series([ + next => s3.createBucket({ Bucket: testBucket }, next), + next => s3.putBucketVersioning({ + Bucket: testBucket, + VersioningConfiguration: { Status: 'Enabled' }, + }, next), + next => s3.deleteObject({ Bucket: testBucket, Key: keyName }, (err, data) => { + if (err) { + return next(err); + } + expectedDMVersionId = data.VersionId; + return next(); + }), + next => s3.putObject({ Bucket: testBucket, Key: keyName }, (err, data) => { + if (err) { + return next(err); + } + expectedVersionId = data.VersionId; + return next(); + }), + ], done); + }); + + after(done => async.series([ + next => removeAllVersions({ Bucket: testBucket }, next), + next => s3.deleteBucket({ Bucket: testBucket }, next), + ], done)); + + it('should return the current version', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: testBucket, + queryObj: { 'list-type': 'current' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 1); + const key = data.Contents[0]; + assert.strictEqual(key.Key, keyName); + assert.strictEqual(key.VersionId, expectedVersionId); + return done(); + }); + }); + + it('should return the non-current delete marker', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: testBucket, + queryObj: { 'list-type': 'noncurrent' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 1); + const key = data.Contents[0]; + assert.strictEqual(key.Key, keyName); + assert.strictEqual(key.VersionId, expectedDMVersionId); + return done(); + }); + }); + + it('should return no orphan delete marker', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: testBucket, + queryObj: { 'list-type': 'orphan' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 0); + return done(); + }); + }); +}); + +runIfMongoV1('listLifecycle with current delete marker version', () => { + let bucketUtil; + let s3; + let expectedVersionId; + const testBucket = 'bucket-for-list-lifecycle-current-dm-tests'; + const keyName = 'key0'; + + before(done => { + bucketUtil = new BucketUtility('account1', { signatureVersion: 'v4' }); + s3 = bucketUtil.s3; + + return async.series([ + next => s3.createBucket({ Bucket: testBucket }, next), + next => s3.putBucketVersioning({ + Bucket: testBucket, + VersioningConfiguration: { Status: 'Enabled' }, + }, next), + next => s3.putObject({ Bucket: testBucket, Key: keyName }, (err, data) => { + if (err) { + return next(err); + } + expectedVersionId = data.VersionId; + return next(); + }), + next => s3.deleteObject({ Bucket: testBucket, Key: keyName }, next), + ], done); + }); + + after(done => async.series([ + next => removeAllVersions({ Bucket: testBucket }, next), + next => s3.deleteBucket({ Bucket: testBucket }, next), + ], done)); + + it('should return no current object if current version is a delete marker', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: testBucket, + queryObj: { 'list-type': 'current' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 0); + return done(); + }); + }); + + it('should return the non-current version', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: testBucket, + queryObj: { 'list-type': 'noncurrent' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 1); + const key = data.Contents[0]; + assert.strictEqual(key.Key, keyName); + assert.strictEqual(key.VersionId, expectedVersionId); + return done(); + }); + }); + + it('should return no orphan delete marker', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: testBucket, + queryObj: { 'list-type': 'orphan' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 0); + return done(); + }); + }); +}); diff --git a/tests/functional/backbeat/listNullVersion.js b/tests/functional/backbeat/listNullVersion.js index 8c1d68c1ca..8373222683 100644 --- a/tests/functional/backbeat/listNullVersion.js +++ b/tests/functional/backbeat/listNullVersion.js @@ -102,3 +102,85 @@ runIfMongoV1('listLifecycle if null version', () => { }); }); }); + +runIfMongoV1('listLifecycle with null current version after versioning suspended', () => { + let bucketUtil; + let s3; + let expectedVersionId; + const nullObjectBucket = 'bucket-for-list-lifecycle-current-null-tests'; + const keyName = 'key0'; + + before(done => { + bucketUtil = new BucketUtility('account1', { signatureVersion: 'v4' }); + s3 = bucketUtil.s3; + + return async.series([ + next => s3.createBucket({ Bucket: nullObjectBucket }, next), + next => s3.putBucketVersioning({ + Bucket: nullObjectBucket, + VersioningConfiguration: { Status: 'Enabled' }, + }, next), + next => s3.putObject({ Bucket: nullObjectBucket, Key: keyName }, (err, data) => { + if (err) { + return next(err); + } + expectedVersionId = data.VersionId; + return next(); + }), + next => s3.putBucketVersioning({ + Bucket: nullObjectBucket, + VersioningConfiguration: { Status: 'Suspended' }, + }, next), + next => s3.putObject({ Bucket: nullObjectBucket, Key: keyName }, next), + ], done); + }); + + after(done => async.series([ + next => removeAllVersions({ Bucket: nullObjectBucket }, next), + next => s3.deleteBucket({ Bucket: nullObjectBucket }, next), + ], done)); + + it('should return list of current versions when bucket has a null current version', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: nullObjectBucket, + queryObj: { 'list-type': 'current' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 1); + const key = data.Contents[0]; + assert.strictEqual(key.Key, keyName); + assert.strictEqual(key.VersionId, 'null'); + return done(); + }); + }); + + it('should return list of non-current versions when bucket has a null current version', done => { + makeBackbeatRequest({ + method: 'GET', + bucket: nullObjectBucket, + queryObj: { 'list-type': 'noncurrent' }, + authCredentials: credentials, + }, (err, response) => { + assert.ifError(err); + assert.strictEqual(response.statusCode, 200); + const data = JSON.parse(response.body); + + assert.strictEqual(data.IsTruncated, false); + assert(!data.NextKeyMarker); + assert.strictEqual(data.MaxKeys, 1000); + assert.strictEqual(data.Contents.length, 1); + const key = data.Contents[0]; + assert.strictEqual(key.Key, keyName); + assert.strictEqual(key.VersionId, expectedVersionId); + return done(); + }); + }); +});