|
9 | 9 |
|
10 | 10 | import json |
11 | 11 |
|
| 12 | +from django.contrib.auth.models import Group |
12 | 13 | from django.contrib.auth.models import Permission |
13 | 14 | from django.core.cache import cache |
14 | 15 | from rest_framework import status |
@@ -77,6 +78,16 @@ def setUp(self): |
77 | 78 | HTTP_AUTHORIZATION=self.th_unrestricted_user_auth |
78 | 79 | ) |
79 | 80 |
|
| 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 | + |
80 | 91 | self.csrf_client_anon = APIClient(enforce_csrf_checks=True) |
81 | 92 | self.csrf_client_anon_1 = APIClient(enforce_csrf_checks=True) |
82 | 93 |
|
@@ -147,6 +158,17 @@ def test_user_with_unrestricted_perm_throttling(self): |
147 | 158 | response = self.th_unrestricted_user_csrf_client.get("/api/packages") |
148 | 159 | self.assertEqual(response.status_code, status.HTTP_200_OK) |
149 | 160 |
|
| 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 | + |
150 | 172 | def test_anon_throttling(self): |
151 | 173 | simulate_throttle_usage( |
152 | 174 | url="/api/packages", |
|
0 commit comments