Skip to content

Commit

Permalink
Merge branch 'bugfix/CLDSRV-413/crr_existing_null_version' into tmp/o…
Browse files Browse the repository at this point in the history
…ctopus/w/7.70/bugfix/CLDSRV-413/crr_existing_null_version
  • Loading branch information
bert-e committed Aug 16, 2023
2 parents 8db04f4 + 159e54e commit 3ac767f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,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.
Expand All @@ -503,7 +504,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;
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/functional/aws-node-sdk/lib/utility/bucket-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 15 additions & 8 deletions tests/functional/raw-node/test/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 3ac767f

Please sign in to comment.