зеркало из
1
0
Форкнуть 0

[Storage] Improve Bad Connection String message (#8471)

* Improve Connection String message

* change

* add tests

* changes

* changes
This commit is contained in:
Rakshith Bhyravabhotla 2019-11-08 14:11:47 -08:00 коммит произвёл GitHub
Родитель 3b3a15b4c0
Коммит 94f7022f82
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 59 добавлений и 9 удалений

Просмотреть файл

@ -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()