Skip to content

Commit

Permalink
CLDSRV-412 Test null version in Lifecycle list of non-current versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas2bert committed Jul 13, 2023
1 parent c5b1ef6 commit ed247ae
Show file tree
Hide file tree
Showing 2 changed files with 290 additions and 0 deletions.
208 changes: 208 additions & 0 deletions tests/functional/backbeat/listDeleteMarker.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
82 changes: 82 additions & 0 deletions tests/functional/backbeat/listNullVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

0 comments on commit ed247ae

Please sign in to comment.