@@ -149,22 +149,51 @@ def test_application_obj_should_do_oidc_discovery_and_skip_instance_discovery(
149149 self .assertEqual (app .authority .token_endpoint , self .token_endpoint )
150150
151151
152- class DstsAuthorityTestCase (OidcAuthorityTestCase ):
153- # Inherits OidcAuthority's test cases and run them with a dSTS authority
154- authority = ( # dSTS is single tenanted with a tenant placeholder
155- 'https://test-instance1-dsts.dsts.core.azure-test.net/dstsv2/common' )
156- authorization_endpoint = (
157- "https://some.url.dsts.core.azure-test.net/dstsv2/common/oauth2/authorize" )
158- token_endpoint = (
159- "https://some.url.dsts.core.azure-test.net/dstsv2/common/oauth2/token" )
152+ @patch ("msal.authority._instance_discovery" )
153+ @patch ("msal.authority.tenant_discovery" )
154+ class DstsAuthorityTestCase (unittest .TestCase ):
155+ # Standalone test class for dSTS authority (not inheriting to avoid decorator stacking)
156+ authority = 'https://test-instance1-dsts.dsts.core.azure-test.net/dstsv2/common'
157+ authorization_endpoint = "https://some.url.dsts.core.azure-test.net/dstsv2/common/oauth2/authorize"
158+ token_endpoint = "https://some.url.dsts.core.azure-test.net/dstsv2/common/oauth2/token"
160159 issuer = "https://test-instance1-dsts.dsts.core.azure-test.net/dstsv2/common"
161160
162- @patch ("msal.authority._instance_discovery" )
163- @patch ("msal.authority.tenant_discovery" ) # Remove the hard-coded return_value
164- def test_application_obj_should_accept_dsts_url_as_an_authority (
161+ def setUp (self ):
162+ self .oidc_discovery_endpoint = self .authority + "/.well-known/openid-configuration"
163+
164+ def setup_tenant_discovery (self , tenant_discovery ):
165+ """Configure the tenant_discovery mock with class-specific values"""
166+ tenant_discovery .return_value = {
167+ "authorization_endpoint" : self .authorization_endpoint ,
168+ "token_endpoint" : self .token_endpoint ,
169+ "issuer" : self .issuer ,
170+ }
171+
172+ def test_authority_obj_should_do_oidc_discovery_and_skip_instance_discovery (
173+ self , oidc_discovery , instance_discovery ):
174+ self .setup_tenant_discovery (oidc_discovery )
175+ c = MinimalHttpClient ()
176+ a = Authority (None , c , oidc_authority_url = self .authority )
177+ instance_discovery .assert_not_called ()
178+ oidc_discovery .assert_called_once_with (self .oidc_discovery_endpoint , c )
179+ self .assertEqual (a .authorization_endpoint , self .authorization_endpoint )
180+ self .assertEqual (a .token_endpoint , self .token_endpoint )
181+
182+ def test_application_obj_should_do_oidc_discovery_and_skip_instance_discovery (
165183 self , oidc_discovery , instance_discovery ):
166184 self .setup_tenant_discovery (oidc_discovery )
185+ app = msal .ClientApplication (
186+ "id" , authority = None , oidc_authority = self .authority )
187+ instance_discovery .assert_not_called ()
188+ oidc_discovery .assert_called_once_with (
189+ self .oidc_discovery_endpoint , app .http_client )
190+ self .assertEqual (
191+ app .authority .authorization_endpoint , self .authorization_endpoint )
192+ self .assertEqual (app .authority .token_endpoint , self .token_endpoint )
167193
194+ def test_application_obj_should_accept_dsts_url_as_an_authority (
195+ self , oidc_discovery , instance_discovery ):
196+ self .setup_tenant_discovery (oidc_discovery )
168197 app = msal .ClientApplication ("id" , authority = self .authority )
169198 instance_discovery .assert_not_called ()
170199 oidc_discovery .assert_called_once_with (
0 commit comments