[Storage] Improve Bad Connection String message (#8471)
* Improve Connection String message * change * add tests * changes * changes
This commit is contained in:
Родитель
3b3a15b4c0
Коммит
94f7022f82
|
@ -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
|
||||
|
|
|
@ -559,5 +559,20 @@ class StorageClientTest(StorageTestCase):
|
|||
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.")
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -401,6 +401,21 @@ class StorageFileClientTest(FileTestCase):
|
|||
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__':
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -458,6 +458,23 @@ class StorageQueueClientTest(StorageTestCase):
|
|||
# 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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче