From 87809c46c167acfc9a34043abe15da5724c739e6 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 24 Sep 2021 17:05:47 +0300 Subject: [PATCH] Fix breaking PBA file upload unit tests on windows. The tests broke because `get` endpoint opened up the file handle which was not closed anywhere. The delete endpoint couldn't delete the file, since a process was using it. --- .../monkey_island/cc/resources/test_pba_file_upload.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py index c06f0c400..3dfad70a7 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_pba_file_upload.py @@ -92,16 +92,19 @@ def test_pba_file_upload_endpoint( content_type="multipart/form-data; " "boundary=---------------------------" "1", follow_redirects=True, ) + resp_get = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py") + assert resp_get.status_code == 200 + assert resp_get.data.decode() == "m0nk3y" + # Closing the response closes the file handle, else it can't be deleted + resp_get.close() + resp_delete = flask_client.delete( f"/api/fileUpload/{pba_os}", data="test.py", content_type="text/plain;" ) resp_get_del = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py") assert resp_post.status_code == 200 - assert resp_get.status_code == 200 - assert resp_get.data.decode() == "m0nk3y" - assert resp_delete.status_code == 200 assert resp_get_del.status_code == 404