@@ -366,3 +366,60 @@ test('Lists site stores', async () => {
366366
367367 expect ( stores ) . toStrictEqual ( [ 'coldplay' , 'phoenix' ] )
368368} )
369+
370+ test ( 'Returns a signed URL or the blob directly based on the request parameters' , async ( ) => {
371+ const siteID = '9a003659-aaaa-0000-aaaa-63d3720d8621'
372+ const token = 'some token'
373+ const value = 'value 1'
374+ const directory = await tmp . dir ( )
375+ const server = new BlobsServer ( {
376+ directory : directory . path ,
377+ token,
378+ } )
379+
380+ const { port } = await server . start ( )
381+ const store = getStore ( {
382+ edgeURL : `http://localhost:${ port } ` ,
383+ name : 'my-store' ,
384+ token,
385+ siteID,
386+ } )
387+
388+ await store . set ( 'key-1' , value )
389+
390+ // When reading through a legacy API endpoint, we should get a signed URL.
391+ const res1 = await fetch ( `http://localhost:${ port } /api/v1/sites/${ siteID } /blobs/key-1?context=site:my-store` , {
392+ headers : {
393+ authorization : `Bearer ${ token } ` ,
394+ } ,
395+ } )
396+ const { url : url1 } = await res1 . json ( )
397+ const data1 = await fetch ( url1 )
398+
399+ expect ( await data1 . text ( ) ) . toBe ( value )
400+
401+ // When reading through a new API endpoint, we should get the blob data by
402+ // default.
403+ const res2 = await fetch ( `http://localhost:${ port } /api/v1/blobs/${ siteID } /site:my-store/key-1` , {
404+ headers : {
405+ authorization : `Bearer ${ token } ` ,
406+ } ,
407+ } )
408+ expect ( await res2 . text ( ) ) . toBe ( value )
409+
410+ // When reading through a new API endpoint and requesting a signed URL, we
411+ // should get one.
412+ const res3 = await fetch ( `http://localhost:${ port } /api/v1/blobs/${ siteID } /site:my-store/key-1` , {
413+ headers : {
414+ accept : 'application/json;type=signed-url' ,
415+ authorization : `Bearer ${ token } ` ,
416+ } ,
417+ } )
418+ const { url : url3 } = await res3 . json ( )
419+ const data3 = await fetch ( url3 )
420+
421+ expect ( await data3 . text ( ) ) . toBe ( value )
422+
423+ await server . stop ( )
424+ await fs . rm ( directory . path , { force : true , recursive : true } )
425+ } )
0 commit comments