mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 18:37:33 -04:00
Send upload_id to Template Preview for logging
This means we can include the anonymous ID for the file in the log we have about Type3 fonts [1]. Currently, we have no way of tracing manually uploaded files with this potential defect. [1]: https://github.com/alphagov/notifications-template-preview/pull/557
This commit is contained in:
@@ -182,6 +182,7 @@ def upload_letter(service_id):
|
|||||||
try:
|
try:
|
||||||
response = sanitise_letter(
|
response = sanitise_letter(
|
||||||
BytesIO(pdf_file_bytes),
|
BytesIO(pdf_file_bytes),
|
||||||
|
upload_id=upload_id,
|
||||||
allow_international_letters=current_service.has_permission(
|
allow_international_letters=current_service.has_permission(
|
||||||
'international_letters'
|
'international_letters'
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -94,11 +94,12 @@ def get_page_count_for_letter(template, values=None):
|
|||||||
return page_count
|
return page_count
|
||||||
|
|
||||||
|
|
||||||
def sanitise_letter(pdf_file, *, allow_international_letters):
|
def sanitise_letter(pdf_file, *, upload_id, allow_international_letters):
|
||||||
return requests.post(
|
return requests.post(
|
||||||
'{}/precompiled/sanitise?allow_international_letters={}'.format(
|
'{}/precompiled/sanitise?allow_international_letters={}&upload_id={}'.format(
|
||||||
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
|
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
|
||||||
'true' if allow_international_letters else 'false',
|
'true' if allow_international_letters else 'false',
|
||||||
|
upload_id,
|
||||||
),
|
),
|
||||||
data=pdf_file,
|
data=pdf_file,
|
||||||
headers={'Authorization': 'Token {}'.format(current_app.config['TEMPLATE_PREVIEW_API_KEY'])}
|
headers={'Authorization': 'Token {}'.format(current_app.config['TEMPLATE_PREVIEW_API_KEY'])}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ def test_post_upload_letter_redirects_for_valid_file(
|
|||||||
mock_sanitise.assert_called_once_with(
|
mock_sanitise.assert_called_once_with(
|
||||||
ANY,
|
ANY,
|
||||||
allow_international_letters=expected_allow_international,
|
allow_international_letters=expected_allow_international,
|
||||||
|
upload_id=ANY,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert 'The Queen' in page.find('div', class_='js-stick-at-bottom-when-scrolling').text
|
assert 'The Queen' in page.find('div', class_='js-stick-at-bottom-when-scrolling').text
|
||||||
|
|||||||
@@ -164,18 +164,27 @@ def test_from_example_template_makes_request(mocker):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('allow_international_letters, expected_url', (
|
@pytest.mark.parametrize('allow_international_letters, query_param_value', [
|
||||||
(False, 'http://localhost:9999/precompiled/sanitise?allow_international_letters=false'),
|
[False, "false"],
|
||||||
(True, 'http://localhost:9999/precompiled/sanitise?allow_international_letters=true'),
|
[True, "true"]
|
||||||
))
|
])
|
||||||
def test_sanitise_letter_calls_template_preview_sanitise_endoint_with_file(
|
def test_sanitise_letter_calls_template_preview_sanitise_endoint_with_file(
|
||||||
mocker,
|
mocker,
|
||||||
allow_international_letters,
|
allow_international_letters,
|
||||||
expected_url,
|
query_param_value,
|
||||||
|
fake_uuid,
|
||||||
):
|
):
|
||||||
request_mock = mocker.patch('app.template_previews.requests.post')
|
request_mock = mocker.patch('app.template_previews.requests.post')
|
||||||
|
|
||||||
sanitise_letter('pdf_data', allow_international_letters=allow_international_letters)
|
sanitise_letter(
|
||||||
|
'pdf_data',
|
||||||
|
upload_id=fake_uuid,
|
||||||
|
allow_international_letters=allow_international_letters
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_url = f'http://localhost:9999/precompiled/sanitise' \
|
||||||
|
f'?allow_international_letters={query_param_value}' \
|
||||||
|
f'&upload_id={fake_uuid}'
|
||||||
|
|
||||||
request_mock.assert_called_once_with(
|
request_mock.assert_called_once_with(
|
||||||
expected_url,
|
expected_url,
|
||||||
|
|||||||
Reference in New Issue
Block a user