@@ -14,6 +14,7 @@ const { auth, errors } = require('arsenal');
1414const AuthInfo = auth . AuthInfo ;
1515const { config } = require ( '../../../lib/Config' ) ;
1616const quotaUtils = require ( '../../../lib/api/apiUtils/quotas/quotaUtils' ) ;
17+ const versioningUtils = require ( '../../../lib/api/apiUtils/object/versioning' ) ;
1718const { bucketPut } = require ( '../../../lib/api/bucketPut' ) ;
1819const bucketDelete = require ( '../../../lib/api/bucketDelete' ) ;
1920const 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