From c91fff997ee9c3cc3cd931e22cdea0695cde2dee Mon Sep 17 00:00:00 2001 From: cka-y Date: Wed, 3 Jul 2024 12:48:15 -0400 Subject: [PATCH 1/3] feat: added user agent to header --- functions-python/helpers/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions-python/helpers/utils.py b/functions-python/helpers/utils.py index 41a4d833a..fab3168b2 100644 --- a/functions-python/helpers/utils.py +++ b/functions-python/helpers/utils.py @@ -100,7 +100,12 @@ 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 From e7ac0a602de97afefa5e224a87fc50d78369eff4 Mon Sep 17 00:00:00 2001 From: cka-y Date: Wed, 3 Jul 2024 12:53:01 -0400 Subject: [PATCH 2/3] fix: lint --- functions-python/helpers/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/functions-python/helpers/utils.py b/functions-python/helpers/utils.py index fab3168b2..b0e508ddc 100644 --- a/functions-python/helpers/utils.py +++ b/functions-python/helpers/utils.py @@ -101,10 +101,9 @@ def download_and_get_hash( # authentication_type == 1 -> the credentials are passed in the header 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' + "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 From e40e26ab0606f507264365b649c8a6835ddb810a Mon Sep 17 00:00:00 2001 From: cka-y Date: Wed, 3 Jul 2024 13:05:06 -0400 Subject: [PATCH 3/3] fix: tests --- functions-python/helpers/tests/test_helpers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/functions-python/helpers/tests/test_helpers.py b/functions-python/helpers/tests/test_helpers.py index 15a6433bc..16826cca7 100644 --- a/functions-python/helpers/tests/test_helpers.py +++ b/functions-python/helpers/tests/test_helpers.py @@ -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): @@ -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): @@ -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):