@@ -834,8 +834,16 @@ async def test_download_md5_mismatch_local_file(self) -> None:
834834 assert not mocked_remove .called
835835
836836 async def test_download_expired_url (self , syn : Synapse ) -> None :
837- url = "http://www.ayy.lmao/filerino.txt?Expires=0"
838- new_url = "http://www.ayy.lmao/new_url.txt?Expires=1715000000"
837+ url = (
838+ "http://www.ayy.lmao/filerino.txt?Expires=0"
839+ "X-Amz-Date=20240509T180000Z"
840+ "&X-Amz-Expires=1000"
841+ )
842+ new_url = (
843+ "http://www.ayy.lmao/new_url.txt?Expires=1715000000"
844+ "X-Amz-Date=20240509T180000Z"
845+ "&X-Amz-Expires=1000"
846+ )
839847 contents = "\n " .join (str (i ) for i in range (1000 ))
840848 temp_destination = os .path .normpath (
841849 os .path .expanduser ("~/fake/path/filerino.txt.temp" )
@@ -899,6 +907,70 @@ async def test_download_expired_url(self, syn: Synapse) -> None:
899907 auth = None ,
900908 )
901909
910+ async def test_download_no_aws_expiration (self , syn : Synapse ) -> None :
911+ url = "http://www.ayy.lmao/filerino.txt?Expires=0"
912+ contents = "\n " .join (str (i ) for i in range (1000 ))
913+ temp_destination = os .path .normpath (
914+ os .path .expanduser ("~/fake/path/filerino.txt.temp" )
915+ )
916+ destination = os .path .normpath (os .path .expanduser ("~/fake/path/filerino.txt" ))
917+
918+ mock_requests_get = MockRequestGetFunction (
919+ [
920+ create_mock_response (
921+ url ,
922+ "stream" ,
923+ contents = contents ,
924+ buffer_size = 1024 ,
925+ partial_end = len (contents ),
926+ status_code = 200 ,
927+ ),
928+ ]
929+ )
930+ with patch .object (
931+ syn ._requests_session , "get" , side_effect = mock_requests_get
932+ ) as mocked_get , patch (
933+ "synapseclient.core.download.download_functions._pre_signed_url_expiration_time" ,
934+ return_value = datetime .datetime (1900 , 1 , 1 , tzinfo = datetime .timezone .utc ),
935+ ) as mocked_pre_signed_url_expiration_time , patch (
936+ "synapseclient.core.download.download_functions.get_file_handle_for_download" ,
937+ ) as mocked_get_file_handle_for_download , patch .object (
938+ Synapse , "_generate_headers" , side_effect = mock_generate_headers
939+ ), patch .object (
940+ utils , "temp_download_filename" , return_value = temp_destination
941+ ), patch (
942+ "synapseclient.core.download.download_functions.open" ,
943+ new_callable = mock_open (),
944+ create = True ,
945+ ), patch .object (
946+ hashlib , "new"
947+ ) as mocked_hashlib_new , patch .object (
948+ shutil , "move"
949+ ), patch .object (
950+ os , "remove"
951+ ):
952+ mocked_hashlib_new .return_value .hexdigest .return_value = "fake md5 is fake"
953+ # WHEN I call download_from_url with an expired url
954+ download_from_url (
955+ url = url ,
956+ destination = destination ,
957+ entity_id = OBJECT_ID ,
958+ file_handle_associate_type = OBJECT_TYPE ,
959+ expected_md5 = "fake md5 is fake" ,
960+ )
961+ # I expect the expired url to be identified
962+ mocked_pre_signed_url_expiration_time .assert_not_called ()
963+ # AND I expect the URL to be refreshed
964+ mocked_get_file_handle_for_download .assert_not_called ()
965+ # AND I expect the download to be retried with the new URL
966+ mocked_get .assert_called_with (
967+ url = url ,
968+ headers = mock_generate_headers (self ),
969+ stream = True ,
970+ allow_redirects = False ,
971+ auth = None ,
972+ )
973+
902974 async def test_download_url_no_expiration (self , syn : Synapse ) -> None :
903975 url = "http://www.ayy.lmao/filerino.txt"
904976 contents = "\n " .join (str (i ) for i in range (1000 ))
0 commit comments