44
55
66class TestAuthority (unittest .TestCase ):
7- COMMON_AUTH_ENDPOINT = \
8- 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
9- COMMON_TOKEN_ENDPOINT = \
10- 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
117
128 def test_wellknown_host_and_tenant (self ):
13- # Test one specific sample in straightforward way, for readability
14- a = Authority ('https://login.microsoftonline.com/common' )
15- self .assertEqual (a .authorization_endpoint , self .COMMON_AUTH_ENDPOINT )
16- self .assertEqual (a .token_endpoint , self .COMMON_TOKEN_ENDPOINT )
17-
18- # Test all well known authority hosts, using same real "common" tenant
9+ # Assert all well known authority hosts are using their own "common" tenant
1910 for host in WELL_KNOWN_AUTHORITY_HOSTS :
2011 a = Authority ('https://{}/common' .format (host ))
21- # Note: this "common" tenant endpoints always point to its real host
2212 self .assertEqual (
23- a .authorization_endpoint , self .COMMON_AUTH_ENDPOINT )
24- self .assertEqual (a .token_endpoint , self .COMMON_TOKEN_ENDPOINT )
13+ a .authorization_endpoint ,
14+ 'https://%s/common/oauth2/v2.0/authorize' % host )
15+ self .assertEqual (
16+ a .token_endpoint , 'https://%s/common/oauth2/v2.0/token' % host )
2517
2618 @unittest .skip ("As of Jan 2017, the server no longer returns V1 endpoint" )
2719 def test_lessknown_host_will_return_a_set_of_v1_endpoints (self ):
@@ -33,20 +25,12 @@ def test_lessknown_host_will_return_a_set_of_v1_endpoints(self):
3325 self .assertEqual (a .token_endpoint , v1_token_endpoint )
3426 self .assertNotIn ('v2.0' , a .token_endpoint )
3527
36- def test_unknown_host (self ):
28+ def test_unknown_host_wont_pass_instance_discovery (self ):
3729 with self .assertRaisesRegexp (MsalServiceError , "invalid_instance" ):
3830 Authority ('https://unknown.host/tenant_doesnt_matter_in_this_case' )
3931
40- def test_unknown_host_valid_tenant_and_skip_host_validation (self ):
41- # When skipping host (a.k.a. instance) validation,
42- # the Tenant Discovery will always use WORLD_WIDE service as instance,
43- # so, if the tenant happens to exist there, it will find some endpoints.
44- a = Authority ('https://incorrect.host/common' , validate_authority = False )
45- self .assertEqual (a .authorization_endpoint , self .COMMON_AUTH_ENDPOINT )
46- self .assertEqual (a .token_endpoint , self .COMMON_TOKEN_ENDPOINT )
47-
48- def test_unknown_host_unknown_tenant_and_skip_host_validation (self ):
49- with self .assertRaisesRegexp (MsalServiceError , "invalid_tenant" ):
32+ def test_invalid_host_skipping_validation_meets_connection_error_down_the_road (self ):
33+ with self .assertRaises (requests .exceptions .RequestException ):
5034 Authority ('https://unknown.host/invalid' , validate_authority = False )
5135
5236
0 commit comments