From 3e605b5418ee545983087f55fdc793b9871dc333 Mon Sep 17 00:00:00 2001 From: Marian Cepok Date: Tue, 23 Mar 2021 21:36:55 +0100 Subject: [PATCH 1/2] Fix too specific parsing of `False` in LegacyUIDeprecated --- airflow/upgrade/rules/legacy_ui_deprecated.py | 4 ++-- tests/upgrade/rules/test_legacy_ui_deprecated.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/airflow/upgrade/rules/legacy_ui_deprecated.py b/airflow/upgrade/rules/legacy_ui_deprecated.py index 9570af7819340..07617a8853bb2 100644 --- a/airflow/upgrade/rules/legacy_ui_deprecated.py +++ b/airflow/upgrade/rules/legacy_ui_deprecated.py @@ -28,8 +28,8 @@ class LegacyUIDeprecated(BaseRule): def check(self): if conf.has_option("webserver", "rbac"): - rbac = conf.get("webserver", "rbac") - if rbac == "false": + rbac = conf.get("webserver", "rbac").strip().lower() + if rbac in ("f", "false", "0"): return ( "rbac in airflow.cfg must be explicitly set empty as" " RBAC mechanism is enabled by default." diff --git a/tests/upgrade/rules/test_legacy_ui_deprecated.py b/tests/upgrade/rules/test_legacy_ui_deprecated.py index adbbe8f754ba2..d2ee3a3eb298f 100644 --- a/tests/upgrade/rules/test_legacy_ui_deprecated.py +++ b/tests/upgrade/rules/test_legacy_ui_deprecated.py @@ -21,7 +21,7 @@ class TestLegacyUIDeprecated(TestCase): - @conf_vars({("webserver", "rbac"): "false"}) + @conf_vars({("webserver", "rbac"): "False"}) def test_invalid_check(self): rule = LegacyUIDeprecated() From bea9ab5e51069458653f36d8b770c22bed99ee64 Mon Sep 17 00:00:00 2001 From: Marian Cepok Date: Wed, 24 Mar 2021 07:19:44 +0100 Subject: [PATCH 2/2] Fix too specific parsing of `False` in LegacyUIDeprecated Added more Unittest for possible False values --- tests/upgrade/rules/test_legacy_ui_deprecated.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/upgrade/rules/test_legacy_ui_deprecated.py b/tests/upgrade/rules/test_legacy_ui_deprecated.py index d2ee3a3eb298f..1aea7ef346572 100644 --- a/tests/upgrade/rules/test_legacy_ui_deprecated.py +++ b/tests/upgrade/rules/test_legacy_ui_deprecated.py @@ -15,14 +15,15 @@ # specific language governing permissions and limitations # under the License. from unittest import TestCase +from unittest.mock import patch from airflow.upgrade.rules.legacy_ui_deprecated import LegacyUIDeprecated from tests.test_utils.config import conf_vars class TestLegacyUIDeprecated(TestCase): - @conf_vars({("webserver", "rbac"): "False"}) - def test_invalid_check(self): + @patch('airflow.configuration.conf.get') + def test_invalid_check(self, conf_get): rule = LegacyUIDeprecated() assert isinstance(rule.description, str) @@ -32,8 +33,10 @@ def test_invalid_check(self): "rbac in airflow.cfg must be explicitly set empty as" " RBAC mechanism is enabled by default." ) - response = rule.check() - assert response == msg + for false_value in ("False", "false", "f", "0"): + conf_get.return_value = false_value + response = rule.check() + assert response == msg @conf_vars({("webserver", "rbac"): ""}) def test_valid_check(self):