Skip to content

Commit 8f0920f

Browse files
authored
Always apply proxy configuration with MSAL for KiotaRequestAdapterHook in msgraph module (#61199)
* Update msgraph.py to_msal_proxies Updated the logic of function to_msal_proxies. Return proxies attribute even when the authority is not filled * Added Unit tests for testing to_msal_proxies. * Changed elif to if based on Static Tests * Removed trailing whitespaces based on Static Test output.
1 parent 7edec78 commit 8f0920f

File tree

2 files changed

+42
-0
lines changed
  • providers/microsoft/azure

2 files changed

+42
-0
lines changed

providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ def to_msal_proxies(self, authority: str | None, proxies: dict | None) -> dict |
292292
if authority.endswith(domain_name):
293293
return None
294294
return proxies
295+
if proxies:
296+
return proxies
295297
return None
296298

297299
def _build_request_adapter(self, connection) -> tuple[str, RequestAdapter]:

providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,46 @@ async def test_build_request_adapter_masks_secrets(self):
432432
mock_redact.assert_any_call({"http": "http://user:pass@proxy:3128"}, name="proxies")
433433
mock_redact.assert_any_call("my_secret_password", name="client_secret")
434434

435+
def test_msal_returns_none_when_authority_matches_no_proxy(self):
436+
hook = KiotaRequestAdapterHook(conn_id="msgraph")
437+
438+
proxies = {"http": "http://proxy", "no": "*.example.com"}
439+
authority = "api.example.com"
440+
441+
result = hook.to_msal_proxies(authority, proxies)
442+
443+
assert result is None
444+
445+
def test_msal_returns_proxies_when_authority_does_not_match_no_proxy(self):
446+
hook = KiotaRequestAdapterHook(conn_id="msgraph")
447+
448+
proxies = {"http": "http://proxy", "no": "*.example.com"}
449+
authority = "api.other.com"
450+
451+
result = hook.to_msal_proxies(authority, proxies)
452+
453+
assert result == proxies
454+
455+
def test_msal_returns_proxies_when_no_authority_no_proxy_key(self):
456+
hook = KiotaRequestAdapterHook(conn_id="msgraph")
457+
458+
proxies = {"no": "*example.com"}
459+
authority = None
460+
461+
result = hook.to_msal_proxies(authority, proxies)
462+
463+
assert result == proxies
464+
465+
def test_msal_returns_proxies_when_no_authority_with_proxy_key(self):
466+
hook = KiotaRequestAdapterHook(conn_id="msgraph")
467+
468+
proxies = {"http": "http://proxy"}
469+
authority = None
470+
471+
result = hook.to_msal_proxies(authority, proxies)
472+
473+
assert result == proxies
474+
435475

436476
class TestKiotaRequestAdapterHookProtocol:
437477
"""Test protocol handling in KiotaRequestAdapterHook."""

0 commit comments

Comments
 (0)