@@ -553,10 +553,10 @@ func TestTenantDiscoveryValidateIssuer(t *testing.T) {
553553 expectError : false ,
554554 },
555555 {
556- desc : "custom authority with a non-matching Entra issuer" ,
556+ desc : "custom authority with a trusted Entra issuer" ,
557557 issuer : "https://login.microsoftonline.com/" ,
558558 authority : "https://contoso.com/tenant-id" ,
559- expectError : true ,
559+ expectError : false , // Trusted hosts are always valid issuers
560560 },
561561 {
562562 desc : "Entra authority with a non-matching custom issuer" ,
@@ -606,6 +606,48 @@ func TestTenantDiscoveryValidateIssuer(t *testing.T) {
606606 aliases : map [string ]bool {},
607607 expectError : true ,
608608 },
609+ // Test cases for regional authority scenarios where instance discovery isn't performed
610+ {
611+ desc : "regional authority with trusted issuer host (no aliases)" ,
612+ issuer : "https://login.microsoftonline.com/tenant-id" ,
613+ authority : "https://westus2.login.microsoft.com/tenant-id" ,
614+ aliases : nil ,
615+ expectError : false ,
616+ },
617+ {
618+ desc : "regional authority with different trusted issuer host (no aliases)" ,
619+ issuer : "https://login.windows.net/tenant-id" ,
620+ authority : "https://eastus.login.microsoft.com/tenant-id" ,
621+ aliases : map [string ]bool {},
622+ expectError : false ,
623+ },
624+ {
625+ desc : "regional authority with Azure Government trusted issuer" ,
626+ issuer : "https://login.microsoftonline.us/tenant-id" ,
627+ authority : "https://usgovvirginia.login.microsoftonline.us/tenant-id" ,
628+ aliases : nil ,
629+ expectError : false ,
630+ },
631+ {
632+ desc : "regional authority with untrusted issuer host (no aliases)" ,
633+ issuer : "https://malicious.example.com/tenant-id" ,
634+ authority : "https://westus2.login.microsoft.com/tenant-id" ,
635+ aliases : nil ,
636+ expectError : true ,
637+ },
638+ {
639+ desc : "regional authority subdomain with matching trusted issuer" ,
640+ issuer : "https://login.microsoftonline.com/tenant-id" ,
641+ authority : "https://region.login.microsoftonline.com/tenant-id" ,
642+ aliases : nil ,
643+ expectError : false ,
644+ }, {
645+ desc : "regional authority subdomain with matching trusted issuer" ,
646+ issuer : "https://login.dummy-uri.com/tenant-id" ,
647+ authority : "https://region.login.dummy-uri.com/tenant-id" ,
648+ aliases : nil ,
649+ expectError : false ,
650+ },
609651 }
610652
611653 for _ , test := range tests {
@@ -625,3 +667,39 @@ func TestTenantDiscoveryValidateIssuer(t *testing.T) {
625667 })
626668 }
627669}
670+
671+ func TestTrustedHost (t * testing.T ) {
672+ tests := []struct {
673+ host string
674+ expectedTrust bool
675+ }{
676+ // Microsoft Azure Worldwide hosts
677+ {"login.microsoftonline.com" , true },
678+ {"login.windows.net" , true },
679+ {"login.microsoft.com" , true },
680+ {"sts.windows.net" , true },
681+ // Microsoft Azure China hosts
682+ {"login.partner.microsoftonline.cn" , true },
683+ {"login.chinacloudapi.cn" , true },
684+ // Microsoft Azure Germany hosts
685+ {"login.microsoftonline.de" , true },
686+ // Microsoft Azure US Government hosts
687+ {"login.microsoftonline.us" , true },
688+ {"login.usgovcloudapi.net" , true },
689+ {"login-us.microsoftonline.com" , true },
690+ // Untrusted hosts
691+ {"malicious.example.com" , false },
692+ {"fake-login.microsoftonline.com" , false },
693+ {"login.example.com" , false },
694+ {"" , false },
695+ }
696+
697+ for _ , test := range tests {
698+ t .Run (test .host , func (t * testing.T ) {
699+ result := TrustedHost (test .host )
700+ if result != test .expectedTrust {
701+ t .Errorf ("TrustedHost(%q) = %v, want %v" , test .host , result , test .expectedTrust )
702+ }
703+ })
704+ }
705+ }
0 commit comments