Skip to content

Commit

Permalink
adds no AWS expiration unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
BWMac committed Sep 27, 2024
1 parent 79908ce commit ab62549
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/unit/synapseclient/core/unit_test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,70 @@ async def test_download_expired_url(self, syn: Synapse) -> None:
auth=None,
)

async def test_download_no_aws_expiration(self, syn: Synapse) -> None:
url = "http://www.ayy.lmao/filerino.txt?Expires=0"
contents = "\n".join(str(i) for i in range(1000))
temp_destination = os.path.normpath(
os.path.expanduser("~/fake/path/filerino.txt.temp")
)
destination = os.path.normpath(os.path.expanduser("~/fake/path/filerino.txt"))

mock_requests_get = MockRequestGetFunction(
[
create_mock_response(
url,
"stream",
contents=contents,
buffer_size=1024,
partial_end=len(contents),
status_code=200,
),
]
)
with patch.object(
syn._requests_session, "get", side_effect=mock_requests_get
) as mocked_get, patch(
"synapseclient.core.download.download_functions._pre_signed_url_expiration_time",
return_value=datetime.datetime(1900, 1, 1, tzinfo=datetime.timezone.utc),
) as mocked_pre_signed_url_expiration_time, patch(
"synapseclient.core.download.download_functions.get_file_handle_for_download",
) as mocked_get_file_handle_for_download, patch.object(
Synapse, "_generate_headers", side_effect=mock_generate_headers
), patch.object(
utils, "temp_download_filename", return_value=temp_destination
), patch(
"synapseclient.core.download.download_functions.open",
new_callable=mock_open(),
create=True,
), patch.object(
hashlib, "new"
) as mocked_hashlib_new, patch.object(
shutil, "move"
), patch.object(
os, "remove"
):
mocked_hashlib_new.return_value.hexdigest.return_value = "fake md5 is fake"
# WHEN I call download_from_url with an expired url
download_from_url(
url=url,
destination=destination,
entity_id=OBJECT_ID,
file_handle_associate_type=OBJECT_TYPE,
expected_md5="fake md5 is fake",
)
# I expect the expired url to be identified
mocked_pre_signed_url_expiration_time.assert_not_called()
# AND I expect the URL to be refreshed
mocked_get_file_handle_for_download.assert_not_called()
# AND I expect the download to be retried with the new URL
mocked_get.assert_called_with(
url=url,
headers=mock_generate_headers(self),
stream=True,
allow_redirects=False,
auth=None,
)

async def test_download_url_no_expiration(self, syn: Synapse) -> None:
url = "http://www.ayy.lmao/filerino.txt"
contents = "\n".join(str(i) for i in range(1000))
Expand Down

0 comments on commit ab62549

Please sign in to comment.