@@ -141,6 +141,12 @@ def _overwrite_iam_request(app, request):
141
141
client = auth ._get_client (app )
142
142
client ._token_generator .request = request
143
143
144
+
145
+ def _is_emulated ():
146
+ emulator_host = os .getenv (EMULATOR_HOST_ENV_VAR , '' )
147
+ return emulator_host and '//' not in emulator_host
148
+
149
+
144
150
@pytest .fixture (scope = 'module' , params = [{'emulated' : False }, {'emulated' : True }])
145
151
def auth_app (request ):
146
152
"""Returns an App initialized with a mock service account credential.
@@ -219,6 +225,8 @@ class TestCreateCustomToken:
219
225
220
226
@pytest .mark .parametrize ('values' , valid_args .values (), ids = list (valid_args ))
221
227
def test_valid_params (self , auth_app , values ):
228
+ if _is_emulated ():
229
+ pytest .skip ("Not supported with auth emulator" )
222
230
user , claims = values
223
231
custom_token = auth .create_custom_token (user , claims , app = auth_app )
224
232
verify_custom_token (custom_token , claims )
@@ -230,10 +238,14 @@ def test_invalid_params(self, auth_app, values):
230
238
auth .create_custom_token (user , claims , app = auth_app )
231
239
232
240
def test_noncert_credential (self , user_mgt_app ):
241
+ if _is_emulated ():
242
+ pytest .skip ("Not supported with auth emulator" )
233
243
with pytest .raises (ValueError ):
234
244
auth .create_custom_token (MOCK_UID , app = user_mgt_app )
235
245
236
246
def test_sign_with_iam (self ):
247
+ if _is_emulated ():
248
+ pytest .skip ("Not supported with auth emulator" )
237
249
options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
238
250
app = firebase_admin .initialize_app (
239
251
testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -248,6 +260,8 @@ def test_sign_with_iam(self):
248
260
firebase_admin .delete_app (app )
249
261
250
262
def test_sign_with_iam_error (self ):
263
+ if _is_emulated ():
264
+ pytest .skip ("Not supported with auth emulator" )
251
265
options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
252
266
app = firebase_admin .initialize_app (
253
267
testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -264,6 +278,8 @@ def test_sign_with_iam_error(self):
264
278
firebase_admin .delete_app (app )
265
279
266
280
def test_sign_with_discovered_service_account (self ):
281
+ if _is_emulated ():
282
+ pytest .skip ("Not supported with auth emulator" )
267
283
request = testutils .MockRequest (200 , 'discovered-service-account' )
268
284
options = {'projectId' : 'mock-project-id' }
269
285
app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'iam-signer-app' ,
@@ -287,6 +303,8 @@ def test_sign_with_discovered_service_account(self):
287
303
firebase_admin .delete_app (app )
288
304
289
305
def test_sign_with_discovery_failure (self ):
306
+ if _is_emulated ():
307
+ pytest .skip ("Not supported with auth emulator" )
290
308
request = testutils .MockFailedRequest (Exception ('test error' ))
291
309
options = {'projectId' : 'mock-project-id' }
292
310
app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'iam-signer-app' ,
@@ -431,6 +449,8 @@ def test_valid_token_check_revoked(self, user_mgt_app, id_token):
431
449
432
450
@pytest .mark .parametrize ('id_token' , valid_tokens .values (), ids = list (valid_tokens ))
433
451
def test_revoked_token_check_revoked (self , user_mgt_app , revoked_tokens , id_token ):
452
+ if _is_emulated ():
453
+ pytest .skip ("Not supported with auth emulator" )
434
454
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
435
455
_instrument_user_manager (user_mgt_app , 200 , revoked_tokens )
436
456
with pytest .raises (auth .RevokedIdTokenError ) as excinfo :
@@ -460,13 +480,18 @@ def test_invalid_arg(self, user_mgt_app, id_token):
460
480
461
481
@pytest .mark .parametrize ('id_token' , invalid_tokens .values (), ids = list (invalid_tokens ))
462
482
def test_invalid_token (self , user_mgt_app , id_token ):
483
+ if _is_emulated ():
484
+ pytest .skip ("Not supported with auth emulator" )
463
485
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
464
486
with pytest .raises (auth .InvalidIdTokenError ) as excinfo :
465
487
auth .verify_id_token (id_token , app = user_mgt_app )
466
488
assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
467
489
assert excinfo .value .http_response is None
468
490
469
491
def test_expired_token (self , user_mgt_app ):
492
+ if _is_emulated ():
493
+ pytest .skip ("Not supported with auth emulator" )
494
+ _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
470
495
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
471
496
id_token = self .invalid_tokens ['ExpiredToken' ]
472
497
with pytest .raises (auth .ExpiredIdTokenError ) as excinfo :
@@ -505,6 +530,8 @@ def test_custom_token(self, auth_app):
505
530
assert str (excinfo .value ) == message
506
531
507
532
def test_certificate_request_failure (self , user_mgt_app ):
533
+ if _is_emulated ():
534
+ pytest .skip ("Not supported with auth emulator" )
508
535
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
509
536
with pytest .raises (auth .CertificateFetchError ) as excinfo :
510
537
auth .verify_id_token (TEST_ID_TOKEN , app = user_mgt_app )
@@ -580,13 +607,17 @@ def test_invalid_args(self, user_mgt_app, cookie):
580
607
581
608
@pytest .mark .parametrize ('cookie' , invalid_cookies .values (), ids = list (invalid_cookies ))
582
609
def test_invalid_cookie (self , user_mgt_app , cookie ):
610
+ if _is_emulated ():
611
+ pytest .skip ("Not supported with auth emulator" )
583
612
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
584
613
with pytest .raises (auth .InvalidSessionCookieError ) as excinfo :
585
614
auth .verify_session_cookie (cookie , app = user_mgt_app )
586
615
assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
587
616
assert excinfo .value .http_response is None
588
617
589
618
def test_expired_cookie (self , user_mgt_app ):
619
+ if _is_emulated ():
620
+ pytest .skip ("Not supported with auth emulator" )
590
621
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
591
622
cookie = self .invalid_cookies ['ExpiredCookie' ]
592
623
with pytest .raises (auth .ExpiredSessionCookieError ) as excinfo :
@@ -620,6 +651,8 @@ def test_custom_token(self, auth_app):
620
651
auth .verify_session_cookie (custom_token , app = auth_app )
621
652
622
653
def test_certificate_request_failure (self , user_mgt_app ):
654
+ if _is_emulated ():
655
+ pytest .skip ("Not supported with auth emulator" )
623
656
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
624
657
with pytest .raises (auth .CertificateFetchError ) as excinfo :
625
658
auth .verify_session_cookie (TEST_SESSION_COOKIE , app = user_mgt_app )
@@ -632,6 +665,8 @@ def test_certificate_request_failure(self, user_mgt_app):
632
665
class TestCertificateCaching :
633
666
634
667
def test_certificate_caching (self , user_mgt_app , httpserver ):
668
+ if _is_emulated ():
669
+ pytest .skip ("Not supported with auth emulator" )
635
670
httpserver .serve_content (MOCK_PUBLIC_CERTS , 200 , headers = {'Cache-Control' : 'max-age=3600' })
636
671
verifier = _token_gen .TokenVerifier (user_mgt_app )
637
672
verifier .cookie_verifier .cert_url = httpserver .url
0 commit comments