1
1
import unittest
2
+ import requests
2
3
from fnmatch import fnmatch
3
4
from unittest import mock
4
5
from unittest .mock import ANY
5
6
6
7
from cryptography .hazmat .primitives import asymmetric , serialization
7
8
9
+ from ... import Auth0Error
8
10
from ...authentication .get_token import GetToken
9
11
10
12
@@ -335,7 +337,25 @@ def test_backchannel_login(self, mock_post):
335
337
"grant_type" : "urn:openid:params:grant-type:ciba" ,
336
338
},
337
339
)
338
-
340
+
341
+ @mock .patch ("requests.request" )
342
+ def test_backchannel_login_headers_on_failure (self , mock_requests_request ):
343
+ response = requests .Response ()
344
+ response .status_code = 400
345
+ response .headers = {"Retry-After" : "100" }
346
+ response ._content = b'{"error":"slow_down"}'
347
+ mock_requests_request .return_value = response
348
+
349
+ g = GetToken ("my.domain.com" , "cid" , client_secret = "csec" )
350
+
351
+ with self .assertRaises (Auth0Error ) as context :
352
+ g .backchannel_login (
353
+ auth_req_id = "reqid" ,
354
+ grant_type = "urn:openid:params:grant-type:ciba" ,
355
+ )
356
+ self .assertEqual (context .exception .headers ["Retry-After" ], "100" )
357
+ self .assertEqual (context .exception .status_code , 400 )
358
+
339
359
@mock .patch ("auth0.rest.RestClient.post" )
340
360
def test_connection_login (self , mock_post ):
341
361
g = GetToken ("my.domain.com" , "cid" , client_secret = "csec" )
@@ -364,4 +384,33 @@ def test_connection_login(self, mock_post):
364
384
"requested_token_type" : "http://auth0.com/oauth/token-type/federated-connection-access-token" ,
365
385
"connection" : "google-oauth2"
366
386
},
387
+ )
388
+
389
+ @mock .patch ("auth0.rest.RestClient.post" )
390
+ def test_connection_login_with_login_hint (self , mock_post ):
391
+ g = GetToken ("my.domain.com" , "cid" , client_secret = "csec" )
392
+
393
+ g .access_token_for_connection (
394
+ subject_token_type = "urn:ietf:params:oauth:token-type:refresh_token" ,
395
+ subject_token = "refid" ,
396
+ requested_token_type = "http://auth0.com/oauth/token-type/federated-connection-access-token" ,
397
+ connection = "google-oauth2" ,
398
+
399
+ )
400
+
401
+ args , kwargs = mock_post .call_args
402
+
403
+ self .assertEqual (args [0 ], "https://my.domain.com/oauth/token" )
404
+ self .assertEqual (
405
+ kwargs ["data" ],
406
+ {
407
+ "grant_type" : "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token" ,
408
+ "client_id" : "cid" ,
409
+ "client_secret" : "csec" ,
410
+ "subject_token_type" : "urn:ietf:params:oauth:token-type:refresh_token" ,
411
+ "subject_token" : "refid" ,
412
+ "requested_token_type" : "http://auth0.com/oauth/token-type/federated-connection-access-token" ,
413
+ "connection" : "google-oauth2" ,
414
+
415
+ },
367
416
)
0 commit comments