@@ -220,6 +220,64 @@ describe('routeBackbeat', () => {
220220 assert . deepStrictEqual ( mockResponse . body , { } ) ;
221221 } ) ;
222222
223+ it ( 'should put metadata after updating account info' , async ( ) => {
224+ mockRequest . method = 'PUT' ;
225+ mockRequest . url = '/_/backbeat/metadata/bucket0/key0' +
226+ '?accountId=123456789012&versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf' ;
227+ mockRequest . headers = {
228+ 'x-scal-versioning-required' : 'true' ,
229+ } ;
230+ mockRequest . destroy = ( ) => { } ;
231+
232+ sandbox . stub ( metadata , 'putObjectMD' ) . callsFake ( ( bucketName , objectKey , omVal , options , logParam , cb ) => {
233+ assert . strictEqual ( omVal [ 'owner-display-name' ] , 'Bart' ) ;
234+ assert . strictEqual ( omVal [ 'owner-id' ] , '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be' ) ;
235+ cb ( null , { } ) ;
236+ } ) ;
237+
238+ metadataUtils . standardMetadataValidateBucketAndObj . callsFake ( ( params , denies , log , callback ) => {
239+ const bucketInfo = {
240+ getVersioningConfiguration : ( ) => ( { Status : 'Enabled' } ) ,
241+ isVersioningEnabled : ( ) => true ,
242+ } ;
243+ const objMd = { } ;
244+ callback ( null , bucketInfo , objMd ) ;
245+ } ) ;
246+
247+ routeBackbeat ( '127.0.0.1' , mockRequest , mockResponse , log ) ;
248+
249+ void await endPromise ;
250+
251+ assert . strictEqual ( mockResponse . statusCode , 200 ) ;
252+ assert . deepStrictEqual ( mockResponse . body , { } ) ;
253+ } ) ;
254+
255+ it ( 'should fail to put metadata when accountId is invalid' , async ( ) => {
256+ mockRequest . method = 'PUT' ;
257+ mockRequest . url = '/_/backbeat/metadata/bucket0/key0' +
258+ '?accountId=invalid&versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf' ;
259+ mockRequest . headers = {
260+ 'x-scal-versioning-required' : 'true' ,
261+ } ;
262+ mockRequest . destroy = ( ) => { } ;
263+
264+ metadataUtils . standardMetadataValidateBucketAndObj . callsFake ( ( params , denies , log , callback ) => {
265+ const bucketInfo = {
266+ getVersioningConfiguration : ( ) => ( { Status : 'Enabled' } ) ,
267+ isVersioningEnabled : ( ) => true ,
268+ } ;
269+ const objMd = { } ;
270+ callback ( null , bucketInfo , objMd ) ;
271+ } ) ;
272+
273+ routeBackbeat ( '127.0.0.1' , mockRequest , mockResponse , log ) ;
274+
275+ void await endPromise ;
276+
277+ assert . strictEqual ( mockResponse . statusCode , 404 ) ;
278+ assert . deepStrictEqual ( mockResponse . body . code , 'AccountNotFound' ) ;
279+ } ) ;
280+
223281 it ( 'should handle error when putting metadata' , async ( ) => {
224282 mockRequest . method = 'PUT' ;
225283 mockRequest . url = '/_/backbeat/metadata/bucket0/key0' ;
0 commit comments