mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-08 19:28:29 +02:00
Allow providing REST API authentication token with Bearer keyword (#995)
This commit is contained in:
32
bookmarks/tests/test_auth_api.py
Normal file
32
bookmarks/tests/test_auth_api.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.authtoken.models import Token
|
||||
|
||||
from bookmarks.tests.helpers import LinkdingApiTestCase, BookmarkFactoryMixin
|
||||
|
||||
|
||||
class AuthApiTestCase(LinkdingApiTestCase, BookmarkFactoryMixin):
|
||||
|
||||
def authenticate(self, keyword):
|
||||
self.api_token = Token.objects.get_or_create(
|
||||
user=self.get_or_create_test_user()
|
||||
)[0]
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"{keyword} {self.api_token.key}")
|
||||
|
||||
def test_auth_with_token_keyword(self):
|
||||
self.authenticate("Token")
|
||||
|
||||
url = reverse("bookmarks:user-profile")
|
||||
self.get(url, expected_status_code=status.HTTP_200_OK)
|
||||
|
||||
def test_auth_with_bearer_keyword(self):
|
||||
self.authenticate("Bearer")
|
||||
|
||||
url = reverse("bookmarks:user-profile")
|
||||
self.get(url, expected_status_code=status.HTTP_200_OK)
|
||||
|
||||
def test_auth_with_unknown_keyword(self):
|
||||
self.authenticate("Key")
|
||||
|
||||
url = reverse("bookmarks:user-profile")
|
||||
self.get(url, expected_status_code=status.HTTP_401_UNAUTHORIZED)
|
Reference in New Issue
Block a user