Skip to content

Commit

Permalink
allow conn str to have trailing semicolon, whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
swathipil committed Feb 4, 2021
1 parent 05236dc commit ec0eb20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ 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(";")]
if any(len(tup) != 2 for tup in conn_properties):
conn_settings = [s.split("=", 1) for s in conn_str.strip().rstrip(';').split(";")]
if any(len(tup) != 2 for tup in conn_settings):
raise ValueError("Connection string is either blank or malformed.")
conn_settings = dict(conn_properties) # type: ignore
conn_settings = dict(conn_settings) # type: ignore

# case sensitive check when parsing for connection string properties
if check_case:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def test_sb_parse_conn_str_sas_trailing_semicolon(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_no_keyname(self, **kwargs):
conn_str = 'Endpoint=sb://resourcename.servicebus.windows.net/;SharedAccessKey=THISISATESTKEYXXXXXXXXXXXXXXXXXXXXXXXXXXXX='
with pytest.raises(ValueError) as e:
Expand Down
2 changes: 1 addition & 1 deletion sdk/servicebus/azure-servicebus/tests/test_sb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_client_sas_credential(self,
token = credential.get_token(auth_uri).token

# Finally let's do it with SAS token + conn str
token_conn_str = "Endpoint=sb://{}/;SharedAccessSignature={};".format(hostname, token.decode())
token_conn_str = "Endpoint=sb://{}/;SharedAccessSignature={}".format(hostname, token.decode())

client = ServiceBusClient.from_connection_string(token_conn_str)
with client:
Expand Down

0 comments on commit ec0eb20

Please sign in to comment.