Skip to content

Commit 67bf283

Browse files
committed
Updates per PR feedback
1 parent b0b6754 commit 67bf283

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

auth0/authentication/back_channel_login.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def back_channel_login(
3333
Rich Authorization Requests (RAR) details to include in the CIBA request.
3434
3535
requested_expiry (int, optional): Number of seconds the authentication request is valid for.
36-
Auth0 defaults to 30 seconds if not provided.
36+
Auth0 defaults to 300 seconds (5 mins) if not provided.
3737
3838
**kwargs: Other fields to send along with the request.
3939
@@ -56,6 +56,8 @@ def back_channel_login(
5656
data["authorization_details"] = json.dumps(authorization_details)
5757

5858
if requested_expiry is not None:
59+
if not isinstance(requested_expiry, int) or requested_expiry <= 0:
60+
raise ValueError("requested_expiry must be a positive integer")
5961
data["requested_expiry"] = str(requested_expiry)
6062

6163
data.update(kwargs)

auth0/test/authentication/test_back_channel_login.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ def test_ciba(self, mock_post):
3333
},
3434
)
3535

36+
@mock.patch("requests.request")
37+
def test_server_error(self, mock_requests_request):
38+
response = requests.Response()
39+
response.status_code = 400
40+
response._content = b'{"error":"foo"}'
41+
mock_requests_request.return_value = response
42+
43+
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec")
44+
with self.assertRaises(Auth0Error) as context:
45+
g.back_channel_login(
46+
binding_message="msg",
47+
login_hint="hint",
48+
scope="openid"
49+
)
50+
self.assertEqual(context.exception.status_code, 400)
51+
self.assertEqual(context.exception.message, 'foo')
52+
3653
@mock.patch("auth0.rest.RestClient.post")
3754
def test_should_require_binding_message(self, mock_post):
3855
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec")
@@ -161,3 +178,33 @@ def test_with_request_expiry(self, mock_post):
161178
"requested_expiry": "100",
162179
},
163180
)
181+
182+
def test_requested_expiry_negative_raises(self):
183+
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec")
184+
with self.assertRaises(ValueError):
185+
g.back_channel_login(
186+
binding_message="msg",
187+
login_hint="hint",
188+
scope="openid",
189+
requested_expiry=-10
190+
)
191+
192+
def test_requested_expiry_zero_raises(self):
193+
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec")
194+
with self.assertRaises(ValueError):
195+
g.back_channel_login(
196+
binding_message="msg",
197+
login_hint="hint",
198+
scope="openid",
199+
requested_expiry=0
200+
)
201+
202+
def test_requested_non_int_raises(self):
203+
g = BackChannelLogin("my.domain.com", "cid", client_secret="clsec")
204+
with self.assertRaises(ValueError):
205+
g.back_channel_login(
206+
binding_message="msg",
207+
login_hint="hint",
208+
scope="openid",
209+
requested_expiry="string_instead_of_int"
210+
)

auth0/test/authentication/test_get_token.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from cryptography.hazmat.primitives import asymmetric, serialization
88

9+
from ... import Auth0Error
910
from ...authentication.get_token import GetToken
1011

1112

@@ -337,24 +338,23 @@ def test_backchannel_login(self, mock_post):
337338
},
338339
)
339340

340-
@mock.patch("auth0.rest.RestClient.post")
341-
def test_backchannel_login_headers_on_failure(self, mock_post):
341+
@mock.patch("requests.request")
342+
def test_backchannel_login_headers_on_failure(self, mock_requests_request):
342343
response = requests.Response()
343344
response.status_code = 400
344-
response.headers = {"Retry-After": 100}
345+
response.headers = {"Retry-After": "100"}
345346
response._content = b'{"error":"slow_down"}'
346-
mock_post.side_effect = requests.exceptions.HTTPError(response=response)
347+
mock_requests_request.return_value = response
347348

348349
g = GetToken("my.domain.com", "cid", client_secret="csec")
349350

350-
try:
351+
with self.assertRaises(Auth0Error) as context:
351352
g.backchannel_login(
352353
auth_req_id="reqid",
353354
grant_type="urn:openid:params:grant-type:ciba",
354355
)
355-
except requests.exceptions.HTTPError as e:
356-
self.assertEqual(e.response.headers["Retry-After"], 100)
357-
self.assertEqual(e.response.status_code, 400)
356+
self.assertEqual(context.exception.headers["Retry-After"], "100")
357+
self.assertEqual(context.exception.status_code, 400)
358358

359359
@mock.patch("auth0.rest.RestClient.post")
360360
def test_connection_login(self, mock_post):

0 commit comments

Comments
 (0)