2929
3030import firebase_admin
3131from firebase_admin import auth
32+ from firebase_admin import _auth_utils
3233from firebase_admin import credentials
3334from firebase_admin import exceptions
3435from firebase_admin import _token_gen
@@ -219,6 +220,8 @@ class TestCreateCustomToken:
219220
220221 @pytest .mark .parametrize ('values' , valid_args .values (), ids = list (valid_args ))
221222 def test_valid_params (self , auth_app , values ):
223+ if _auth_utils .is_emulated ():
224+ pytest .skip ("Not supported with auth emulator" )
222225 user , claims = values
223226 custom_token = auth .create_custom_token (user , claims , app = auth_app )
224227 verify_custom_token (custom_token , claims )
@@ -230,10 +233,14 @@ def test_invalid_params(self, auth_app, values):
230233 auth .create_custom_token (user , claims , app = auth_app )
231234
232235 def test_noncert_credential (self , user_mgt_app ):
236+ if _auth_utils .is_emulated ():
237+ pytest .skip ("Not supported with auth emulator" )
233238 with pytest .raises (ValueError ):
234239 auth .create_custom_token (MOCK_UID , app = user_mgt_app )
235240
236241 def test_sign_with_iam (self ):
242+ if _auth_utils .is_emulated ():
243+ pytest .skip ("Not supported with auth emulator" )
237244 options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
238245 app = firebase_admin .initialize_app (
239246 testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -248,6 +255,8 @@ def test_sign_with_iam(self):
248255 firebase_admin .delete_app (app )
249256
250257 def test_sign_with_iam_error (self ):
258+ if _auth_utils .is_emulated ():
259+ pytest .skip ("Not supported with auth emulator" )
251260 options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
252261 app = firebase_admin .initialize_app (
253262 testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -264,6 +273,8 @@ def test_sign_with_iam_error(self):
264273 firebase_admin .delete_app (app )
265274
266275 def test_sign_with_discovered_service_account (self ):
276+ if _auth_utils .is_emulated ():
277+ pytest .skip ("Not supported with auth emulator" )
267278 request = testutils .MockRequest (200 , 'discovered-service-account' )
268279 options = {'projectId' : 'mock-project-id' }
269280 app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'iam-signer-app' ,
@@ -287,6 +298,8 @@ def test_sign_with_discovered_service_account(self):
287298 firebase_admin .delete_app (app )
288299
289300 def test_sign_with_discovery_failure (self ):
301+ if _auth_utils .is_emulated ():
302+ pytest .skip ("Not supported with auth emulator" )
290303 request = testutils .MockFailedRequest (Exception ('test error' ))
291304 options = {'projectId' : 'mock-project-id' }
292305 app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'iam-signer-app' ,
@@ -431,6 +444,8 @@ def test_valid_token_check_revoked(self, user_mgt_app, id_token):
431444
432445 @pytest .mark .parametrize ('id_token' , valid_tokens .values (), ids = list (valid_tokens ))
433446 def test_revoked_token_check_revoked (self , user_mgt_app , revoked_tokens , id_token ):
447+ if _auth_utils .is_emulated ():
448+ pytest .skip ("Not supported with auth emulator" )
434449 _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
435450 _instrument_user_manager (user_mgt_app , 200 , revoked_tokens )
436451 with pytest .raises (auth .RevokedIdTokenError ) as excinfo :
@@ -460,13 +475,18 @@ def test_invalid_arg(self, user_mgt_app, id_token):
460475
461476 @pytest .mark .parametrize ('id_token' , invalid_tokens .values (), ids = list (invalid_tokens ))
462477 def test_invalid_token (self , user_mgt_app , id_token ):
478+ if _auth_utils .is_emulated ():
479+ pytest .skip ("Not supported with auth emulator" )
463480 _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
464481 with pytest .raises (auth .InvalidIdTokenError ) as excinfo :
465482 auth .verify_id_token (id_token , app = user_mgt_app )
466483 assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
467484 assert excinfo .value .http_response is None
468485
469486 def test_expired_token (self , user_mgt_app ):
487+ if _auth_utils .is_emulated ():
488+ pytest .skip ("Not supported with auth emulator" )
489+ _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
470490 _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
471491 id_token = self .invalid_tokens ['ExpiredToken' ]
472492 with pytest .raises (auth .ExpiredIdTokenError ) as excinfo :
@@ -505,6 +525,8 @@ def test_custom_token(self, auth_app):
505525 assert str (excinfo .value ) == message
506526
507527 def test_certificate_request_failure (self , user_mgt_app ):
528+ if _auth_utils .is_emulated ():
529+ pytest .skip ("Not supported with auth emulator" )
508530 _overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
509531 with pytest .raises (auth .CertificateFetchError ) as excinfo :
510532 auth .verify_id_token (TEST_ID_TOKEN , app = user_mgt_app )
@@ -580,13 +602,17 @@ def test_invalid_args(self, user_mgt_app, cookie):
580602
581603 @pytest .mark .parametrize ('cookie' , invalid_cookies .values (), ids = list (invalid_cookies ))
582604 def test_invalid_cookie (self , user_mgt_app , cookie ):
605+ if _auth_utils .is_emulated ():
606+ pytest .skip ("Not supported with auth emulator" )
583607 _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
584608 with pytest .raises (auth .InvalidSessionCookieError ) as excinfo :
585609 auth .verify_session_cookie (cookie , app = user_mgt_app )
586610 assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
587611 assert excinfo .value .http_response is None
588612
589613 def test_expired_cookie (self , user_mgt_app ):
614+ if _auth_utils .is_emulated ():
615+ pytest .skip ("Not supported with auth emulator" )
590616 _overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
591617 cookie = self .invalid_cookies ['ExpiredCookie' ]
592618 with pytest .raises (auth .ExpiredSessionCookieError ) as excinfo :
@@ -620,6 +646,8 @@ def test_custom_token(self, auth_app):
620646 auth .verify_session_cookie (custom_token , app = auth_app )
621647
622648 def test_certificate_request_failure (self , user_mgt_app ):
649+ if _auth_utils .is_emulated ():
650+ pytest .skip ("Not supported with auth emulator" )
623651 _overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
624652 with pytest .raises (auth .CertificateFetchError ) as excinfo :
625653 auth .verify_session_cookie (TEST_SESSION_COOKIE , app = user_mgt_app )
@@ -632,6 +660,8 @@ def test_certificate_request_failure(self, user_mgt_app):
632660class TestCertificateCaching :
633661
634662 def test_certificate_caching (self , user_mgt_app , httpserver ):
663+ if _auth_utils .is_emulated ():
664+ pytest .skip ("Not supported with auth emulator" )
635665 httpserver .serve_content (MOCK_PUBLIC_CERTS , 200 , headers = {'Cache-Control' : 'max-age=3600' })
636666 verifier = _token_gen .TokenVerifier (user_mgt_app )
637667 verifier .cookie_verifier .cert_url = httpserver .url
0 commit comments