mirror of
https://github.com/sissbruecker/linkding.git
synced 2026-02-27 22:43:15 +08:00
29 lines
969 B
Python
29 lines
969 B
Python
from django.urls import reverse
|
|
from rest_framework import status
|
|
|
|
from bookmarks.tests.helpers import BookmarkFactoryMixin, LinkdingApiTestCase
|
|
|
|
|
|
class AuthApiTestCase(LinkdingApiTestCase, BookmarkFactoryMixin):
|
|
def authenticate(self, keyword):
|
|
self.api_token = self.setup_api_token()
|
|
self.client.credentials(HTTP_AUTHORIZATION=f"{keyword} {self.api_token.key}")
|
|
|
|
def test_auth_with_token_keyword(self):
|
|
self.authenticate("Token")
|
|
|
|
url = reverse("linkding:user-profile")
|
|
self.get(url, expected_status_code=status.HTTP_200_OK)
|
|
|
|
def test_auth_with_bearer_keyword(self):
|
|
self.authenticate("Bearer")
|
|
|
|
url = reverse("linkding:user-profile")
|
|
self.get(url, expected_status_code=status.HTTP_200_OK)
|
|
|
|
def test_auth_with_unknown_keyword(self):
|
|
self.authenticate("Key")
|
|
|
|
url = reverse("linkding:user-profile")
|
|
self.get(url, expected_status_code=status.HTTP_401_UNAUTHORIZED)
|