This is an automated email from the ASF dual-hosted git repository.
dabla pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new f30c2ef60c1 Fix msgraph/Power BI auth failure from empty allowed_hosts
list (#69014)
f30c2ef60c1 is described below
commit f30c2ef60c18d2e84438983767a721a350165732
Author: davidnzhang <[email protected]>
AuthorDate: Thu Jul 2 17:08:35 2026 +1000
Fix msgraph/Power BI auth failure from empty allowed_hosts list (#69014)
* Fix msgraph/Power BI auth failure from empty allowed_hosts list
* Refactor get_allowed_hosts into a static method with direct unit tests
* Filter blank entries from parsed allowed_hosts
---
.../src/airflow/providers/microsoft/azure/hooks/msgraph.py | 9 ++++++++-
.../azure/tests/unit/microsoft/azure/hooks/test_msgraph.py | 14 ++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git
a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
index d1bc2f8deb1..06be566f095 100644
---
a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
+++
b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
@@ -294,6 +294,13 @@ class KiotaRequestAdapterHook(BaseHook):
return proxies
return None
+ @staticmethod
+ def get_allowed_hosts(authority: str | None, config: dict) -> list[str]:
+ allowed_hosts = config.get("allowed_hosts", authority)
+ if not allowed_hosts:
+ return []
+ return [host for host in allowed_hosts.split(",") if host]
+
def _build_request_adapter(self, connection) -> tuple[str, RequestAdapter]:
client_id = connection.login
client_secret = connection.password
@@ -311,7 +318,7 @@ class KiotaRequestAdapterHook(BaseHook):
scopes = scopes.split(",")
verify = config.get("verify", True)
trust_env = config.get("trust_env", False)
- allowed_hosts = (config.get("allowed_hosts", authority) or
"").split(",")
+ allowed_hosts = self.get_allowed_hosts(authority, config)
self.log.info(
"Creating Microsoft Graph SDK client %s for conn_id: %s",
diff --git
a/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py
b/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py
index 8a6252da36e..3c6a6515c60 100644
--- a/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py
+++ b/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py
@@ -570,6 +570,20 @@ class TestKiotaRequestAdapterHook:
adapter.send_no_response_content_async.assert_called_once()
assert hook.conn_id not in hook.cached_request_adapters
+ def test_allowed_hosts_is_empty_list_when_not_configured(self):
+ """An unset allowed_hosts/authority must yield []."""
+ actual = KiotaRequestAdapterHook.get_allowed_hosts(None, {})
+
+ assert actual == []
+
+ def test_allowed_hosts_from_config(self):
+ """A configured allowed_hosts string must be split into a list."""
+ actual = KiotaRequestAdapterHook.get_allowed_hosts(
+ None, {"allowed_hosts":
"api.powerbi.com,login.microsoftonline.com"}
+ )
+
+ assert actual == ["api.powerbi.com", "login.microsoftonline.com"]
+
class TestKiotaRequestAdapterHookProtocol:
"""Test protocol handling in KiotaRequestAdapterHook."""