dabla commented on code in PR #77007:
URL: https://github.com/apache/airflow/pull/77007#discussion_r4579921287


##########
providers/keycloak/tests/unit/keycloak/auth_manager/test_keycloak_auth_manager.py:
##########
@@ -1630,5 +1631,100 @@ def test_filter_authorized_dag_ids_caps_max_workers(
 
         mock_executor.assert_called_once_with(max_workers=expected_max_workers)
 
+    @pytest.mark.parametrize(
+        ("filter_name", "check_name", "resources", "expected"),
+        [
+            pytest.param(
+                "filter_authorized_dag_ids",
+                "is_authorized_dag",
+                {"dag_ids": {"dag_0", "dag_1", "dag_2"}},
+                {"dag_0", "dag_1", "dag_2"},
+                id="dags",
+            ),
+            pytest.param(
+                "filter_authorized_assets",
+                "is_authorized_asset",
+                {"assets": [AssetDetails(id="1"), AssetDetails(id="2"), 
AssetDetails(id=None)]},
+                {"1", "2"},
+                id="assets",
+            ),
+            pytest.param(
+                "filter_authorized_connections",
+                "is_authorized_connection",
+                {"conn_ids": {"conn_0", "conn_1", "conn_2"}},
+                {"conn_0", "conn_1", "conn_2"},
+                id="connections",
+            ),
+            pytest.param(
+                "filter_authorized_pools",
+                "is_authorized_pool",
+                {"pool_names": {"pool_0", "pool_1", "pool_2"}},
+                {"pool_0", "pool_1", "pool_2"},
+                id="pools",
+            ),
+            pytest.param(
+                "filter_authorized_variables",
+                "is_authorized_variable",
+                {"variable_keys": {"var_0", "var_1", "var_2"}},
+                {"var_0", "var_1", "var_2"},
+                id="variables",
+            ),
+        ],
+    )
+    @pytest.mark.parametrize("authorized", [True, False])
+    def test_filter_with_team_level_authorization_asks_keycloak_once(
+        self, auth_manager, user, filter_name, check_name, resources, 
expected, authorized
+    ):
+        """One decision of Keycloak applies to every resource of the list."""
+        with (
+            conf_vars({(CONF_SECTION_NAME, CONF_TEAM_LEVEL_AUTHORIZATION_KEY): 
"True"}),
+            patch.object(
+                KeycloakAuthManager, check_name, autospec=True, 
return_value=authorized
+            ) as mock_is_authorized,
+        ):
+            result = getattr(auth_manager, filter_name)(**resources, 
user=user, method="GET")
+
+        assert result == (expected if authorized else set())
+        mock_is_authorized.assert_called_once()
+
+    @pytest.mark.skipif(not AIRFLOW_V_3_2_PLUS, reason="team_name not 
supported before Airflow 3.2.0")
+    @patch.object(KeycloakAuthManager, "is_authorized_dag", autospec=True, 
return_value=True)
+    def 
test_filter_with_team_level_authorization_asks_for_a_listed_dag_of_the_team(
+        self, mock_is_authorized, auth_manager_multi_team, user
+    ):
+        """The request names a Dag of the list and its team, as a check of 
that single Dag would."""
+        with conf_vars({(CONF_SECTION_NAME, 
CONF_TEAM_LEVEL_AUTHORIZATION_KEY): "True"}):
+            auth_manager_multi_team.filter_authorized_dag_ids(
+                dag_ids={"dag_1", "dag_0"}, user=user, method="PUT", 
team_name="team_a"
+            )
+
+        mock_is_authorized.assert_called_once_with(
+            auth_manager_multi_team,
+            method="PUT",
+            user=user,
+            details=DagDetails(id="dag_0", team_name="team_a"),
+        )
+
+    @patch.object(KeycloakAuthManager, "is_authorized_dag", autospec=True, 
return_value=True)
+    def 
test_filter_with_team_level_authorization_and_no_resources_skips_keycloak(

Review Comment:
   Right, it never depended on the new branch. Dropped in c8e4e4585f.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to