Skip to content
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
2 changes: 1 addition & 1 deletion awscli/botocore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Config:
:type user_agent_appid: str
:param user_agent_appid: A value that gets included in the User-Agent
string in the format "app/<user_agent_appid>". Allowed characters are
ASCII alphanumerics and ``!$%&'*+-.^_`|~``. All other characters will
ASCII alphanumerics and ``!#$%&'*+-.^_`|~``. All other characters will
be replaced by a ``-``.
:type connect_timeout: float or int
Expand Down
7 changes: 4 additions & 3 deletions awscli/botocore/useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,10 @@ def _build_app_id(self):
User-Agent header.
"""
if self._client_config and self._client_config.user_agent_appid:
return [
UserAgentComponent('app', self._client_config.user_agent_appid)
]
appid = sanitize_user_agent_string_component(
raw_str=self._client_config.user_agent_appid, allow_hash=True
)
return [RawStringUserAgentComponent(f'app/{appid}')]
else:
return []

Expand Down
24 changes: 24 additions & 0 deletions tests/unit/botocore/test_useragent.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,27 @@ def test_non_positive_user_agent_component_size_config_raises():
with pytest.raises(ValueError) as excinfo:
UserAgentComponentSizeConfig(-1, ',')
assert 'Invalid `max_size_in_bytes`' in str(excinfo.value)


def test_hash_in_user_agent_appid():
ua = UserAgentString(
platform_name='linux',
platform_version='1.2.3-foo',
platform_machine='x86_64',
python_version='3.8.20',
python_implementation='Dpython',
execution_env='AWS_Lambda_python3.8',
).with_client_config(Config(user_agent_appid='fooapp#1.0.0'))

actual = ua.to_string()
expected = (
f'Botocore/{botocore_version} '
'ua/2.1 '
'os/linux#1.2.3-foo '
'md/arch#x86_64 '
'lang/python#3.8.20 '
'md/pyimpl#Dpython '
'exec-env/AWS_Lambda_python3.8 '
'app/fooapp#1.0.0'
)
assert actual == expected