File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ class Config:
4141 :type user_agent_appid: str
4242 :param user_agent_appid: A value that gets included in the User-Agent
4343 string in the format "app/<user_agent_appid>". Allowed characters are
44- ASCII alphanumerics and ``!$%&'*+-.^_`|~``. All other characters will
44+ ASCII alphanumerics and ``!# $%&'*+-.^_`|~``. All other characters will
4545 be replaced by a ``-``.
4646
4747 :type connect_timeout: float or int
Original file line number Diff line number Diff line change @@ -608,9 +608,10 @@ def _build_app_id(self):
608608 User-Agent header.
609609 """
610610 if self ._client_config and self ._client_config .user_agent_appid :
611- return [
612- UserAgentComponent ('app' , self ._client_config .user_agent_appid )
613- ]
611+ appid = sanitize_user_agent_string_component (
612+ raw_str = self ._client_config .user_agent_appid , allow_hash = True
613+ )
614+ return [RawStringUserAgentComponent (f'app/{ appid } ' )]
614615 else :
615616 return []
616617
Original file line number Diff line number Diff line change @@ -252,3 +252,27 @@ def test_non_positive_user_agent_component_size_config_raises():
252252 with pytest .raises (ValueError ) as excinfo :
253253 UserAgentComponentSizeConfig (- 1 , ',' )
254254 assert 'Invalid `max_size_in_bytes`' in str (excinfo .value )
255+
256+
257+ def test_hash_in_user_agent_appid ():
258+ ua = UserAgentString (
259+ platform_name = 'linux' ,
260+ platform_version = '1.2.3-foo' ,
261+ platform_machine = 'x86_64' ,
262+ python_version = '3.8.20' ,
263+ python_implementation = 'Dpython' ,
264+ execution_env = 'AWS_Lambda_python3.8' ,
265+ ).with_client_config (Config (user_agent_appid = 'fooapp#1.0.0' ))
266+
267+ actual = ua .to_string ()
268+ expected = (
269+ f'Botocore/{ botocore_version } '
270+ 'ua/2.1 '
271+ 'os/linux#1.2.3-foo '
272+ 'md/arch#x86_64 '
273+ 'lang/python#3.8.20 '
274+ 'md/pyimpl#Dpython '
275+ 'exec-env/AWS_Lambda_python3.8 '
276+ 'app/fooapp#1.0.0'
277+ )
278+ assert actual == expected
You can’t perform that action at this time.
0 commit comments