25
25
26
26
27
27
fake_time = time .time ()
28
+ CODE = "asdf345xdf"
28
29
29
30
30
31
def fake_token (token ):
@@ -51,9 +52,7 @@ def setUp(self):
51
52
self .client_secret = "someclientsecret"
52
53
self .user_username = "user_username"
53
54
self .user_password = "user_password"
54
- self .client_WebApplication = WebApplicationClient (
55
- self .client_id , code = "asdf345xdf"
56
- )
55
+ self .client_WebApplication = WebApplicationClient (self .client_id , code = CODE )
57
56
self .client_LegacyApplication = LegacyApplicationClient (self .client_id )
58
57
self .client_BackendApplication = BackendApplicationClient (self .client_id )
59
58
self .client_MobileApplication = MobileApplicationClient (self .client_id )
@@ -291,7 +290,7 @@ def fake_send(r, **kwargs):
291
290
_fetch_history [2 ][2 ], expected_auth_header
292
291
) # ensure a Basic Authorization header
293
292
294
- # scneario 4 - send in a username/password combo
293
+ # scenario 4 - send in a username/password combo
295
294
# this should send the `client_id` in the headers, like scenario 1
296
295
self .assertEqual (
297
296
sess .fetch_token (
@@ -312,31 +311,39 @@ def fake_send(r, **kwargs):
312
311
self .assertIn ("username=%s" % self .user_username , _fetch_history [3 ][1 ])
313
312
self .assertIn ("password=%s" % self .user_password , _fetch_history [3 ][1 ])
314
313
314
+ # scenario 5 - send data in `params` and not in `data` for providers
315
+ # that expect data in URL
316
+ self .assertEqual (
317
+ sess .fetch_token (url , client_secret = "somesecret" , force_querystring = True ),
318
+ self .token ,
319
+ )
320
+ self .assertIn ("code=%s" % CODE , _fetch_history [4 ][0 ])
321
+
315
322
# some quick tests for valid ways of supporting `client_secret`
316
323
317
324
# scenario 2b - force the `client_id` into the body; but the `client_secret` is `None`
318
325
self .assertEqual (
319
326
sess .fetch_token (url , client_secret = None , include_client_id = True ),
320
327
self .token ,
321
328
)
322
- self .assertEqual (len (_fetch_history ), 5 )
323
- self .assertIn ("client_id=%s" % self .client_id , _fetch_history [4 ][1 ])
329
+ self .assertEqual (len (_fetch_history ), 6 )
330
+ self .assertIn ("client_id=%s" % self .client_id , _fetch_history [5 ][1 ])
324
331
self .assertNotIn (
325
- "client_secret" , _fetch_history [4 ][1 ]
332
+ "client_secret= " , _fetch_history [5 ][1 ]
326
333
) # no `client_secret` in the body
327
334
self .assertEqual (
328
- _fetch_history [4 ][2 ], None
335
+ _fetch_history [5 ][2 ], None
329
336
) # ensure NO Basic Authorization header
330
337
331
338
# scenario 2c - force the `client_id` into the body; but the `client_secret` is an empty string
332
339
self .assertEqual (
333
340
sess .fetch_token (url , client_secret = "" , include_client_id = True ), self .token
334
341
)
335
- self .assertEqual (len (_fetch_history ), 6 )
336
- self .assertIn ("client_id=%s" % self .client_id , _fetch_history [5 ][1 ])
337
- self .assertIn ("client_secret=" , _fetch_history [5 ][1 ])
342
+ self .assertEqual (len (_fetch_history ), 7 )
343
+ self .assertIn ("client_id=%s" % self .client_id , _fetch_history [6 ][1 ])
344
+ self .assertIn ("client_secret=" , _fetch_history [6 ][1 ])
338
345
self .assertEqual (
339
- _fetch_history [5 ][2 ], None
346
+ _fetch_history [6 ][2 ], None
340
347
) # ensure NO Basic Authorization header
341
348
342
349
def test_cleans_previous_token_before_fetching_new_one (self ):
0 commit comments