mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-12-02 13:53:43 +03:00
updated exceptions to raise error if not not handled
This commit is contained in:
parent
241011a353
commit
aaab91f82b
|
@ -555,3 +555,14 @@ class APIBasicTests(TestsMixin, TestCase):
|
||||||
self.assertEqual(['jwt-auth'], list(resp.cookies.keys()))
|
self.assertEqual(['jwt-auth'], list(resp.cookies.keys()))
|
||||||
resp = self.get('/protected-view/')
|
resp = self.get('/protected-view/')
|
||||||
self.assertEquals(resp.status_code, 200)
|
self.assertEquals(resp.status_code, 200)
|
||||||
|
|
||||||
|
@override_settings(REST_USE_JWT=True)
|
||||||
|
def test_blacklisting(self):
|
||||||
|
payload = {
|
||||||
|
"username": self.USERNAME,
|
||||||
|
"password": self.PASS
|
||||||
|
}
|
||||||
|
get_user_model().objects.create_user(self.USERNAME, '', self.PASS)
|
||||||
|
self.post(self.login_url, data=payload, status_code=200)
|
||||||
|
resp = self.post(self.logout_url, status=200)
|
||||||
|
pass
|
||||||
|
|
|
@ -147,18 +147,26 @@ class LogoutView(APIView):
|
||||||
try:
|
try:
|
||||||
token = RefreshToken(request.data['refresh'])
|
token = RefreshToken(request.data['refresh'])
|
||||||
token.blacklist()
|
token.blacklist()
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
response = Response({"detail": _("Refresh token was not included.")},
|
response = Response({"detail": _("Refresh token was not included in request data.")},
|
||||||
status=status.HTTP_401_UNAUTHORIZED)
|
status=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
|
||||||
except TokenError as e:
|
except TokenError as e:
|
||||||
if e.args[0] == 'Token is blacklisted':
|
if hasattr(e, 'args') and 'Token is blacklisted' in e.args:
|
||||||
response = Response({"detail": _("Token is already blacklisted.")},
|
response = Response({"detail": _("Token is already blacklisted.")},
|
||||||
status=status.HTTP_404_NOT_FOUND)
|
status=status.HTTP_404_NOT_FOUND)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
# warn user blacklist is not enabled
|
# warn user blacklist is not enabled
|
||||||
if e.args[0] == "'RefreshToken' object has no attribute 'blacklist'":
|
if hasattr(e, 'args') and "'RefreshToken' object has no attribute 'blacklist'" in e.args:
|
||||||
response = Response({"detail": _("Blacklist is not enabled in INSTALLED_APPS.")},
|
response = Response({"detail": _("Blacklist is not enabled in INSTALLED_APPS.")},
|
||||||
status=status.HTTP_501_NOT_IMPLEMENTED)
|
status=status.HTTP_501_NOT_IMPLEMENTED)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user