@@ -83,20 +83,21 @@ def test_success_dynamic_instance_discovery(self):
83
83
self .nonHardCodedAuthorizeEndpoint
84
84
)
85
85
86
- responseOptions = { 'authority' : self .nonHardCodedAuthority }
86
+ responseOptions = { 'authority' : self .nonHardCodedAuthority }
87
87
response = util .create_response (responseOptions )
88
88
wireResponse = response ['wireResponse' ]
89
89
90
90
util .setup_expected_client_cred_token_request_response (200 , wireResponse , self .nonHardCodedAuthority )
91
91
92
- token_response = adal .acquire_token_with_client_credentials (
93
- self .nonHardCodedAuthority , cp ['clientId' ], cp ['clientSecret' ], response ['resource' ])
92
+ context = adal .AuthenticationContext (self .nonHardCodedAuthority )
93
+ token_response = context .acquire_token_with_client_credentials (
94
+ response ['resource' ], cp ['clientId' ], cp ['clientSecret' ])
94
95
self .assertTrue (
95
96
util .is_match_token_response (response ['cachedResponse' ], token_response ),
96
97
'The response does not match what was expected.: ' + str (token_response )
97
98
)
98
99
99
- def performStaticInstanceDiscovery (self , authorityHost , callback ):
100
+ def performStaticInstanceDiscovery (self , authorityHost ):
100
101
hardCodedAuthority = 'https://' + authorityHost + '/' + cp ['tenant' ]
101
102
102
103
responseOptions = {
@@ -106,8 +107,9 @@ def performStaticInstanceDiscovery(self, authorityHost, callback):
106
107
wireResponse = response ['wireResponse' ]
107
108
tokenRequest = util .setup_expected_client_cred_token_request_response (200 , wireResponse , hardCodedAuthority )
108
109
109
- token_response = adal .acquire_token_with_client_credentials (
110
- hardCodedAuthority , cp ['clientId' ], cp ['clientSecret' ], response ['resource' ])
110
+ context = adal .AuthenticationContext (hardCodedAuthority )
111
+ token_response = context .acquire_token_with_client_credentials (
112
+ response ['resource' ], cp ['clientId' ], cp ['clientSecret' ])
111
113
112
114
self .assertTrue (
113
115
util .is_match_token_response (response ['cachedResponse' ], token_response ),
@@ -117,32 +119,31 @@ def performStaticInstanceDiscovery(self, authorityHost, callback):
117
119
118
120
@httpretty .activate
119
121
def test_success_static_instance_discovery (self ):
120
- def callback (err ):
121
- if err :
122
- raise Exception (err )
123
122
124
- self .performStaticInstanceDiscovery ('login.microsoftonline.com' , callback )
125
- self .performStaticInstanceDiscovery ('login.windows.net' , callback )
126
- self .performStaticInstanceDiscovery ('login.chinacloudapi.cn' , callback )
127
- self .performStaticInstanceDiscovery ('login.cloudgovapi.us' , callback )
123
+ self .performStaticInstanceDiscovery ('login.microsoftonline.com' )
124
+ self .performStaticInstanceDiscovery ('login.windows.net' )
125
+ self .performStaticInstanceDiscovery ('login.chinacloudapi.cn' )
126
+ self .performStaticInstanceDiscovery ('login.cloudgovapi.us' )
128
127
129
128
130
129
@httpretty .activate
131
130
def test_http_error (self ):
132
131
util .setup_expected_instance_discovery_request (500 , cp ['authorityHosts' ]['global' ], None , self .nonHardCodedAuthorizeEndpoint )
133
132
134
- with self .assertRaisesRegexp (Exception , '500' ):
135
- token_response = adal .acquire_token_with_client_credentials (
136
- self .nonHardCodedAuthority , cp ['clientId' ], cp ['clientSecret' ], cp ['resource' ])
133
+ with self .assertRaisesRegex (Exception , '500' ):
134
+ context = adal .AuthenticationContext (self .nonHardCodedAuthority )
135
+ token_response = context .acquire_token_with_client_credentials (
136
+ cp ['resource' ], cp ['clientId' ], cp ['clientSecret' ])
137
137
138
138
@httpretty .activate
139
139
def test_validation_error (self ):
140
140
returnDoc = { 'error' : 'invalid_instance' , 'error_description' : 'the instance was invalid' }
141
141
util .setup_expected_instance_discovery_request (400 , cp ['authorityHosts' ]['global' ], returnDoc , self .nonHardCodedAuthorizeEndpoint )
142
142
143
- with self .assertRaisesRegexp (Exception , 'instance was invalid' ):
144
- token_response = adal .acquire_token_with_client_credentials (
145
- self .nonHardCodedAuthority , cp ['clientId' ], cp ['clientSecret' ], cp ['resource' ])
143
+ with self .assertRaisesRegex (Exception , 'instance was invalid' ):
144
+ context = adal .AuthenticationContext (self .nonHardCodedAuthority )
145
+ token_response = context .acquire_token_with_client_credentials (
146
+ cp ['resource' ], cp ['clientId' ], cp ['clientSecret' ])
146
147
147
148
@httpretty .activate
148
149
def test_validation_off (self ):
@@ -159,8 +160,9 @@ def test_validation_off(self):
159
160
160
161
util .setup_expected_client_cred_token_request_response (200 , wireResponse , self .nonHardCodedAuthority )
161
162
162
- token_response = adal .acquire_token_with_client_credentials (
163
- self .nonHardCodedAuthority , cp ['clientId' ], cp ['clientSecret' ], response ['resource' ], validate_authority = False )
163
+ context = adal .AuthenticationContext (self .nonHardCodedAuthority )
164
+ token_response = context .acquire_token_with_client_credentials (
165
+ response ['resource' ], cp ['clientId' ], cp ['clientSecret' ])
164
166
self .assertTrue (
165
167
util .is_match_token_response (response ['cachedResponse' ], token_response ),
166
168
'The response does not match what was expected.: ' + str (token_response )
@@ -169,12 +171,12 @@ def test_validation_off(self):
169
171
170
172
@httpretty .activate
171
173
def test_bad_url_not_https (self ):
172
- with self .assertRaisesRegexp (ValueError , "The authority url must be an https endpoint\." ):
174
+ with self .assertRaisesRegex (ValueError , "The authority url must be an https endpoint\." ):
173
175
context = AuthenticationContext ('http://this.is.not.https.com/mytenant.com' )
174
176
175
177
@httpretty .activate
176
178
def test_bad_url_has_query (self ):
177
- with self .assertRaisesRegexp (ValueError , "The authority url must not have a query string\." ):
179
+ with self .assertRaisesRegex (ValueError , "The authority url must not have a query string\." ):
178
180
context = AuthenticationContext (cp ['authorityTenant' ] + '?this=should¬=be&here=foo' )
179
181
180
182
@httpretty .activate
@@ -190,13 +192,9 @@ def test_url_extra_path_elements(self):
190
192
authority = Authority (authority_url , True )
191
193
obj = util .create_empty_adal_object ()
192
194
193
- def callback (err ):
194
- if err :
195
- self .assertFalse (err , 'Received unexpected error: ' + err .args [0 ])
196
- req = httpretty .last_request ()
197
- util .match_standard_request_headers (req )
198
-
199
- authority .validate (obj ['call_context' ], callback )
195
+ authority .validate (obj ['call_context' ])
196
+ req = httpretty .last_request ()
197
+ util .match_standard_request_headers (req )
200
198
201
199
if __name__ == '__main__' :
202
200
unittest .main ()
0 commit comments