4
4
5
5
6
6
class 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'
11
7
12
8
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
19
10
for host in WELL_KNOWN_AUTHORITY_HOSTS :
20
11
a = Authority ('https://{}/common' .format (host ))
21
- # Note: this "common" tenant endpoints always point to its real host
22
12
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 )
25
17
26
18
@unittest .skip ("As of Jan 2017, the server no longer returns V1 endpoint" )
27
19
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):
33
25
self .assertEqual (a .token_endpoint , v1_token_endpoint )
34
26
self .assertNotIn ('v2.0' , a .token_endpoint )
35
27
36
- def test_unknown_host (self ):
28
+ def test_unknown_host_wont_pass_instance_discovery (self ):
37
29
with self .assertRaisesRegexp (MsalServiceError , "invalid_instance" ):
38
30
Authority ('https://unknown.host/tenant_doesnt_matter_in_this_case' )
39
31
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 ):
50
34
Authority ('https://unknown.host/invalid' , validate_authority = False )
51
35
52
36
0 commit comments