Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ def to_msal_proxies(self, authority: str | None, proxies: dict | None) -> dict |
return proxies
return None

@staticmethod
def get_allowed_hosts(authority: str, 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
Expand All @@ -311,7 +318,7 @@ def _build_request_adapter(self, connection) -> tuple[str, RequestAdapter]:
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,20 @@ async def test_send_request_invalidates_cache_and_raises_on_any_error(self):
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."""
Expand Down