@@ -75,6 +75,8 @@ def _merge_jwt_claims(defaults, overrides):
75
75
return defaults
76
76
77
77
def verify_custom_token (custom_token , expected_claims , tenant_id = None ):
78
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
79
+ pytest .skip ("Not supported with auth emulator" )
78
80
assert isinstance (custom_token , bytes )
79
81
token = google .oauth2 .id_token .verify_token (
80
82
custom_token ,
@@ -230,10 +232,14 @@ def test_invalid_params(self, auth_app, values):
230
232
auth .create_custom_token (user , claims , app = auth_app )
231
233
232
234
def test_noncert_credential (self , user_mgt_app ):
235
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
236
+ pytest .skip ("Not supported with auth emulator" )
233
237
with pytest .raises (ValueError ):
234
238
auth .create_custom_token (MOCK_UID , app = user_mgt_app )
235
239
236
240
def test_sign_with_iam (self ):
241
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
242
+ pytest .skip ("Not supported with auth emulator" )
237
243
options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
238
244
app = firebase_admin .initialize_app (
239
245
testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -248,6 +254,8 @@ def test_sign_with_iam(self):
248
254
firebase_admin .delete_app (app )
249
255
250
256
def test_sign_with_iam_error (self ):
257
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
258
+ pytest .skip ("Not supported with auth emulator" )
251
259
options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
252
260
app = firebase_admin .initialize_app (
253
261
testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -264,6 +272,8 @@ def test_sign_with_iam_error(self):
264
272
firebase_admin .delete_app (app )
265
273
266
274
def test_sign_with_discovered_service_account (self ):
275
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
276
+ pytest .skip ("Not supported with auth emulator" )
267
277
request = testutils .MockRequest (200 , 'discovered-service-account' )
268
278
options = {'projectId' : 'mock-project-id' }
269
279
app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'iam-signer-app' ,
@@ -287,6 +297,8 @@ def test_sign_with_discovered_service_account(self):
287
297
firebase_admin .delete_app (app )
288
298
289
299
def test_sign_with_discovery_failure (self ):
300
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
301
+ pytest .skip ("Not supported with auth emulator" )
290
302
request = testutils .MockFailedRequest (Exception ('test error' ))
291
303
options = {'projectId' : 'mock-project-id' }
292
304
app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'iam-signer-app' ,
@@ -431,6 +443,8 @@ def test_valid_token_check_revoked(self, user_mgt_app, id_token):
431
443
432
444
@pytest .mark .parametrize ('id_token' , valid_tokens .values (), ids = list (valid_tokens ))
433
445
def test_revoked_token_check_revoked (self , user_mgt_app , revoked_tokens , id_token ):
446
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
447
+ pytest .skip ("Not supported with auth emulator" )
434
448
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
435
449
_instrument_user_manager (user_mgt_app , 200 , revoked_tokens )
436
450
with pytest .raises (auth .RevokedIdTokenError ) as excinfo :
@@ -460,13 +474,18 @@ def test_invalid_arg(self, user_mgt_app, id_token):
460
474
461
475
@pytest .mark .parametrize ('id_token' , invalid_tokens .values (), ids = list (invalid_tokens ))
462
476
def test_invalid_token (self , user_mgt_app , id_token ):
477
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
478
+ pytest .skip ("Not supported with auth emulator" )
463
479
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
464
480
with pytest .raises (auth .InvalidIdTokenError ) as excinfo :
465
481
auth .verify_id_token (id_token , app = user_mgt_app )
466
482
assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
467
483
assert excinfo .value .http_response is None
468
484
469
485
def test_expired_token (self , user_mgt_app ):
486
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
487
+ pytest .skip ("Not supported with auth emulator" )
488
+ _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
470
489
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
471
490
id_token = self .invalid_tokens ['ExpiredToken' ]
472
491
with pytest .raises (auth .ExpiredIdTokenError ) as excinfo :
@@ -505,6 +524,8 @@ def test_custom_token(self, auth_app):
505
524
assert str (excinfo .value ) == message
506
525
507
526
def test_certificate_request_failure (self , user_mgt_app ):
527
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
528
+ pytest .skip ("Not supported with auth emulator" )
508
529
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
509
530
with pytest .raises (auth .CertificateFetchError ) as excinfo :
510
531
auth .verify_id_token (TEST_ID_TOKEN , app = user_mgt_app )
@@ -580,13 +601,17 @@ def test_invalid_args(self, user_mgt_app, cookie):
580
601
581
602
@pytest .mark .parametrize ('cookie' , invalid_cookies .values (), ids = list (invalid_cookies ))
582
603
def test_invalid_cookie (self , user_mgt_app , cookie ):
604
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
605
+ pytest .skip ("Not supported with auth emulator" )
583
606
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
584
607
with pytest .raises (auth .InvalidSessionCookieError ) as excinfo :
585
608
auth .verify_session_cookie (cookie , app = user_mgt_app )
586
609
assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
587
610
assert excinfo .value .http_response is None
588
611
589
612
def test_expired_cookie (self , user_mgt_app ):
613
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
614
+ pytest .skip ("Not supported with auth emulator" )
590
615
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
591
616
cookie = self .invalid_cookies ['ExpiredCookie' ]
592
617
with pytest .raises (auth .ExpiredSessionCookieError ) as excinfo :
@@ -620,6 +645,8 @@ def test_custom_token(self, auth_app):
620
645
auth .verify_session_cookie (custom_token , app = auth_app )
621
646
622
647
def test_certificate_request_failure (self , user_mgt_app ):
648
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
649
+ pytest .skip ("Not supported with auth emulator" )
623
650
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
624
651
with pytest .raises (auth .CertificateFetchError ) as excinfo :
625
652
auth .verify_session_cookie (TEST_SESSION_COOKIE , app = user_mgt_app )
@@ -632,6 +659,8 @@ def test_certificate_request_failure(self, user_mgt_app):
632
659
class TestCertificateCaching :
633
660
634
661
def test_certificate_caching (self , user_mgt_app , httpserver ):
662
+ if os .getenv (EMULATOR_HOST_ENV_VAR ):
663
+ pytest .skip ("Not supported with auth emulator" )
635
664
httpserver .serve_content (MOCK_PUBLIC_CERTS , 200 , headers = {'Cache-Control' : 'max-age=3600' })
636
665
verifier = _token_gen .TokenVerifier (user_mgt_app )
637
666
verifier .cookie_verifier .cert_url = httpserver .url
0 commit comments