@@ -37,7 +37,11 @@ import {
37
37
AppCheckInternalComponentName
38
38
} from '@firebase/app-check-interop-types' ;
39
39
import { makeFakeApp , createTestService } from '../test/utils' ;
40
- import { FunctionsService , httpsCallable } from './service' ;
40
+ import {
41
+ FunctionsService ,
42
+ httpsCallable ,
43
+ httpsCallableFromURL
44
+ } from './service' ;
41
45
import { FUNCTIONS_TYPE } from './constants' ;
42
46
import { FunctionsError } from './error' ;
43
47
@@ -526,6 +530,7 @@ describe('Firebase Functions > Stream', () => {
526
530
expect ( options . credentials ) . to . equal ( undefined ) ;
527
531
expect ( options . headers [ 'Accept' ] ) . to . equal ( 'text/event-stream' ) ;
528
532
} ) ;
533
+
529
534
it ( 'calls cloud workstations with credentials' , async ( ) => {
530
535
const authMock : FirebaseAuthInternal = {
531
536
getToken : async ( ) => ( { accessToken : 'auth-token' } )
@@ -589,6 +594,69 @@ describe('Firebase Functions > Stream', () => {
589
594
expect ( options . credentials ) . to . equal ( 'include' ) ;
590
595
} ) ;
591
596
597
+ it . only ( 'calls streamFromURL cloud workstations with credentials' , async ( ) => {
598
+ const authMock : FirebaseAuthInternal = {
599
+ getToken : async ( ) => ( { accessToken : 'auth-token' } )
600
+ } as unknown as FirebaseAuthInternal ;
601
+ const authProvider = new Provider < FirebaseAuthInternalName > (
602
+ 'auth-internal' ,
603
+ new ComponentContainer ( 'test' )
604
+ ) ;
605
+ authProvider . setComponent (
606
+ new Component ( 'auth-internal' , ( ) => authMock , ComponentType . PRIVATE )
607
+ ) ;
608
+ const appCheckMock : FirebaseAppCheckInternal = {
609
+ getToken : async ( ) => ( { token : 'app-check-token' } )
610
+ } as unknown as FirebaseAppCheckInternal ;
611
+ const appCheckProvider = new Provider < AppCheckInternalComponentName > (
612
+ 'app-check-internal' ,
613
+ new ComponentContainer ( 'test' )
614
+ ) ;
615
+ appCheckProvider . setComponent (
616
+ new Component (
617
+ 'app-check-internal' ,
618
+ ( ) => appCheckMock ,
619
+ ComponentType . PRIVATE
620
+ )
621
+ ) ;
622
+
623
+ const functions = createTestService (
624
+ app ,
625
+ region ,
626
+ authProvider ,
627
+ undefined ,
628
+ appCheckProvider
629
+ ) ;
630
+ functions . emulatorOrigin = 'test.cloudworkstations.dev' ;
631
+ const mockFetch = sinon . stub ( functions , 'fetchImpl' as any ) ;
632
+
633
+ const mockResponse = new ReadableStream ( {
634
+ start ( controller ) {
635
+ controller . enqueue (
636
+ new TextEncoder ( ) . encode ( 'data: {"result":"Success"}\n' )
637
+ ) ;
638
+ controller . close ( ) ;
639
+ }
640
+ } ) ;
641
+
642
+ mockFetch . resolves ( {
643
+ body : mockResponse ,
644
+ headers : new Headers ( { 'Content-Type' : 'text/event-stream' } ) ,
645
+ status : 200 ,
646
+ statusText : 'OK'
647
+ } as Response ) ;
648
+
649
+ const func = httpsCallableFromURL < Record < string , any > , string , string > (
650
+ functions ,
651
+ 'stream'
652
+ ) ;
653
+ await func . stream ( { } ) ;
654
+
655
+ expect ( mockFetch . calledOnce ) . to . be . true ;
656
+ const [ _ , options ] = mockFetch . firstCall . args ;
657
+ expect ( options . credentials ) . to . equal ( 'include' ) ;
658
+ } ) ;
659
+
592
660
it ( 'aborts during initial fetch' , async ( ) => {
593
661
const controller = new AbortController ( ) ;
594
662
0 commit comments