mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-13 10:28:11 -04:00
Add before_request check for request size
The test checks various routes to ensure that request above our threshold fail before any other processing happens
This commit is contained in:
36
tests/app/test_request_size.py
Normal file
36
tests/app/test_request_size.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
import json
|
||||
|
||||
@pytest.mark.parametrize('endpoint, max_content_length, expected_status_code', [
|
||||
("/_status", 5*1024*1024, 413),
|
||||
("/provider-details", 5*1024*1024, 413),
|
||||
("/v2/notifications/email", 5*1024*1024, 413),
|
||||
|
||||
("/_status", None, 200),
|
||||
("/provider-details", None, 405),
|
||||
("/v2/notifications/email", None, 401),
|
||||
])
|
||||
def test_request_status_when_content_length_is_set(
|
||||
notify_api,
|
||||
sample_email_template_with_placeholders,
|
||||
mocker,
|
||||
endpoint,
|
||||
max_content_length,
|
||||
expected_status_code):
|
||||
|
||||
notify_api.config['MAX_CONTENT_LENGTH'] = max_content_length
|
||||
large_name = "J" * (max_content_length or 1 + 1)
|
||||
data = {
|
||||
'email_address': 'ok@ok.com',
|
||||
'template_id': str(sample_email_template_with_placeholders.id),
|
||||
'personalisation': {
|
||||
'name': large_name
|
||||
}
|
||||
}
|
||||
with notify_api.test_client() as client:
|
||||
response = client.post(
|
||||
path=endpoint,
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json')])
|
||||
|
||||
assert response.status_code == expected_status_code
|
||||
Reference in New Issue
Block a user