@@ -30,7 +30,8 @@ import {
30
30
TEST_AUTH_DOMAIN ,
31
31
TEST_KEY ,
32
32
testAuth ,
33
- TestAuth
33
+ TestAuth ,
34
+ FAKE_APP_CHECK_CONTROLLER
34
35
} from '../../test/helpers/mock_auth' ;
35
36
import { AuthEventManager } from '../core/auth/auth_event_manager' ;
36
37
import { OAuthProvider } from '../core/providers/oauth' ;
@@ -125,6 +126,48 @@ describe('platform_browser/popup_redirect', () => {
125
126
) ;
126
127
} ) ;
127
128
129
+ it ( 'includes the App Check token in the url fragment if present' , async ( ) => {
130
+ await resolver . _initialize ( auth ) ;
131
+ sinon
132
+ . stub ( FAKE_APP_CHECK_CONTROLLER , 'getToken' )
133
+ . returns ( Promise . resolve ( { token : 'fake-token' } ) ) ;
134
+
135
+ await resolver . _openPopup ( auth , provider , event ) ;
136
+
137
+ const matches = ( popupUrl as string ) . match ( / .* ?# ( .* ) / ) ;
138
+ expect ( matches ) . not . to . be . null ;
139
+ const fragment = matches ! [ 1 ] ;
140
+ expect ( fragment ) . to . include ( 'fac=fake-token' ) ;
141
+ } ) ;
142
+
143
+ it ( 'does not add the App Check token in the url fragment if none returned' , async ( ) => {
144
+ await resolver . _initialize ( auth ) ;
145
+ sinon
146
+ . stub ( FAKE_APP_CHECK_CONTROLLER , 'getToken' )
147
+ . returns ( Promise . resolve ( { token : '' } ) ) ;
148
+
149
+ await resolver . _openPopup ( auth , provider , event ) ;
150
+
151
+ const matches = ( popupUrl as string ) . match ( / .* ?# ( .* ) / ) ;
152
+ expect ( matches ) . not . to . be . null ;
153
+ const fragment = matches ! [ 1 ] ;
154
+ expect ( fragment ) . not . to . include ( 'fac' ) ;
155
+ } ) ;
156
+
157
+ it ( 'does not add the App Check token in the url fragment if controller unavailable' , async ( ) => {
158
+ await resolver . _initialize ( auth ) ;
159
+ sinon
160
+ . stub ( FAKE_APP_CHECK_CONTROLLER , 'getToken' )
161
+ . returns ( undefined as any ) ;
162
+
163
+ await resolver . _openPopup ( auth , provider , event ) ;
164
+
165
+ const matches = ( popupUrl as string ) . match ( / .* ?# ( .* ) / ) ;
166
+ expect ( matches ) . not . to . be . null ;
167
+ const fragment = matches ! [ 1 ] ;
168
+ expect ( fragment ) . not . to . include ( 'fac' ) ;
169
+ } ) ;
170
+
128
171
it ( 'throws an error if apiKey is unspecified' , async ( ) => {
129
172
delete ( auth . config as Partial < Config > ) . apiKey ;
130
173
await resolver . _initialize ( auth ) ;
@@ -157,8 +200,10 @@ describe('platform_browser/popup_redirect', () => {
157
200
// eslint-disable-next-line @typescript-eslint/no-floating-promises
158
201
resolver . _openRedirect ( auth , provider , event ) ;
159
202
160
- // Delay one tick
161
- await Promise . resolve ( ) ;
203
+ // Wait a bit so the _openRedirect() call completes
204
+ await new Promise ( ( resolve ) : void => {
205
+ setTimeout ( resolve , 100 ) ;
206
+ } ) ;
162
207
163
208
expect ( newWindowLocation ) . to . include (
164
209
`https://${ TEST_AUTH_DOMAIN } /__/auth/handler`
@@ -177,6 +222,66 @@ describe('platform_browser/popup_redirect', () => {
177
222
) ;
178
223
} ) ;
179
224
225
+ it ( 'includes the App Check token in the url fragment if present' , async ( ) => {
226
+ sinon
227
+ . stub ( FAKE_APP_CHECK_CONTROLLER , 'getToken' )
228
+ . returns ( Promise . resolve ( { token : 'fake-token' } ) ) ;
229
+
230
+ // This promise will never resolve on purpose
231
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
232
+ resolver . _openRedirect ( auth , provider , event ) ;
233
+
234
+ // Wait a bit so the _openRedirect() call completes
235
+ await new Promise ( ( resolve ) : void => {
236
+ setTimeout ( resolve , 100 ) ;
237
+ } ) ;
238
+
239
+ const matches = newWindowLocation . match ( / .* ?# ( .* ) / ) ;
240
+ expect ( matches ) . not . to . be . null ;
241
+ const fragment = matches ! [ 1 ] ;
242
+ expect ( fragment ) . to . include ( 'fac=fake-token' ) ;
243
+ } ) ;
244
+
245
+ it ( 'does not add the App Check token in the url fragment if none returned' , async ( ) => {
246
+ sinon
247
+ . stub ( FAKE_APP_CHECK_CONTROLLER , 'getToken' )
248
+ . returns ( Promise . resolve ( { token : '' } ) ) ;
249
+
250
+ // This promise will never resolve on purpose
251
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
252
+ resolver . _openRedirect ( auth , provider , event ) ;
253
+
254
+ // Wait a bit so the _openRedirect() call completes
255
+ await new Promise ( ( resolve ) : void => {
256
+ setTimeout ( resolve , 100 ) ;
257
+ } ) ;
258
+
259
+ const matches = newWindowLocation . match ( / .* ?# ( .* ) / ) ;
260
+ expect ( matches ) . not . to . be . null ;
261
+ const fragment = matches ! [ 1 ] ;
262
+ expect ( fragment ) . not . to . include ( 'fac' ) ;
263
+ } ) ;
264
+
265
+ it ( 'does not add the App Check token in the url fragment if controller unavailable' , async ( ) => {
266
+ sinon
267
+ . stub ( FAKE_APP_CHECK_CONTROLLER , 'getToken' )
268
+ . returns ( undefined as any ) ;
269
+
270
+ // This promise will never resolve on purpose
271
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
272
+ resolver . _openRedirect ( auth , provider , event ) ;
273
+
274
+ // Wait a bit so the _openRedirect() call completes
275
+ await new Promise ( ( resolve ) : void => {
276
+ setTimeout ( resolve , 100 ) ;
277
+ } ) ;
278
+
279
+ const matches = newWindowLocation . match ( / .* ?# ( .* ) / ) ;
280
+ expect ( matches ) . not . to . be . null ;
281
+ const fragment = matches ! [ 1 ] ;
282
+ expect ( fragment ) . not . to . include ( 'fac' ) ;
283
+ } ) ;
284
+
180
285
it ( 'throws an error if authDomain is unspecified' , async ( ) => {
181
286
delete auth . config . authDomain ;
182
287
0 commit comments