@@ -303,9 +303,7 @@ describe('session cookie extraction', () => {
303303 expect ( extractCookie ( event ) ) . toBeUndefined ( )
304304 } )
305305
306- // @TODO : Disabled Studio Auth Implementation
307- // we need to avoid using body instead of headers
308- it . skip ( 'extracts GraphiQL cookie from the header extensions' , ( ) => {
306+ it ( 'extracts GraphiQL cookie from the body extensions' , ( ) => {
309307 const dbUserId = 42
310308
311309 const cookie = encryptToCookie ( JSON . stringify ( { id : dbUserId } ) )
@@ -322,33 +320,46 @@ describe('session cookie extraction', () => {
322320 expect ( extractCookie ( event ) ) . toEqual ( cookie )
323321 } )
324322
325- // @TODO : Disabled Studio Auth Implementation
326- // we need to avoid using body instead of headers
327- it . skip ( 'overwrites cookie with event header GraphiQL when in dev' , ( ) => {
328- const sessionCookie = encryptToCookie (
329- JSON . stringify ( { id : 9999999999 } ) + ';' + 'token'
323+ it ( 'extracts GraphiQL cookie from the rw-studio header (Fetch request)' , ( ) => {
324+ const dbUserId = 42
325+
326+ const impersonatedCookie = encryptToCookie (
327+ JSON . stringify ( { id : dbUserId } )
330328 )
331329
332- event = {
330+ const req = new Request ( 'http://localhost:8910/_rw_mw' , {
331+ method : 'POST' ,
333332 headers : {
334- cookie : sessionCookie ,
333+ 'auth-provider' : 'dbAuth' ,
334+ 'rw-studio-impersonation-cookie' : impersonatedCookie ,
335+ authorization : 'Bearer ' + dbUserId ,
335336 } ,
336- }
337+ } )
338+
339+ expect ( extractCookie ( req ) ) . toEqual ( impersonatedCookie )
340+ } )
341+
342+ it ( 'impersonation cookie takes precendence' , ( ) => {
343+ const sessionCookie = encryptToCookie (
344+ JSON . stringify ( { id : 9999999999 } ) + ';' + 'token'
345+ )
337346
338347 const dbUserId = 42
339348
340- const cookie = encryptToCookie ( JSON . stringify ( { id : dbUserId } ) )
341- event . body = JSON . stringify ( {
342- extensions : {
343- headers : {
344- 'auth-provider' : 'dbAuth' ,
345- cookie,
346- authorization : 'Bearer ' + dbUserId ,
347- } ,
349+ const impersonatedCookie = encryptToCookie (
350+ JSON . stringify ( { id : dbUserId } )
351+ )
352+
353+ event = {
354+ headers : {
355+ cookie : sessionCookie , // This user doesn't exist
356+ 'auth-provider' : 'dbAuth' ,
357+ 'rw-studio-impersonation-cookie' : impersonatedCookie ,
358+ authorization : 'Bearer ' + dbUserId ,
348359 } ,
349- } )
360+ }
350361
351- expect ( extractCookie ( event ) ) . toEqual ( cookie )
362+ expect ( extractCookie ( event ) ) . toEqual ( impersonatedCookie )
352363 } )
353364 } )
354365} )
0 commit comments