-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the number of request/response pairs returned by the API configu…
…rable (#9967) * limit req response via setting * add unittest * update running test documentation * also must do here * fix linting, add urls.py * trailing space in a comment... * switch back to finding - different test uses it * change test data to not break * reset data, use my own * Update dojo/settings/settings.dist.py Co-authored-by: Charles Neill <[email protected]> --------- Co-authored-by: Charles Neill <[email protected]>
- Loading branch information
1 parent
3a25a44
commit 65bc290
Showing
8 changed files
with
1,177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from rest_framework.test import APITestCase, APIClient | ||
from django.urls import reverse | ||
from rest_framework.authtoken.models import Token | ||
from django.conf import settings | ||
|
||
|
||
class APILimitReqRespPairsTest(APITestCase): | ||
""" | ||
Test the MAX_REQRESP_FROM_API setting for /api/v2/findings/{id}/request_response/ | ||
""" | ||
|
||
fixtures = ['unit_limit_reqresp.json'] | ||
|
||
def setUp(self: object): | ||
token = Token.objects.get(user__username='admin') | ||
self.client = APIClient() | ||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) | ||
|
||
def assertReqrespValue(self: object, value: int, expect_notequal: bool = False) -> None: | ||
settings.MAX_REQRESP_FROM_API = value | ||
r = self.client.get(reverse('finding-list'), format='json') | ||
results = r.json()['results'] | ||
# get finding with id 8 | ||
finding = self.getFinding(8, results) | ||
if expect_notequal: | ||
self.assertNotEqual(len(finding['request_response']['req_resp']), value) | ||
else: | ||
self.assertEqual(len(finding['request_response']['req_resp']), value) | ||
|
||
def getFinding(self: object, idn: int, results: list) -> dict: | ||
for result in results: | ||
if result['id'] == idn: | ||
return result | ||
return None | ||
|
||
def test_reqresp(self: object) -> None: | ||
self.assertReqrespValue(5) | ||
self.assertReqrespValue(10) | ||
self.assertReqrespValue(18) # actual number of reqresp | ||
self.assertReqrespValue(100, True) # more than the number in the request | ||
self.assertReqrespValue(-1, True) # default value of MAX_REQRESP_FROM_API | ||
self.assertReqrespValue(-100, True) # crazy negative value |