@@ -153,13 +153,13 @@ def test_username_password(self):
153
153
self .skipUnlessWithConfig (["client_id" , "username" , "password" , "scope" ])
154
154
self ._test_username_password (** self .config )
155
155
156
- def _get_app_and_auth_code (self , ** kwargs ):
156
+ def _get_app_and_auth_code (self , scopes = None , ** kwargs ):
157
157
return _get_app_and_auth_code (
158
158
self .config ["client_id" ],
159
159
client_secret = self .config .get ("client_secret" ),
160
160
authority = self .config .get ("authority" ),
161
161
port = self .config .get ("listen_port" , 44331 ),
162
- scopes = self .config ["scope" ],
162
+ scopes = scopes or self .config ["scope" ],
163
163
** kwargs )
164
164
165
165
def _test_auth_code (self , auth_kwargs , token_kwargs ):
@@ -202,27 +202,31 @@ def test_ssh_cert(self):
202
202
"sshcrt" : "true" ,
203
203
}
204
204
205
- (self .app , ac , redirect_uri ) = self ._get_app_and_auth_code ()
205
+ scopes = [ # Only this scope would result in an SSH-Cert
206
+ "https://pas.windows.net/CheckMyAccess/Linux/user_impersonation" ]
207
+ (self .app , ac , redirect_uri ) = self ._get_app_and_auth_code (scopes = scopes )
206
208
207
209
result = self .app .acquire_token_by_authorization_code (
208
- ac , self . config [ "scope" ] , redirect_uri = redirect_uri , data = data1 ,
210
+ ac , scopes , redirect_uri = redirect_uri , data = data1 ,
209
211
params = ssh_test_slice )
212
+ self .assertIsNotNone (result .get ("access_token" ), "Encountered {}: {}" .format (
213
+ result .get ("error" ), result .get ("error_description" )))
210
214
self .assertEqual ("ssh-cert" , result ["token_type" ])
211
215
logger .debug ("%s.cache = %s" ,
212
216
self .id (), json .dumps (self .app .token_cache ._cache , indent = 4 ))
213
217
214
218
# acquire_token_silent() needs to be passed the same key to work
215
219
account = self .app .get_accounts ()[0 ]
216
220
result_from_cache = self .app .acquire_token_silent (
217
- self . config [ "scope" ] , account = account , data = data1 )
221
+ scopes , account = account , data = data1 )
218
222
self .assertIsNotNone (result_from_cache )
219
223
self .assertEqual (
220
224
result ['access_token' ], result_from_cache ['access_token' ],
221
225
"We should get the cached SSH-cert" )
222
226
223
227
# refresh_token grant can fetch an ssh-cert bound to a different key
224
228
refreshed_ssh_cert = self .app .acquire_token_silent (
225
- self . config [ "scope" ] , account = account , params = ssh_test_slice ,
229
+ scopes , account = account , params = ssh_test_slice ,
226
230
data = {"token_type" : "ssh-cert" , "key_id" : "key2" , "req_cnf" : JWK2 })
227
231
self .assertIsNotNone (refreshed_ssh_cert )
228
232
self .assertEqual (refreshed_ssh_cert ["token_type" ], "ssh-cert" )
0 commit comments