From 6503cd5c6e1f4eced7e8fd85637bde8217cb473a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mu=C3=B1oz=20C=C3=A1rdenas?= Date: Tue, 12 Jun 2018 12:28:17 +0200 Subject: [PATCH] Fix exception for JWT_AUTH_COOKIE --- oauth2_provider_jwt/authentication.py | 2 +- tests/test_authentication.py | 10 +++++++++- tests/test_views.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/oauth2_provider_jwt/authentication.py b/oauth2_provider_jwt/authentication.py index ce3fce0..57719bc 100644 --- a/oauth2_provider_jwt/authentication.py +++ b/oauth2_provider_jwt/authentication.py @@ -50,7 +50,7 @@ def _get_jwt_value(self, request): auth_header_prefix = getattr(settings, 'JWT_AUTH_HEADER_PREFIX', 'JWT') if not auth: - if settings.JWT_AUTH_COOKIE: + if getattr(settings, 'JWT_AUTH_COOKIE', None): return request.COOKIES.get(settings.JWT_AUTH_COOKIE) return None diff --git a/tests/test_authentication.py b/tests/test_authentication.py index 09effc7..28efdd8 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -11,7 +11,15 @@ class JWTAuthenticationTests(TestCase): def setUp(self): self.client = APIClient(enforce_csrf_checks=True) - def test_get_no_jwt_header_failing_jwt_auth(self): + def test_get_no_jwt_header(self): + """ + If there is no auth, it's part of a different layer if user needs + to be authenticated. That's why we return a positive response. + """ + response = self.client.get('/jwt/') + self.assertEqual(response.status_code, 200) + + def test_get_no_jwt_token_failing_jwt_auth(self): response = self.client.get('/jwt/', HTTP_AUTHORIZATION='JWT') self.assertEqual(response.status_code, 401) self.assertEqual( diff --git a/tests/test_views.py b/tests/test_views.py index 5a915a1..2359018 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -4,7 +4,7 @@ try: from urllib.parse import urlencode except ImportError: - from urllib import urlencode + from urllib import urlencode # noqa try: from unittest.mock import patch except ImportError: