29
29
30
30
import firebase_admin
31
31
from firebase_admin import auth
32
+ from firebase_admin import _auth_utils
32
33
from firebase_admin import credentials
33
34
from firebase_admin import exceptions
34
35
from firebase_admin import _token_gen
@@ -219,6 +220,8 @@ class TestCreateCustomToken:
219
220
220
221
@pytest .mark .parametrize ('values' , valid_args .values (), ids = list (valid_args ))
221
222
def test_valid_params (self , auth_app , values ):
223
+ if _auth_utils .is_emulated ():
224
+ pytest .skip ("Not supported with auth emulator" )
222
225
user , claims = values
223
226
custom_token = auth .create_custom_token (user , claims , app = auth_app )
224
227
verify_custom_token (custom_token , claims )
@@ -230,10 +233,14 @@ def test_invalid_params(self, auth_app, values):
230
233
auth .create_custom_token (user , claims , app = auth_app )
231
234
232
235
def test_noncert_credential (self , user_mgt_app ):
236
+ if _auth_utils .is_emulated ():
237
+ pytest .skip ("Not supported with auth emulator" )
233
238
with pytest .raises (ValueError ):
234
239
auth .create_custom_token (MOCK_UID , app = user_mgt_app )
235
240
236
241
def test_sign_with_iam (self ):
242
+ if _auth_utils .is_emulated ():
243
+ pytest .skip ("Not supported with auth emulator" )
237
244
options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
238
245
app = firebase_admin .initialize_app (
239
246
testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -248,6 +255,8 @@ def test_sign_with_iam(self):
248
255
firebase_admin .delete_app (app )
249
256
250
257
def test_sign_with_iam_error (self ):
258
+ if _auth_utils .is_emulated ():
259
+ pytest .skip ("Not supported with auth emulator" )
251
260
options = {'serviceAccountId' : 'test-service-account' , 'projectId' : 'mock-project-id' }
252
261
app = firebase_admin .initialize_app (
253
262
testutils .MockCredential (), name = 'iam-signer-app' , options = options )
@@ -264,6 +273,8 @@ def test_sign_with_iam_error(self):
264
273
firebase_admin .delete_app (app )
265
274
266
275
def test_sign_with_discovered_service_account (self ):
276
+ if _auth_utils .is_emulated ():
277
+ pytest .skip ("Not supported with auth emulator" )
267
278
request = testutils .MockRequest (200 , 'discovered-service-account' )
268
279
options = {'projectId' : 'mock-project-id' }
269
280
app = firebase_admin .initialize_app (testutils .MockCredential (), name = 'iam-signer-app' ,
@@ -287,6 +298,8 @@ def test_sign_with_discovered_service_account(self):
287
298
firebase_admin .delete_app (app )
288
299
289
300
def test_sign_with_discovery_failure (self ):
301
+ if _auth_utils .is_emulated ():
302
+ pytest .skip ("Not supported with auth emulator" )
290
303
request = testutils .MockFailedRequest (Exception ('test error' ))
291
304
options = {'projectId' : 'mock-project-id' }
292
305
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):
431
444
432
445
@pytest .mark .parametrize ('id_token' , valid_tokens .values (), ids = list (valid_tokens ))
433
446
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" )
434
449
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
435
450
_instrument_user_manager (user_mgt_app , 200 , revoked_tokens )
436
451
with pytest .raises (auth .RevokedIdTokenError ) as excinfo :
@@ -460,13 +475,18 @@ def test_invalid_arg(self, user_mgt_app, id_token):
460
475
461
476
@pytest .mark .parametrize ('id_token' , invalid_tokens .values (), ids = list (invalid_tokens ))
462
477
def test_invalid_token (self , user_mgt_app , id_token ):
478
+ if _auth_utils .is_emulated ():
479
+ pytest .skip ("Not supported with auth emulator" )
463
480
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
464
481
with pytest .raises (auth .InvalidIdTokenError ) as excinfo :
465
482
auth .verify_id_token (id_token , app = user_mgt_app )
466
483
assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
467
484
assert excinfo .value .http_response is None
468
485
469
486
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 )
470
490
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
471
491
id_token = self .invalid_tokens ['ExpiredToken' ]
472
492
with pytest .raises (auth .ExpiredIdTokenError ) as excinfo :
@@ -505,6 +525,8 @@ def test_custom_token(self, auth_app):
505
525
assert str (excinfo .value ) == message
506
526
507
527
def test_certificate_request_failure (self , user_mgt_app ):
528
+ if _auth_utils .is_emulated ():
529
+ pytest .skip ("Not supported with auth emulator" )
508
530
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
509
531
with pytest .raises (auth .CertificateFetchError ) as excinfo :
510
532
auth .verify_id_token (TEST_ID_TOKEN , app = user_mgt_app )
@@ -580,13 +602,17 @@ def test_invalid_args(self, user_mgt_app, cookie):
580
602
581
603
@pytest .mark .parametrize ('cookie' , invalid_cookies .values (), ids = list (invalid_cookies ))
582
604
def test_invalid_cookie (self , user_mgt_app , cookie ):
605
+ if _auth_utils .is_emulated ():
606
+ pytest .skip ("Not supported with auth emulator" )
583
607
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
584
608
with pytest .raises (auth .InvalidSessionCookieError ) as excinfo :
585
609
auth .verify_session_cookie (cookie , app = user_mgt_app )
586
610
assert isinstance (excinfo .value , exceptions .InvalidArgumentError )
587
611
assert excinfo .value .http_response is None
588
612
589
613
def test_expired_cookie (self , user_mgt_app ):
614
+ if _auth_utils .is_emulated ():
615
+ pytest .skip ("Not supported with auth emulator" )
590
616
_overwrite_cert_request (user_mgt_app , MOCK_REQUEST )
591
617
cookie = self .invalid_cookies ['ExpiredCookie' ]
592
618
with pytest .raises (auth .ExpiredSessionCookieError ) as excinfo :
@@ -620,6 +646,8 @@ def test_custom_token(self, auth_app):
620
646
auth .verify_session_cookie (custom_token , app = auth_app )
621
647
622
648
def test_certificate_request_failure (self , user_mgt_app ):
649
+ if _auth_utils .is_emulated ():
650
+ pytest .skip ("Not supported with auth emulator" )
623
651
_overwrite_cert_request (user_mgt_app , testutils .MockRequest (404 , 'not found' ))
624
652
with pytest .raises (auth .CertificateFetchError ) as excinfo :
625
653
auth .verify_session_cookie (TEST_SESSION_COOKIE , app = user_mgt_app )
@@ -632,6 +660,8 @@ def test_certificate_request_failure(self, user_mgt_app):
632
660
class TestCertificateCaching :
633
661
634
662
def test_certificate_caching (self , user_mgt_app , httpserver ):
663
+ if _auth_utils .is_emulated ():
664
+ pytest .skip ("Not supported with auth emulator" )
635
665
httpserver .serve_content (MOCK_PUBLIC_CERTS , 200 , headers = {'Cache-Control' : 'max-age=3600' })
636
666
verifier = _token_gen .TokenVerifier (user_mgt_app )
637
667
verifier .cookie_verifier .cert_url = httpserver .url
0 commit comments