Skip to content

Commit

Permalink
added testcase and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
naviens committed Feb 17, 2025
1 parent a5c4a70 commit 7436100
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 5.0.3
- Fix for Potential n+1 query detected on AuthToken.user

## 5.0.2
- Implement AUTO_REFRESH_MAX_TTL to limit total token lifetime when AUTO_REFRESH = True

Expand Down
13 changes: 13 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ def test_update_token_key(self):
auth_token.token_key,
)

def test_token_auth_n_plus_one(self):
self.assertEqual(AuthToken.objects.count(), 0)
_, token = AuthToken.objects.create(self.user)
rf = APIRequestFactory()
request = rf.get('/')
request.META = {'HTTP_AUTHORIZATION': f'Token {token}'}
with self.assertNumQueries(2):
(self.user, auth_token) = TokenAuthentication().authenticate(request)
self.assertEqual(
token[:CONSTANTS.TOKEN_KEY_LENGTH],
auth_token.token_key,
)

def test_authorization_header_empty(self):
rf = APIRequestFactory()
request = rf.get('/')
Expand Down

0 comments on commit 7436100

Please sign in to comment.