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
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ def format_shared_key_credential(account, credential):

def parse_connection_str(conn_str, credential, service):
conn_str = conn_str.rstrip(";")
conn_settings = dict( # pylint: disable=consider-using-dict-comprehension
[s.split("=", 1) for s in conn_str.split(";")]
)
conn_settings = [s.split("=", 1) for s in conn_str.split(";")]
if any(len(tup) != 2 for tup in conn_settings):
raise ValueError("Connection string is either blank or malformed.")
conn_settings = dict(conn_settings)
endpoints = _SERVICE_PARAMS[service]
primary = None
secondary = None
Expand Down
15 changes: 15 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_blob_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,5 +559,20 @@ def callback(response):
custom_headers = {'User-Agent': 'customer_user_agent'}
service.get_service_properties(raw_response_hook=callback, headers=custom_headers)

def test_error_with_malformed_conn_str(self):
# Arrange
for conn_str in ["", "foobar", "foo;bar;baz", ";", "foobar=baz=foo" , "foo=;bar=;", "=", "=;=="]:
for service_type in SERVICES.items():
# Act
with self.assertRaises(ValueError) as e:
service = service_type[0].from_connection_string(conn_str, blob_name="test", container_name="foo/bar")

if conn_str in("", "foobar", "foo;bar;baz", ";"):
self.assertEqual(
str(e.exception), "Connection string is either blank or malformed.")
elif conn_str in ("foobar=baz=foo" , "foo=;bar=;", "=", "=;=="):
self.assertEqual(
str(e.exception), "Connection string missing required connection details.")


# ------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ def format_shared_key_credential(account, credential):

def parse_connection_str(conn_str, credential, service):
conn_str = conn_str.rstrip(";")
conn_settings = dict( # pylint: disable=consider-using-dict-comprehension
[s.split("=", 1) for s in conn_str.split(";")]
)
conn_settings = [s.split("=", 1) for s in conn_str.split(";")]
if any(len(tup) != 2 for tup in conn_settings):
raise ValueError("Connection string is either blank or malformed.")
conn_settings = dict(conn_settings)
endpoints = _SERVICE_PARAMS[service]
primary = None
secondary = None
Expand Down
15 changes: 15 additions & 0 deletions sdk/storage/azure-storage-file-share/tests/test_file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,21 @@ def callback(response):
custom_headers = {'User-Agent': 'customer_user_agent'}
service.get_service_properties(raw_response_hook=callback, headers=custom_headers)

def test_error_with_malformed_conn_str(self):
# Arrange

for conn_str in ["", "foobar", "foobar=baz=foo", "foo;bar;baz", "foo=;bar=;", "=", ";", "=;=="]:
for service_type in SERVICES.items():
# Act
with self.assertRaises(ValueError) as e:
service = service_type[0].from_connection_string(conn_str, share_name="test", directory_path="foo/bar", file_path="temp/dat")

if conn_str in("", "foobar", "foo;bar;baz", ";"):
self.assertEqual(
str(e.exception), "Connection string is either blank or malformed.")
elif conn_str in ("foobar=baz=foo" , "foo=;bar=;", "=", "=;=="):
self.assertEqual(
str(e.exception), "Connection string missing required connection details.")

# ------------------------------------------------------------------------------
if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,10 @@ def format_shared_key_credential(account, credential):

def parse_connection_str(conn_str, credential, service):
conn_str = conn_str.rstrip(";")
conn_settings = dict( # pylint: disable=consider-using-dict-comprehension
[s.split("=", 1) for s in conn_str.split(";")]
)
conn_settings = [s.split("=", 1) for s in conn_str.split(";")]
if any(len(tup) != 2 for tup in conn_settings):
raise ValueError("Connection string is either blank or malformed.")
conn_settings = dict(conn_settings)
endpoints = _SERVICE_PARAMS[service]
primary = None
secondary = None
Expand Down
17 changes: 17 additions & 0 deletions sdk/storage/azure-storage-queue/tests/test_queue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@ def test_create_queue_client_with_complete_queue_url(self, resource_group, locat
# Assert
self.assertEqual(service.scheme, 'https')
self.assertEqual(service.queue_name, 'bar')

def test_error_with_malformed_conn_str(self):
# Arrange

for conn_str in ["", "foobar", "foobar=baz=foo", "foo;bar;baz", "foo=;bar=;", "=", ";", "=;=="]:
for service_type in SERVICES.items():
# Act
with self.assertRaises(ValueError) as e:
service = service_type[0].from_connection_string(conn_str, queue_name="test")

if conn_str in("", "foobar", "foo;bar;baz", ";"):
self.assertEqual(
str(e.exception), "Connection string is either blank or malformed.")
elif conn_str in ("foobar=baz=foo" , "foo=;bar=;", "=", "=;=="):
self.assertEqual(
str(e.exception), "Connection string missing required connection details.")

# ------------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()