Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Programmatic download of valid ZIP files returns HTML responses for certain producer URLs #524

Merged
merged 3 commits into from
Jul 3, 2024
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
14 changes: 12 additions & 2 deletions functions-python/helpers/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from helpers.utils import create_bucket, download_and_get_hash, download_url_content

responses = urllib3_mock.Responses("requests.packages.urllib3")
expected_user_agent = (
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/126.0.0.0 Mobile Safari/537.36"
)


class TestHelpers(unittest.TestCase):
Expand Down Expand Up @@ -91,7 +95,10 @@ def test_download_and_get_hash_auth_type_1(self):
"GET",
url,
preload_content=False,
headers={api_key_parameter_name: credentials},
headers={
"User-Agent": expected_user_agent,
api_key_parameter_name: credentials,
},
)

if os.path.exists(file_path):
Expand Down Expand Up @@ -132,7 +139,10 @@ def test_download_and_get_hash_auth_type_2(self):
)

mock_request.assert_called_with(
"GET", modified_url, preload_content=False, headers={}
"GET",
modified_url,
preload_content=False,
headers={"User-Agent": expected_user_agent},
)

if os.path.exists(file_path):
Expand Down
6 changes: 5 additions & 1 deletion functions-python/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def download_and_get_hash(
ctx.options |= 0x4 # ssl.OP_LEGACY_SERVER_CONNECT

# authentication_type == 1 -> the credentials are passed in the header
headers = {}
headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/126.0.0.0 Mobile Safari/537.36"
}
if authentication_type == 1 and api_key_parameter_name and credentials:
headers[api_key_parameter_name] = credentials

Expand Down
Loading