Skip to content

Commit

Permalink
Merge pull request #68 from johngian/fix-delegate
Browse files Browse the repository at this point in the history
Fix return value on delegation failure.
  • Loading branch information
johngian committed Dec 2, 2016
2 parents 615d139 + a710f3d commit a77582d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mozilla_django_oidc/contrib/auth0/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ def refresh_id_token(id_token):
}

response = requests.post(delegation_url, data=data)
response.raise_for_status()
return response.json().get('id_token')

if response.status_code == requests.codes.ok:
return response.json().get('id_token')
return None
5 changes: 3 additions & 2 deletions tests/auth0_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Auth0UtilsTestCase(TestCase):
def test_successful_refresh_token(self, mock_post):
"""Test a successful attempt for a refresh id_token."""
mock_response = Mock()
mock_response.status_code = 200
mock_response.json.return_value = {
'id_token': 'foobar'
}
Expand All @@ -27,8 +28,8 @@ def test_successful_refresh_token(self, mock_post):
def test_unsuccessful_attempt(self, mock_post):
"""Test an attempt to get a refresh token that raises an error."""
mock_response = Mock()
mock_response.status_code = 401
http_error = requests.exceptions.HTTPError()
mock_response.raise_for_status.side_effect = http_error
mock_post.return_value = mock_response
with self.assertRaises(Exception):
self.assertEqual(refresh_id_token('token'), None)
self.assertEqual(refresh_id_token('token'), None)

0 comments on commit a77582d

Please sign in to comment.