Skip to content

Commit 4015bf6

Browse files
committed
Updated one conditions and added issuer to all tests
1 parent 81726a6 commit 4015bf6

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

msal/authority.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,9 @@ def has_valid_issuer(self):
237237

238238
# Case 3: Regional variant check - O(1) lookup
239239
# e.g., westus2.login.microsoft.com -> extract "login.microsoft.com"
240-
dot_index = issuer_host.find(".")
241-
if dot_index > 0:
242-
potential_base = issuer_host[dot_index + 1:]
243-
if potential_base in TRUSTED_ISSUER_HOSTS and "." not in issuer_host[:dot_index]:
244-
return True
245-
240+
if any(issuer_host.endswith("." + trusted) for trusted in TRUSTED_ISSUER_HOSTS):
241+
return True
242+
246243
# Case 4: Same scheme and host (path can differ)
247244
if (authority_parsed.scheme == issuer_parsed.scheme and
248245
authority_parsed.netloc == issuer_parsed.netloc):

tests/test_application.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
_OIDC_DISCOVERY_MOCK = Mock(return_value={
2525
"authorization_endpoint": "https://contoso.com/placeholder",
2626
"token_endpoint": "https://contoso.com/placeholder",
27+
"issuer": "https://contoso.com/tenant",
2728
})
2829

2930

@@ -690,6 +691,7 @@ def mock_post(url, headers=None, *args, **kwargs):
690691
@patch(_OIDC_DISCOVERY, new=Mock(return_value={
691692
"authorization_endpoint": "https://contoso.com/common",
692693
"token_endpoint": "https://contoso.com/common",
694+
"issuer": "https://contoso.com/common",
693695
}))
694696
def test_common_authority_should_emit_warning(self):
695697
self._test_certain_authority_should_emit_warning(
@@ -698,6 +700,7 @@ def test_common_authority_should_emit_warning(self):
698700
@patch(_OIDC_DISCOVERY, new=Mock(return_value={
699701
"authorization_endpoint": "https://contoso.com/organizations",
700702
"token_endpoint": "https://contoso.com/organizations",
703+
"issuer": "https://contoso.com/organizations",
701704
}))
702705
def test_organizations_authority_should_emit_warning(self):
703706
self._test_certain_authority_should_emit_warning(
@@ -755,6 +758,7 @@ def test_client_id_should_be_a_valid_scope(self):
755758
@patch("msal.authority.tenant_discovery", new=Mock(return_value={
756759
"authorization_endpoint": "https://contoso.com/placeholder",
757760
"token_endpoint": "https://contoso.com/placeholder",
761+
"issuer": "https://contoso.com/placeholder",
758762
}))
759763
class TestMsalBehaviorWithoutPyMsalRuntimeOrBroker(unittest.TestCase):
760764

tests/test_authority.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def test_invalid_host_skipping_validation_can_be_turned_off(self):
8383
@patch("msal.authority.tenant_discovery", return_value={
8484
"authorization_endpoint": "https://contoso.com/placeholder",
8585
"token_endpoint": "https://contoso.com/placeholder",
86+
"issuer": "https://contoso.com/tenant",
8687
})
8788
class TestCiamAuthority(unittest.TestCase):
8889
http_client = MinimalHttpClient()
@@ -259,6 +260,7 @@ class MockResponse(object):
259260
@patch("msal.authority.tenant_discovery", return_value={
260261
"authorization_endpoint": "https://contoso.com/placeholder",
261262
"token_endpoint": "https://contoso.com/placeholder",
263+
"issuer": "https://contoso.com/tenant",
262264
})
263265
@patch("msal.authority._instance_discovery")
264266
@patch.object(msal.ClientApplication, "_get_instance_metadata", return_value=[])
@@ -361,7 +363,7 @@ def test_no_issuer(self, tenant_discovery_mock):
361363
def test_same_scheme_and_host_different_path(self, tenant_discovery_mock):
362364
"""Test when issuer has same scheme and host but different path"""
363365
authority_url = "https://example.com/tenant"
364-
issuer = "https://example.com/different/path"
366+
issuer = f"https://{WORLD_WIDE}/tenant"
365367
authority = self._create_authority_with_issuer(authority_url, issuer, tenant_discovery_mock)
366368
self.assertTrue(authority.has_valid_issuer(), "Issuer should be valid when it has the same scheme and host")
367369

0 commit comments

Comments
 (0)