@@ -523,8 +523,71 @@ describe('Firebase Functions > Stream', () => {
523523 const [ _ , options ] = mockFetch . firstCall . args ;
524524 expect ( options . headers [ 'Authorization' ] ) . to . equal ( 'Bearer auth-token' ) ;
525525 expect ( options . headers [ 'Content-Type' ] ) . to . equal ( 'application/json' ) ;
526+ expect ( options . credentials ) . to . equal ( undefined ) ;
526527 expect ( options . headers [ 'Accept' ] ) . to . equal ( 'text/event-stream' ) ;
527528 } ) ;
529+ it ( 'calls cloud workstations with credentials' , async ( ) => {
530+ const authMock : FirebaseAuthInternal = {
531+ getToken : async ( ) => ( { accessToken : 'auth-token' } )
532+ } as unknown as FirebaseAuthInternal ;
533+ const authProvider = new Provider < FirebaseAuthInternalName > (
534+ 'auth-internal' ,
535+ new ComponentContainer ( 'test' )
536+ ) ;
537+ authProvider . setComponent (
538+ new Component ( 'auth-internal' , ( ) => authMock , ComponentType . PRIVATE )
539+ ) ;
540+ const appCheckMock : FirebaseAppCheckInternal = {
541+ getToken : async ( ) => ( { token : 'app-check-token' } )
542+ } as unknown as FirebaseAppCheckInternal ;
543+ const appCheckProvider = new Provider < AppCheckInternalComponentName > (
544+ 'app-check-internal' ,
545+ new ComponentContainer ( 'test' )
546+ ) ;
547+ appCheckProvider . setComponent (
548+ new Component (
549+ 'app-check-internal' ,
550+ ( ) => appCheckMock ,
551+ ComponentType . PRIVATE
552+ )
553+ ) ;
554+
555+ const functions = createTestService (
556+ app ,
557+ region ,
558+ authProvider ,
559+ undefined ,
560+ appCheckProvider
561+ ) ;
562+ functions . emulatorOrigin = 'test.cloudworkstations.dev' ;
563+ const mockFetch = sinon . stub ( functions , 'fetchImpl' as any ) ;
564+
565+ const mockResponse = new ReadableStream ( {
566+ start ( controller ) {
567+ controller . enqueue (
568+ new TextEncoder ( ) . encode ( 'data: {"result":"Success"}\n' )
569+ ) ;
570+ controller . close ( ) ;
571+ }
572+ } ) ;
573+
574+ mockFetch . resolves ( {
575+ body : mockResponse ,
576+ headers : new Headers ( { 'Content-Type' : 'text/event-stream' } ) ,
577+ status : 200 ,
578+ statusText : 'OK'
579+ } as Response ) ;
580+
581+ const func = httpsCallable < Record < string , any > , string , string > (
582+ functions ,
583+ 'stream'
584+ ) ;
585+ await func . stream ( { } ) ;
586+
587+ expect ( mockFetch . calledOnce ) . to . be . true ;
588+ const [ _ , options ] = mockFetch . firstCall . args ;
589+ expect ( options . credentials ) . to . equal ( 'include' ) ;
590+ } ) ;
528591
529592 it ( 'aborts during initial fetch' , async ( ) => {
530593 const controller = new AbortController ( ) ;
0 commit comments