Skip to content

Commit 504cde3

Browse files
committed
✅ add a new test for the versioningPreprocess
Issue: CLDSRV-632
1 parent 8e47a3c commit 504cde3

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

lib/routes/routeBackbeat.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
668668
});
669669
},
670670
async () => {
671+
// If we create a new version of an object (so objMd is null),
672+
// we should make sure that the masterVersion is versionned.
673+
// If an object already exists, we just want to update the metadata
674+
// of the existing object and not create a new one
671675
if (versioning && !objMd) {
672676
let masterMD;
673677

tests/unit/routes/routeBackbeat.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const { auth, errors } = require('arsenal');
1414
const AuthInfo = auth.AuthInfo;
1515
const { config } = require('../../../lib/Config');
1616
const quotaUtils = require('../../../lib/api/apiUtils/quotas/quotaUtils');
17+
const versioningUtils = require('../../../lib/api/apiUtils/object/versioning');
1718
const { bucketPut } = require('../../../lib/api/bucketPut');
1819
const bucketDelete = require('../../../lib/api/bucketDelete');
1920
const bucketPutVersioning = require('../../../lib/api/bucketPutVersioning');
@@ -559,6 +560,67 @@ describe('routeBackbeat', () => {
559560
assert.deepStrictEqual(mockResponse.body, {});
560561
assert.strictEqual(dataDeleteSpy.called, false);
561562
});
563+
564+
it('should transform a non-versioned object to a versioned' +
565+
' one and create a new object if the bucket is versioned', async () => {
566+
const bucketInfo = {
567+
getVersioningConfiguration: () => ({ Status: 'Enabled' }),
568+
isVersioningEnabled: () => true,
569+
};
570+
const notFoundObject = undefined;
571+
const nonVersionedObject = {
572+
'content-length': 100,
573+
};
574+
575+
const metadataGetObjectMDPromisedStub = sandbox.stub(metadata, 'getObjectMDPromised');
576+
metadataGetObjectMDPromisedStub.callsFake((bucketName, objectKey, options, log) => Promise.resolve({
577+
data: nonVersionedObject,
578+
}));
579+
const metadataPutObjectMDStub = sandbox.stub(metadata, 'putObjectMD')
580+
.callsFake((bucketName, objectKey, omVal, options, logParam, cb) => {
581+
cb(null, {});
582+
});
583+
584+
mockRequest = prepareDummyRequest();
585+
mockRequest.method = 'PUT';
586+
mockRequest.url = '/_/backbeat/metadata/bucket0/key0';
587+
588+
metadataUtils.standardMetadataValidateBucketAndObj.callsFake((params, denies, log, callback) => {
589+
callback(null, bucketInfo, notFoundObject);
590+
});
591+
592+
routeBackbeat('127.0.0.1', mockRequest, mockResponse, log);
593+
await endPromise;
594+
595+
sinon.assert.calledOnce(metadataGetObjectMDPromisedStub);
596+
sinon.assert.calledTwice(metadataPutObjectMDStub);
597+
sinon.assert.calledWith(
598+
metadataPutObjectMDStub.firstCall,// Transform the non versioned object to a versioned one
599+
'bucket0',
600+
'key0',
601+
sinon.match({
602+
data: nonVersionedObject,
603+
versionId: '99999999999999999999RG001 ',
604+
isNull: true,
605+
isNull2: true
606+
}),
607+
sinon.match({ versionId: 'null' }),
608+
log,
609+
);
610+
sinon.assert.calledWith(
611+
metadataPutObjectMDStub.secondCall, // Create the new object
612+
'bucket0',
613+
'key0',
614+
sinon.match({
615+
nullVersionId: '99999999999999999999RG001 ',
616+
}),
617+
sinon.match({ versioning: true, isNull: false }),
618+
log,
619+
);
620+
621+
assert.strictEqual(mockResponse.statusCode, 200);
622+
assert.deepStrictEqual(mockResponse.body, {});
623+
});
562624
});
563625

564626
describe('batchDelete', () => {

0 commit comments

Comments
 (0)