Skip to content

Commit b1bc7e6

Browse files
committed
Test throttling behavior for user in group
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent cb6f1c6 commit b1bc7e6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

vulnerabilities/tests/test_throttling.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import json
1111

12+
from django.contrib.auth.models import Group
1213
from django.contrib.auth.models import Permission
1314
from django.core.cache import cache
1415
from rest_framework import status
@@ -77,6 +78,16 @@ def setUp(self):
7778
HTTP_AUTHORIZATION=self.th_unrestricted_user_auth
7879
)
7980

81+
# unrestricted throttling for group user
82+
group, _ = Group.objects.get_or_create(name="Test Unrestricted")
83+
group.permissions.add(permission_unrestricted)
84+
85+
self.th_group_user = ApiUser.objects.create_api_user(username="g@mail.com")
86+
self.th_group_user.groups.add(group)
87+
self.th_group_user_auth = f"Token {self.th_group_user.auth_token.key}"
88+
self.th_group_user_csrf_client = APIClient(enforce_csrf_checks=True)
89+
self.th_group_user_csrf_client.credentials(HTTP_AUTHORIZATION=self.th_group_user_auth)
90+
8091
self.csrf_client_anon = APIClient(enforce_csrf_checks=True)
8192
self.csrf_client_anon_1 = APIClient(enforce_csrf_checks=True)
8293

@@ -147,6 +158,17 @@ def test_user_with_unrestricted_perm_throttling(self):
147158
response = self.th_unrestricted_user_csrf_client.get("/api/packages")
148159
self.assertEqual(response.status_code, status.HTTP_200_OK)
149160

161+
def test_user_in_group_with_unrestricted_perm_throttling(self):
162+
simulate_throttle_usage(
163+
url="/api/packages",
164+
client=self.th_group_user_csrf_client,
165+
mock_use_count=20000,
166+
)
167+
168+
# no throttling for user in group with unrestricted perm.
169+
response = self.th_group_user_csrf_client.get("/api/packages")
170+
self.assertEqual(response.status_code, status.HTTP_200_OK)
171+
150172
def test_anon_throttling(self):
151173
simulate_throttle_usage(
152174
url="/api/packages",

0 commit comments

Comments
 (0)