From 638c2a9e2c9769010893d46e1d4e92aaec38e44d Mon Sep 17 00:00:00 2001 From: Swathi Pillalamarri Date: Thu, 4 Feb 2021 18:05:27 -0500 Subject: [PATCH] strip whitespace around conn str --- .../azure-servicebus/azure/servicebus/_base_handler.py | 2 +- .../tests/test_connection_string_parser.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py index 623c6e20e6e8..560bb289d4c7 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_base_handler.py @@ -59,7 +59,7 @@ def _parse_conn_str(conn_str, check_case=False): shared_access_signature_expiry = None # type: Optional[int] # split connection string into properties - conn_properties = [s.split("=", 1) for s in conn_str.rstrip(";").split(";")] + conn_properties = [s.split("=", 1) for s in conn_str.strip().rstrip(";").split(";")] if any(len(tup) != 2 for tup in conn_properties): raise ValueError("Connection string is either blank or malformed.") conn_settings = dict(conn_properties) # type: ignore diff --git a/sdk/servicebus/azure-servicebus/tests/test_connection_string_parser.py b/sdk/servicebus/azure-servicebus/tests/test_connection_string_parser.py index 5e89eab72377..6877c1171ce4 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_connection_string_parser.py +++ b/sdk/servicebus/azure-servicebus/tests/test_connection_string_parser.py @@ -54,6 +54,14 @@ def test_sb_parse_conn_str_sas(self, **kwargs): assert parse_result.shared_access_signature == 'THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=' assert parse_result.shared_access_key_name == None + def test_sb_parse_conn_str_whitespace_trailing_semicolon(self, **kwargs): + conn_str = ' Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=; ' + parse_result = parse_connection_string(conn_str) + assert parse_result.endpoint == 'sb://resourcename.servicebus.windows.net/' + assert parse_result.fully_qualified_namespace == 'resourcename.servicebus.windows.net' + assert parse_result.shared_access_signature == 'THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=' + assert parse_result.shared_access_key_name == None + def test_sb_parse_conn_str_sas_trailing_semicolon(self, **kwargs): conn_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessSignature=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX=;' parse_result = parse_connection_string(conn_str)