Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions api/src/legacy_soap_api/legacy_soap_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,16 @@ def write_debug_data_to_s3(soap_request: SOAPRequest | None, soap_response: SOAP
base_path,
"response.txt",
)
file_util.write_to_file(
response_s3_path,
soap_response.to_bytes().decode("utf-8"),
content_type=text_content_type,
)
if soap_request and soap_request.operation_name == "GetApplicationZipRequest":
logger.info(
"soap_client: response is not currently being logged to s3",
)
else:
file_util.write_to_file(
response_s3_path,
soap_response.to_bytes().decode("utf-8"),
content_type=text_content_type,
)
response_headers_s3_path = file_util.join(
base_path,
"response_headers.txt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,54 @@ def test_write_debug_data_to_s3(
)


def test_write_debug_data_to_s3_does_not_write_get_application_zip_response(
app,
caplog,
db_session,
enable_factory_create,
monkeypatch,
mock_s3_bucket,
s3_config,
) -> None:
test_uuid = uuid.uuid4()
soap_api_config.get_soap_config.cache_clear()
monkeypatch.setenv("SAVE_SOAP_MESSAGES_TO_S3", "true")
caplog.set_level(logging.INFO)
soap_legacy_response = SOAPResponse(
data=SOAP_LEGACY_RESPONSE_PAYLOAD, status_code=200, headers={"xyz": "abc"}
)
soap_request = create_soap_request(SOAP_PAYLOAD, operation_name="GetApplicationZipRequest")
with app.test_request_context("/"):
flask.g.internal_request_id = test_uuid
write_debug_data_to_s3(soap_request, soap_legacy_response)
request_contents = file_util.read_file(
f"s3://local-mock-draft-bucket/soap-debug/{test_uuid}/request.txt"
)
response_headers_contents = file_util.read_file(
f"s3://local-mock-draft-bucket/soap-debug/{test_uuid}/response_headers.txt"
)
request_headers_contents = file_util.read_file(
f"s3://local-mock-draft-bucket/soap-debug/{test_uuid}/request_headers.txt"
)
assert request_contents.replace("\n", "") == SOAP_PAYLOAD.decode().replace("\n", "")
assert not file_util.file_exists(
f"s3://local-mock-draft-bucket/soap-debug/{test_uuid}/response.txt"
)
record = next(
r
for r in caplog.records
if r.message == "soap_client: response is not currently being logged to s3"
)
assert record
assert response_headers_contents.replace("\r", "") == json.dumps({"xyz": "abc"})
assert request_headers_contents.replace("\r", "") == json.dumps(
{
"X-Gg-S2S-Uri": "https://google.com/xyz",
"Soapaction": f"{GRANTOR_SOAP_ACTION_PATH}/GetApplicationZip",
}
)


def test_write_debug_data_to_s3_handles_a_null_soap_request(
app,
caplog,
Expand Down Expand Up @@ -176,6 +224,7 @@ def test_write_debug_data_to_s3_runs_on_any_endpoint(
create_soap_request(SOAP_PAYLOAD, operation_name="GetSubmissionListRequest"),
soap_legacy_response,
)
# Note: Response will not be written for GetApplicationZip
write_debug_data_to_s3(
create_soap_request(SOAP_PAYLOAD, operation_name="GetApplicationZipRequest"),
soap_legacy_response,
Expand All @@ -195,7 +244,7 @@ def test_write_debug_data_to_s3_runs_on_any_endpoint(
create_soap_request(SOAP_PAYLOAD, operation_name="Y"), soap_legacy_response
)
objects = s3_client.list_objects_v2(Bucket="local-mock-draft-bucket")
assert len(objects.get("Contents")) == 28
assert len(objects.get("Contents")) == 27


def test_get_internal_request_id_returns_flask_internal_request_id_if_in_context(app):
Expand Down
Loading