|
15 | 15 | """Test cases for the firebase_admin.tenant_mgt module."""
|
16 | 16 |
|
17 | 17 | import json
|
| 18 | +import time |
| 19 | +import datetime |
| 20 | +import unittest.mock |
18 | 21 | from urllib import parse
|
19 | 22 |
|
20 | 23 | import pytest
|
|
29 | 32 | from firebase_admin import _utils
|
30 | 33 | from tests import testutils
|
31 | 34 | from tests import test_token_gen
|
| 35 | +from tests.test_token_gen import MOCK_CURRENT_TIME |
| 36 | +# jwt_helpers will be used in mocker.patch.object, if not, the string path is fine. |
| 37 | +from google.auth.jwt import _helpers as jwt_helpers |
32 | 38 |
|
33 | 39 |
|
34 | 40 | GET_TENANT_RESPONSE = """{
|
@@ -964,6 +970,18 @@ def _assert_saml_provider_config(self, provider_config, want_id='saml.provider')
|
964 | 970 |
|
965 | 971 | class TestVerifyIdToken:
|
966 | 972 |
|
| 973 | + def setup_method(self, method): |
| 974 | + self.time_patch = unittest.mock.patch('time.time', return_value=MOCK_CURRENT_TIME) |
| 975 | + self.mock_time = self.time_patch.start() |
| 976 | + self.utcnow_patch = unittest.mock.patch.object( |
| 977 | + jwt_helpers, 'utcnow', return_value=datetime.datetime.fromtimestamp( |
| 978 | + MOCK_CURRENT_TIME, tz=datetime.timezone.utc)) |
| 979 | + self.mock_utcnow = self.utcnow_patch.start() |
| 980 | + |
| 981 | + def teardown_method(self, method): |
| 982 | + self.time_patch.stop() |
| 983 | + self.utcnow_patch.stop() |
| 984 | + |
967 | 985 | def test_valid_token(self, tenant_mgt_app):
|
968 | 986 | client = tenant_mgt.auth_for_tenant('test-tenant', app=tenant_mgt_app)
|
969 | 987 | client._token_verifier.request = test_token_gen.MOCK_REQUEST
|
@@ -997,6 +1015,18 @@ def tenant_aware_custom_token_app():
|
997 | 1015 |
|
998 | 1016 | class TestCreateCustomToken:
|
999 | 1017 |
|
| 1018 | + def setup_method(self, method): |
| 1019 | + self.time_patch = unittest.mock.patch('time.time', return_value=MOCK_CURRENT_TIME) |
| 1020 | + self.mock_time = self.time_patch.start() |
| 1021 | + self.utcnow_patch = unittest.mock.patch.object( |
| 1022 | + jwt_helpers, 'utcnow', return_value=datetime.datetime.fromtimestamp( |
| 1023 | + MOCK_CURRENT_TIME, tz=datetime.timezone.utc)) |
| 1024 | + self.mock_utcnow = self.utcnow_patch.start() |
| 1025 | + |
| 1026 | + def teardown_method(self, method): |
| 1027 | + self.time_patch.stop() |
| 1028 | + self.utcnow_patch.stop() |
| 1029 | + |
1000 | 1030 | def test_custom_token(self, tenant_aware_custom_token_app):
|
1001 | 1031 | client = tenant_mgt.auth_for_tenant('test-tenant', app=tenant_aware_custom_token_app)
|
1002 | 1032 |
|
|
0 commit comments