diff --git a/cl/tests/utils.py b/cl/tests/utils.py index f4156fbe11..d7bb4973c8 100644 --- a/cl/tests/utils.py +++ b/cl/tests/utils.py @@ -113,6 +113,14 @@ def make_client(user_pk: int) -> AsyncAPIClient: return client +def make_session_client(user_pk: int) -> AsyncAPIClient: + # Use for endpoints that only accept session authentication + user = User.objects.get(pk=user_pk) + client = AsyncAPIClient() + client.force_login(user) + return client + + def get_with_wait( wait: WebDriverWait, locator: tuple[str, str], diff --git a/cl/users/api_views.py b/cl/users/api_views.py index 2e48866b4d..f686f6a3bf 100644 --- a/cl/users/api_views.py +++ b/cl/users/api_views.py @@ -10,6 +10,7 @@ from rest_framework.viewsets import ModelViewSet from cl.api.api_permissions import IsOwner +from cl.api.authentication import ReplicaRoutingSessionAuthentication from cl.api.models import ( Webhook, WebhookEvent, @@ -29,6 +30,8 @@ class WebhooksViewSet(ModelViewSet): permission_classes = [IsAuthenticated, IsOwner] renderer_classes = [JSONRenderer, TemplateHTMLRenderer] + authentication_classes = [ReplicaRoutingSessionAuthentication] + throttle_classes = [] def get_queryset(self): """ @@ -274,6 +277,8 @@ class WebhookEventViewSet(ModelViewSet): permission_classes = [IsAuthenticated, IsOwner] renderer_classes = [TemplateHTMLRenderer] filterset_class = WebhookEventViewFilter + authentication_classes = [ReplicaRoutingSessionAuthentication] + throttle_classes = [] def get_queryset(self): """ diff --git a/cl/users/tests.py b/cl/users/tests.py index bf32b6592f..3575e86e69 100644 --- a/cl/users/tests.py +++ b/cl/users/tests.py @@ -85,7 +85,7 @@ TestCase, ) from cl.tests.utils import MockResponse as MockPostResponse -from cl.tests.utils import make_client +from cl.tests.utils import make_session_client from cl.users.admin import UserAdmin from cl.users.email_handlers import ( add_bcc_random, @@ -3553,8 +3553,8 @@ def setUpTestData(cls): def setUp(self) -> None: self.webhook_path = reverse("webhooks-list") - self.client = make_client(self.user_1.pk) - self.client_2 = make_client(self.user_2.pk) + self.client = make_session_client(self.user_1.pk) + self.client_2 = make_session_client(self.user_2.pk) def tearDown(cls): Webhook.objects.all().delete()