diff --git a/integration/test_project_config_mgt.py b/integration/test_project_config_mgt.py index a7ca2c5f1..52b86841e 100644 --- a/integration/test_project_config_mgt.py +++ b/integration/test_project_config_mgt.py @@ -16,8 +16,13 @@ import pytest -from firebase_admin import project_config_mgt -from firebase_admin import multi_factor_config_mgt +from firebase_admin.project_config_mgt import ProjectConfig +from firebase_admin.project_config_mgt import get_project_config +from firebase_admin.project_config_mgt import update_project_config +from firebase_admin.multi_factor_config_mgt import MultiFactorConfig +from firebase_admin.multi_factor_config_mgt import MultiFactorServerConfig +from firebase_admin.multi_factor_config_mgt import ProviderConfig +from firebase_admin.multi_factor_config_mgt import TOTPProviderConfig ADJACENT_INTERVALS = 5 @@ -37,34 +42,34 @@ def sample_mfa_config(): def test_update_project_config(): - mfa_object = multi_factor_config_mgt.MultiFactorConfig( + mfa_object = MultiFactorConfig( provider_configs=[ - multi_factor_config_mgt.ProviderConfig( - state=multi_factor_config_mgt.ProviderConfig.State.ENABLED, - totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig( + ProviderConfig( + state=ProviderConfig.State.ENABLED, + totp_provider_config=TOTPProviderConfig( adjacent_intervals=5 ) ) ] ) - project_config = project_config_mgt.update_project_config(multi_factor_config=mfa_object) + project_config = update_project_config(multi_factor_config=mfa_object) _assert_multi_factor_config(project_config.multi_factor_config) def test_get_project(): - project_config = project_config_mgt.get_project_config() - assert isinstance(project_config, project_config_mgt.ProjectConfig) + project_config = get_project_config() + assert isinstance(project_config, ProjectConfig) _assert_multi_factor_config(project_config.multi_factor_config) def _assert_multi_factor_config(multi_factor_config): - assert isinstance(multi_factor_config, multi_factor_config_mgt.MultiFactorServerConfig) + assert isinstance(multi_factor_config, MultiFactorServerConfig) assert len(multi_factor_config.provider_configs) == 1 assert isinstance(multi_factor_config.provider_configs, list) for provider_config in multi_factor_config.provider_configs: - assert isinstance(provider_config, multi_factor_config_mgt.MultiFactorServerConfig + assert isinstance(provider_config, MultiFactorServerConfig .ProviderServerConfig) assert provider_config.state == 'ENABLED' assert isinstance(provider_config.totp_provider_config, - multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig + MultiFactorServerConfig.ProviderServerConfig .TOTPProviderServerConfig) assert provider_config.totp_provider_config.adjacent_intervals == ADJACENT_INTERVALS diff --git a/tests/test_multi_factor_config.py b/tests/test_multi_factor_config.py index eaf0dcb25..88a6f6652 100644 --- a/tests/test_multi_factor_config.py +++ b/tests/test_multi_factor_config.py @@ -15,12 +15,15 @@ import pytest -from firebase_admin import multi_factor_config_mgt - -sample_mfa_config = multi_factor_config_mgt.MultiFactorConfig( - provider_configs=[multi_factor_config_mgt.ProviderConfig( - state=multi_factor_config_mgt.ProviderConfig.State.ENABLED, - totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig( +from firebase_admin.multi_factor_config_mgt import MultiFactorConfig +from firebase_admin.multi_factor_config_mgt import MultiFactorServerConfig +from firebase_admin.multi_factor_config_mgt import TOTPProviderConfig +from firebase_admin.multi_factor_config_mgt import ProviderConfig + +sample_mfa_config = MultiFactorConfig( + provider_configs=[ProviderConfig( + state=ProviderConfig.State.ENABLED, + totp_provider_config=TOTPProviderConfig( adjacent_intervals=5 ) )] @@ -78,7 +81,7 @@ def test_undefined_provider_config_state(self): @pytest.mark.parametrize('state', ['', 1, True, False, [], (), {}, "foo", 'ENABLED']) def test_invalid_provider_config_state(self, state): - test_config = multi_factor_config_mgt.ProviderConfig( + test_config = ProviderConfig( state=state ) with pytest.raises(ValueError) as excinfo: @@ -87,10 +90,10 @@ def test_invalid_provider_config_state(self, state): ' ProviderConfig.State.') @pytest.mark.parametrize('state', - [multi_factor_config_mgt.ProviderConfig.State.ENABLED, - multi_factor_config_mgt.ProviderConfig.State.DISABLED]) + [ProviderConfig.State.ENABLED, + ProviderConfig.State.DISABLED]) def test_undefined_totp_provider_config(self, state): - test_config = multi_factor_config_mgt.ProviderConfig(state=state) + test_config = ProviderConfig(state=state) with pytest.raises(ValueError) as excinfo: test_config.build_server_request() assert str(excinfo.value).startswith('ProviderConfig.totp_provider_config must be' @@ -134,21 +137,21 @@ class TestMultiFactorServerConfig: def test_invalid_multi_factor_config_response(self): test_config = 'invalid' with pytest.raises(ValueError) as excinfo: - multi_factor_config_mgt.MultiFactorServerConfig(test_config) + MultiFactorServerConfig(test_config) assert str(excinfo.value).startswith('Invalid data argument in MultiFactorServerConfig' ' constructor: {0}'.format(test_config)) def test_invalid_provider_config_response(self): test_config = 'invalid' with pytest.raises(ValueError) as excinfo: - multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig(test_config) + MultiFactorServerConfig.ProviderServerConfig(test_config) assert str(excinfo.value).startswith('Invalid data argument in ProviderServerConfig' ' constructor: {0}'.format(test_config)) def test_invalid_totp_provider_config_response(self): test_config = 'invalid' with pytest.raises(ValueError) as excinfo: - multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig.\ + MultiFactorServerConfig.ProviderServerConfig.\ TOTPProviderServerConfig(test_config) assert str(excinfo.value).startswith('Invalid data argument in TOTPProviderServerConfig' ' constructor: {0}'.format(test_config)) @@ -162,20 +165,20 @@ def test_valid_server_response(self): } }] } - mfa_config = multi_factor_config_mgt.MultiFactorServerConfig(response) + mfa_config = MultiFactorServerConfig(response) _assert_multi_factor_config(mfa_config) def _assert_multi_factor_config(mfa_config): - assert isinstance(mfa_config, multi_factor_config_mgt.MultiFactorServerConfig) + assert isinstance(mfa_config, MultiFactorServerConfig) assert len(mfa_config.provider_configs) == 1 assert isinstance(mfa_config.provider_configs, list) for provider_config in mfa_config.provider_configs: assert isinstance( provider_config, - multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig) + MultiFactorServerConfig.ProviderServerConfig) assert provider_config.state == 'ENABLED' assert isinstance(provider_config.totp_provider_config, - multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig + MultiFactorServerConfig.ProviderServerConfig .TOTPProviderServerConfig) assert provider_config.totp_provider_config.adjacent_intervals == 5 diff --git a/tests/test_tenant_mgt.py b/tests/test_tenant_mgt.py index 1a4a0372a..5e9963fec 100644 --- a/tests/test_tenant_mgt.py +++ b/tests/test_tenant_mgt.py @@ -26,7 +26,10 @@ from firebase_admin import tenant_mgt from firebase_admin import _auth_providers from firebase_admin import _user_mgt -from firebase_admin import multi_factor_config_mgt +from firebase_admin.multi_factor_config_mgt import MultiFactorConfig +from firebase_admin.multi_factor_config_mgt import MultiFactorServerConfig +from firebase_admin.multi_factor_config_mgt import ProviderConfig +from firebase_admin.multi_factor_config_mgt import TOTPProviderConfig from tests import testutils from tests import test_token_gen @@ -257,11 +260,11 @@ def test_invalid_multi_factor_configs(self, multi_factor_config, tenant_mgt_app) def test_create_tenant(self, tenant_mgt_app): _, recorder = _instrument_tenant_mgt(tenant_mgt_app, 200, GET_TENANT_RESPONSE) - mfa_object = multi_factor_config_mgt.MultiFactorConfig( + mfa_object = MultiFactorConfig( provider_configs=[ - multi_factor_config_mgt.ProviderConfig( - state=multi_factor_config_mgt.ProviderConfig.State.ENABLED, - totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig( + ProviderConfig( + state=ProviderConfig.State.ENABLED, + totp_provider_config=TOTPProviderConfig( adjacent_intervals=ADJACENT_INTERVALS ) ) @@ -376,11 +379,11 @@ def test_update_tenant_no_args(self, tenant_mgt_app): def test_update_tenant(self, tenant_mgt_app): _, recorder = _instrument_tenant_mgt(tenant_mgt_app, 200, GET_TENANT_RESPONSE) - mfa_object = multi_factor_config_mgt.MultiFactorConfig( + mfa_object = MultiFactorConfig( provider_configs=[ - multi_factor_config_mgt.ProviderConfig( - state=multi_factor_config_mgt.ProviderConfig.State.ENABLED, - totp_provider_config=multi_factor_config_mgt.TOTPProviderConfig( + ProviderConfig( + state=ProviderConfig.State.ENABLED, + totp_provider_config=TOTPProviderConfig( adjacent_intervals=ADJACENT_INTERVALS ) ) @@ -1065,15 +1068,15 @@ def test_custom_token_with_claims(self, tenant_aware_custom_token_app): custom_token, expected_claims=claims, tenant_id='test-tenant') def _assert_multi_factor_config(mfa_config): - assert isinstance(mfa_config, multi_factor_config_mgt.MultiFactorServerConfig) + assert isinstance(mfa_config, MultiFactorServerConfig) assert len(mfa_config.provider_configs) == 1 assert isinstance(mfa_config.provider_configs, list) for provider_config in mfa_config.provider_configs: - assert isinstance(provider_config, multi_factor_config_mgt.MultiFactorServerConfig.\ + assert isinstance(provider_config, MultiFactorServerConfig.\ ProviderServerConfig) assert provider_config.state == 'ENABLED' assert isinstance(provider_config.totp_provider_config, - multi_factor_config_mgt.MultiFactorServerConfig.ProviderServerConfig + MultiFactorServerConfig.ProviderServerConfig .TOTPProviderServerConfig) assert provider_config.totp_provider_config.adjacent_intervals == ADJACENT_INTERVALS