Skip to content

Commit 7fa2cb7

Browse files
committed
[NDR-293] Add Eicar to LG E2E test
1 parent b0c6134 commit 7fa2cb7

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

lambdas/tests/e2e/api/test_upload_document_api.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,36 @@ def test_create_document_virus(test_data, snapshot_json):
175175
presign_uri = upload_response["content"][0]["attachment"]["url"]
176176
del upload_response["content"][0]["attachment"]["url"]
177177

178-
sample_pdf_path = os.path.join(os.path.dirname(__file__), "files", "dummy.pdf")
179-
with open(sample_pdf_path, "rb") as f:
180-
files = {"file": f}
181-
presign_response = requests.put(presign_uri, files=files)
182-
assert presign_response.status_code == 200
178+
try:
179+
# Create EICAR file
180+
eicar_path = os.path.join(os.path.dirname(__file__), "files", "eicar.com")
181+
eicar_base64 = "WDVPIVAlQEFQWzRcUFpYNTRQXlkyQ0MpN30kRUlDQVItU1RBTkRBUkQtQU5USVZJUlUtVEVTVC1GSUxFISRIK0gq"
182+
with open(eicar_path, "wb") as f:
183+
f.write(base64.b64decode(eicar_base64))
184+
185+
# Upload EICAR file to presigned URL
186+
with open(eicar_path, "rb") as f:
187+
presign_response = requests.put(presign_uri, files={"file": f})
188+
assert presign_response.status_code == 200
189+
190+
retrieve_url = (
191+
f"https://{API_ENDPOINT}/FhirDocumentReference/{upload_response['id']}"
192+
)
183193

184-
retrieve_url = (
185-
f"https://{API_ENDPOINT}/FhirDocumentReference/{upload_response['id']}"
186-
)
194+
def condition(response_json):
195+
logging.info(response_json)
196+
return response_json.get("docStatus", False) == "cancelled"
187197

188-
def condition(response_json):
189-
logging.info(response_json)
190-
return response_json.get("docStatus", False) == "cancelled"
198+
raw_retrieve_response = fetch_with_retry(retrieve_url, condition)
199+
retrieve_response = raw_retrieve_response.json()
191200

192-
raw_retrieve_response = fetch_with_retry(retrieve_url, condition)
193-
retrieve_response = raw_retrieve_response.json()
201+
assert upload_response == snapshot_json(exclude=paths("id", "date"))
202+
assert retrieve_response == snapshot_json(exclude=paths("id", "date"))
194203

195-
assert upload_response == snapshot_json(exclude=paths("id", "date"))
196-
assert retrieve_response == snapshot_json(exclude=paths("id", "date"))
204+
finally:
205+
# Delete the EICAR file
206+
if os.path.exists(eicar_path):
207+
os.remove(eicar_path)
197208

198209

199210
def test_create_document_does_not_save_raw(test_data):

0 commit comments

Comments
 (0)