diff --git a/airflow/providers/fab/auth_manager/fab_auth_manager.py b/airflow/providers/fab/auth_manager/fab_auth_manager.py index b6a1c563ce548..dba6aca7efd5d 100644 --- a/airflow/providers/fab/auth_manager/fab_auth_manager.py +++ b/airflow/providers/fab/auth_manager/fab_auth_manager.py @@ -17,7 +17,6 @@ # under the License. from __future__ import annotations -import warnings from functools import cached_property from pathlib import Path from typing import TYPE_CHECKING, Container @@ -43,7 +42,7 @@ GroupCommand, ) from airflow.configuration import conf -from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning +from airflow.exceptions import AirflowException from airflow.models import DagModel from airflow.providers.fab.auth_manager.cli_commands.definition import ( ROLES_COMMANDS, @@ -334,20 +333,12 @@ def security_manager(self) -> FabAirflowSecurityManagerOverride: from airflow.providers.fab.auth_manager.security_manager.override import ( FabAirflowSecurityManagerOverride, ) - from airflow.www.security_manager import AirflowSecurityManagerV2 sm_from_config = self.appbuilder.get_app.config.get("SECURITY_MANAGER_CLASS") if sm_from_config: - if not issubclass(sm_from_config, AirflowSecurityManagerV2): - raise Exception( - """Your CUSTOM_SECURITY_MANAGER must extend AirflowSecurityManagerV2, - not FAB's own security manager.""" - ) if not issubclass(sm_from_config, FabAirflowSecurityManagerOverride): - warnings.warn( - "Please make your custom security manager inherit from " - "FabAirflowSecurityManagerOverride instead of AirflowSecurityManager.", - AirflowProviderDeprecationWarning, + raise Exception( + """Your CUSTOM_SECURITY_MANAGER must extend FabAirflowSecurityManagerOverride.""" ) return sm_from_config(self.appbuilder) diff --git a/tests/providers/fab/auth_manager/test_fab_auth_manager.py b/tests/providers/fab/auth_manager/test_fab_auth_manager.py index e4c574553656b..72f5a76355f2c 100644 --- a/tests/providers/fab/auth_manager/test_fab_auth_manager.py +++ b/tests/providers/fab/auth_manager/test_fab_auth_manager.py @@ -63,8 +63,12 @@ def auth_manager(): @pytest.fixture -def auth_manager_with_appbuilder(): - flask_app = Flask(__name__) +def flask_app(): + return Flask(__name__) + + +@pytest.fixture +def auth_manager_with_appbuilder(flask_app): appbuilder = init_appbuilder(flask_app) return FabAuthManager(appbuilder) @@ -355,6 +359,28 @@ def test_is_authorized_view(self, access_view, user_permissions, expected_result def test_security_manager_return_fab_security_manager_override(self, auth_manager_with_appbuilder): assert isinstance(auth_manager_with_appbuilder.security_manager, FabAirflowSecurityManagerOverride) + @pytest.mark.db_test + def test_security_manager_return_custom_provided(self, flask_app, auth_manager_with_appbuilder): + class TestSecurityManager(FabAirflowSecurityManagerOverride): + pass + + flask_app.config["SECURITY_MANAGER_CLASS"] = TestSecurityManager + assert isinstance(auth_manager_with_appbuilder.security_manager, TestSecurityManager) + + @pytest.mark.db_test + def test_security_manager_wrong_inheritance_raise_exception( + self, flask_app, auth_manager_with_appbuilder + ): + class TestSecurityManager: + pass + + flask_app.config["SECURITY_MANAGER_CLASS"] = TestSecurityManager + + with pytest.raises( + Exception, match="Your CUSTOM_SECURITY_MANAGER must extend FabAirflowSecurityManagerOverride." + ): + auth_manager_with_appbuilder.security_manager + @pytest.mark.db_test def test_get_url_login_when_auth_view_not_defined(self, auth_manager_with_appbuilder): with pytest.raises(AirflowException, match="`auth_view` not defined in the security manager."):