Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/w/7.70/bugfix/CLDSRV-413/crr_exi…
Browse files Browse the repository at this point in the history
…sting_null_version' into w/8.6/bugfix/CLDSRV-413/crr_existing_null_version
  • Loading branch information
tmacro committed Aug 17, 2023
2 parents de589a0 + cb7609b commit 8f77cd1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,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.
Expand All @@ -527,7 +532,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 @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 15 additions & 8 deletions tests/multipleBackend/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8f77cd1

Please sign in to comment.