@@ -526,3 +526,81 @@ def test_issuer_case_sensitivity_host(self, tenant_discovery_mock):
526526 self .assertTrue (authority .has_valid_issuer (),
527527 "Host comparison should be case-insensitive" )
528528
529+ # Case 3b: Regional prefix on authority host tests
530+ @patch ("msal.authority.tenant_discovery" )
531+ def test_regional_issuer_matching_authority_host (self , tenant_discovery_mock ):
532+ """Test issuer with region prefix on the authority host: us.someweb.com -> someweb.com"""
533+ authority_url = "https://someweb.com/tenant"
534+ issuer = "https://us.someweb.com/tenant"
535+ authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
536+ self .assertTrue (authority .has_valid_issuer (),
537+ "Issuer with region prefix on authority host should be valid" )
538+
539+ @patch ("msal.authority.tenant_discovery" )
540+ def test_regional_issuer_westus2_on_custom_authority (self , tenant_discovery_mock ):
541+ """Test issuer westus2.myidp.example.com with authority myidp.example.com"""
542+ authority_url = "https://myidp.example.com/tenant"
543+ issuer = "https://westus2.myidp.example.com/tenant"
544+ authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
545+ self .assertTrue (authority .has_valid_issuer (),
546+ "Regional prefix westus2 on custom authority host should be valid" )
547+
548+ @patch ("msal.authority.tenant_discovery" )
549+ def test_regional_issuer_does_not_match_different_authority (self , tenant_discovery_mock ):
550+ """Test issuer us.someweb.com should NOT match authority otherdomain.com"""
551+ authority_url = "https://otherdomain.com/tenant"
552+ issuer = "https://us.someweb.com/tenant"
553+ tenant_discovery_mock .return_value = {
554+ "authorization_endpoint" : "https://example.com/oauth2/authorize" ,
555+ "token_endpoint" : "https://example.com/oauth2/token" ,
556+ "issuer" : issuer ,
557+ }
558+ with self .assertRaises (ValueError ):
559+ Authority (None , self .http_client , oidc_authority_url = authority_url )
560+
561+ @patch ("msal.authority.tenant_discovery" )
562+ def test_regional_issuer_on_authority_with_different_path (self , tenant_discovery_mock ):
563+ """Test issuer eastus.someweb.com/v2 with authority someweb.com/tenant"""
564+ authority_url = "https://someweb.com/tenant"
565+ issuer = "https://eastus.someweb.com/v2"
566+ authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
567+ self .assertTrue (authority .has_valid_issuer (),
568+ "Regional issuer with different path should still match by host" )
569+
570+ # Case 5: B2C host suffix tests
571+ @patch ("msal.authority.tenant_discovery" )
572+ def test_b2c_issuer_host (self , tenant_discovery_mock ):
573+ """Test issuer from a well-known B2C host: tenant.b2clogin.com"""
574+ authority_url = "https://custom-domain.com/tenant"
575+ issuer = "https://tenant.b2clogin.com/tenant/v2.0"
576+ authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
577+ self .assertTrue (authority .has_valid_issuer (),
578+ "Issuer ending with b2clogin.com should be valid" )
579+
580+ @patch ("msal.authority.tenant_discovery" )
581+ def test_b2c_china_issuer_host (self , tenant_discovery_mock ):
582+ """Test issuer from B2C China host: tenant.b2clogin.cn"""
583+ authority_url = "https://custom-domain.com/tenant"
584+ issuer = "https://tenant.b2clogin.cn/tenant/v2.0"
585+ authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
586+ self .assertTrue (authority .has_valid_issuer (),
587+ "Issuer ending with b2clogin.cn should be valid" )
588+
589+ @patch ("msal.authority.tenant_discovery" )
590+ def test_b2c_us_gov_issuer_host (self , tenant_discovery_mock ):
591+ """Test issuer from B2C US Government host: tenant.b2clogin.us"""
592+ authority_url = "https://custom-domain.com/tenant"
593+ issuer = "https://tenant.b2clogin.us/tenant/v2.0"
594+ authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
595+ self .assertTrue (authority .has_valid_issuer (),
596+ "Issuer ending with b2clogin.us should be valid" )
597+
598+ @patch ("msal.authority.tenant_discovery" )
599+ def test_ciam_issuer_host_via_b2c_check (self , tenant_discovery_mock ):
600+ """Test issuer from ciamlogin.com host is accepted via B2C check"""
601+ authority_url = "https://custom-domain.com/tenant"
602+ issuer = "https://mytenant.ciamlogin.com/tenant"
603+ authority = self ._create_authority_with_issuer (authority_url , issuer , tenant_discovery_mock )
604+ self .assertTrue (authority .has_valid_issuer (),
605+ "Issuer ending with ciamlogin.com should be valid" )
606+
0 commit comments