From b5ed5c8f947785d038d6e4f7b0ad5d6b9b10ca98 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Wed, 18 Jan 2023 10:05:47 -0500 Subject: [PATCH] chore: add additional logging to JWT auth middleware authenticate_credentials (#292) --- CHANGELOG.rst | 8 ++++++++ edx_rest_framework_extensions/__init__.py | 2 +- edx_rest_framework_extensions/auth/jwt/authentication.py | 2 +- .../auth/jwt/tests/test_authentication.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f4e829ae..33b2287f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,14 @@ Change Log Unreleased ---------- +[8.4.1] - 2022-12-18 +-------------------- + +Added +~~~~~ + +* Additional logging in `authenticate_credentials` within the JWT authentication middleware for debugging purposes. + [8.4.0] - 2022-12-16 -------------------- diff --git a/edx_rest_framework_extensions/__init__.py b/edx_rest_framework_extensions/__init__.py index 166a2448..736ee77e 100644 --- a/edx_rest_framework_extensions/__init__.py +++ b/edx_rest_framework_extensions/__init__.py @@ -1,3 +1,3 @@ """ edx Django REST Framework extensions. """ -__version__ = '8.4.0' # pragma: no cover +__version__ = '8.4.1' # pragma: no cover diff --git a/edx_rest_framework_extensions/auth/jwt/authentication.py b/edx_rest_framework_extensions/auth/jwt/authentication.py index 1c40556a..462b2b7f 100644 --- a/edx_rest_framework_extensions/auth/jwt/authentication.py +++ b/edx_rest_framework_extensions/auth/jwt/authentication.py @@ -148,7 +148,7 @@ def authenticate_credentials(self, payload): if attributes_updated: user.save() except Exception as authentication_error: - msg = 'User retrieval failed.' + msg = f'[edx-drf-extensions] User retrieval failed for username {username}.' logger.exception(msg) raise exceptions.AuthenticationFailed(msg) from authentication_error diff --git a/edx_rest_framework_extensions/auth/jwt/tests/test_authentication.py b/edx_rest_framework_extensions/auth/jwt/tests/test_authentication.py index 40e09e94..96c3a2a9 100644 --- a/edx_rest_framework_extensions/auth/jwt/tests/test_authentication.py +++ b/edx_rest_framework_extensions/auth/jwt/tests/test_authentication.py @@ -167,7 +167,7 @@ def test_authenticate_credentials_user_retrieval_failed(self): JwtAuthentication().authenticate_credentials, {'username': 'test', 'email': 'test@example.com'} ) - logger.assert_called_with('User retrieval failed.') + logger.assert_called_with('[edx-drf-extensions] User retrieval failed for username test.') def test_authenticate_credentials_no_usernames(self): """ Verify an AuthenticationFailed exception is raised if the payload contains no username claim. """