@@ -328,14 +328,6 @@ def test_no_issuer(self, tenant_discovery_mock):
328328 Authority (None , self .http_client , oidc_authority_url = authority_url )
329329 self .assertIn ("issuer" , str (context .exception ).lower ())
330330
331- @patch ("msal.authority.tenant_discovery" )
332- def test_microsoft_host_issuer (self , tenant_discovery_mock ):
333- """Test when issuer has a known Microsoft host"""
334- authority_url = "https://custom-domain.com/tenant"
335- issuer = f"https://{ WORLD_WIDE } /tenant"
336- authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
337- self .assertTrue (authority .has_valid_issuer (), "Issuer should be valid when it has a known Microsoft host" )
338-
339331 @patch ("msal.authority.tenant_discovery" )
340332 def test_same_scheme_and_host_different_path (self , tenant_discovery_mock ):
341333 """Test when issuer has same scheme and host but different path"""
@@ -377,3 +369,46 @@ def test_invalid_issuer(self, tenant_discovery_mock):
377369 self .assertIn ("issuer" , str (context .exception ).lower ())
378370 self .assertIn (issuer , str (context .exception ))
379371 self .assertIn (authority_url , str (context .exception ))
372+
373+ @patch ("msal.authority.tenant_discovery" )
374+ def test_custom_authority_with_microsoft_issuer (self , tenant_discovery_mock ):
375+ """Test when custom authority is used with a known Microsoft issuer (should fail)"""
376+ authority_url = "https://custom-domain.com/tenant"
377+ issuer = f"https://{ WORLD_WIDE } /tenant"
378+
379+ tenant_discovery_mock .return_value = {
380+ "authorization_endpoint" : "https://example.com/oauth2/authorize" ,
381+ "token_endpoint" : "https://example.com/oauth2/token" ,
382+ "issuer" : issuer ,
383+ }
384+
385+ # Since initialization now checks for valid issuer and we removed the check for known hosts,
386+ # we expect it to raise ValueError because the hosts don't match
387+ with self .assertRaises (ValueError ) as context :
388+ Authority (None , self .http_client , oidc_authority_url = authority_url )
389+
390+ self .assertIn ("issuer" , str (context .exception ).lower ())
391+ self .assertIn (issuer , str (context .exception ))
392+ self .assertIn (authority_url , str (context .exception ))
393+
394+ @patch ("msal.authority.tenant_discovery" )
395+ def test_known_authority_with_non_matching_issuer (self , tenant_discovery_mock ):
396+ """Test when known authority is used with an issuer that doesn't match (should fail)"""
397+ # Known Microsoft authority URLs
398+ authority_url = f"https://{ WORLD_WIDE } /tenant"
399+ issuer = "https://custom-domain.com/tenant"
400+
401+ tenant_discovery_mock .return_value = {
402+ "authorization_endpoint" : "https://example.com/oauth2/authorize" ,
403+ "token_endpoint" : "https://example.com/oauth2/token" ,
404+ "issuer" : issuer ,
405+ }
406+
407+ # We expect it to raise ValueError because the paths don't match
408+ # and we're now checking for exact matches
409+ with self .assertRaises (ValueError ) as context :
410+ Authority (None , self .http_client , oidc_authority_url = authority_url )
411+
412+ self .assertIn ("issuer" , str (context .exception ).lower ())
413+ self .assertIn (issuer , str (context .exception ))
414+ self .assertIn (authority_url , str (context .exception ))
0 commit comments