2424from  firebase_admin  import  exceptions 
2525from  firebase_admin  import  tenant_mgt 
2626from  tests  import  testutils 
27+ from  tests  import  test_token_gen 
2728
2829
2930GET_TENANT_RESPONSE  =  """{ 
@@ -696,7 +697,6 @@ def test_tenant_not_found(self, tenant_mgt_app):
696697        assert  excinfo .value .http_response  is  not None 
697698        assert  excinfo .value .cause  is  not None 
698699
699- 
700700    def  _assert_request (self , recorder , want_url , want_body ):
701701        assert  len (recorder ) ==  1 
702702        req  =  recorder [0 ]
@@ -706,6 +706,31 @@ def _assert_request(self, recorder, want_url, want_body):
706706        assert  body  ==  want_body 
707707
708708
709+ class  TestVerifyIdToken :
710+ 
711+     def  test_valid_token (self , tenant_mgt_app ):
712+         client  =  tenant_mgt .auth_for_tenant ('test-tenant' , app = tenant_mgt_app )
713+         client ._token_verifier .request  =  test_token_gen .MOCK_REQUEST 
714+ 
715+         claims  =  client .verify_id_token (test_token_gen .TEST_ID_TOKEN_WITH_TENANT )
716+ 
717+         assert  claims ['admin' ] is  True 
718+         assert  claims ['uid' ] ==  claims ['sub' ]
719+         assert  claims ['firebase' ]['tenant' ] ==  'test-tenant' 
720+ 
721+     def  test_invalid_tenant_id (self , tenant_mgt_app ):
722+         client  =  tenant_mgt .auth_for_tenant ('other-tenant' , app = tenant_mgt_app )
723+         client ._token_verifier .request  =  test_token_gen .MOCK_REQUEST 
724+ 
725+         with  pytest .raises (tenant_mgt .TenantIdMismatchError ) as  excinfo :
726+             client .verify_id_token (test_token_gen .TEST_ID_TOKEN_WITH_TENANT )
727+ 
728+         assert  'Invalid tenant ID: test-tenant'  in  str (excinfo .value )
729+         assert  isinstance (excinfo .value , exceptions .InvalidArgumentError )
730+         assert  excinfo .value .cause  is  None 
731+         assert  excinfo .value .http_response  is  None 
732+ 
733+ 
709734def  _assert_tenant (tenant , tenant_id = 'tenant-id' ):
710735    assert  isinstance (tenant , tenant_mgt .Tenant )
711736    assert  tenant .tenant_id  ==  tenant_id 
0 commit comments