Fix unit.utils.test_url for Windows

Detect escaped urls in Windows
Unescape urls in Windows
Fix tests to deal with sanitized Windows paths
This commit is contained in:
twangboy 2017-08-17 14:20:25 -06:00
parent 973d288eca
commit 7f5ee55f57
2 changed files with 20 additions and 8 deletions

View file

@ -60,15 +60,15 @@ def is_escaped(url):
'''
test whether `url` is escaped with `|`
'''
if salt.utils.is_windows():
return False
scheme = urlparse(url).scheme
if not scheme:
return url.startswith('|')
elif scheme == 'salt':
path, saltenv = parse(url)
return path.startswith('|')
if salt.utils.is_windows() and '|' in url:
return path.startswith('_')
else:
return path.startswith('|')
else:
return False
@ -100,15 +100,15 @@ def unescape(url):
'''
remove escape character `|` from `url`
'''
if salt.utils.is_windows():
return url
scheme = urlparse(url).scheme
if not scheme:
return url.lstrip('|')
elif scheme == 'salt':
path, saltenv = parse(url)
return create(path.lstrip('|'), saltenv)
if salt.utils.is_windows() and '|' in url:
return create(path.lstrip('_'), saltenv)
else:
return create(path.lstrip('|'), saltenv)
else:
return url

View file

@ -38,6 +38,8 @@ class UrlTestCase(TestCase):
'''
path = '?funny/path with {interesting|chars}'
url = 'salt://' + path
if salt.utils.is_windows():
path = '_funny/path with {interesting_chars}'
self.assertEqual(salt.utils.url.parse(url), (path, None))
@ -48,6 +50,8 @@ class UrlTestCase(TestCase):
saltenv = 'ambience'
path = '?funny/path&with {interesting|chars}'
url = 'salt://' + path + '?saltenv=' + saltenv
if salt.utils.is_windows():
path = '_funny/path&with {interesting_chars}'
self.assertEqual(salt.utils.url.parse(url), (path, saltenv))
@ -59,6 +63,8 @@ class UrlTestCase(TestCase):
'''
path = '? interesting/&path.filetype'
url = 'salt://' + path
if salt.utils.is_windows():
url = 'salt://_ interesting/&path.filetype'
self.assertEqual(salt.utils.url.create(path), url)
@ -68,6 +74,8 @@ class UrlTestCase(TestCase):
'''
saltenv = 'raumklang'
path = '? interesting/&path.filetype'
if salt.utils.is_windows():
path = '_ interesting/&path.filetype'
url = 'salt://' + path + '?saltenv=' + saltenv
@ -149,6 +157,8 @@ class UrlTestCase(TestCase):
'''
path = 'dir/file.conf'
escaped_path = '|' + path
if salt.utils.is_windows():
escaped_path = path
self.assertEqual(salt.utils.url.escape(path), escaped_path)
@ -167,6 +177,8 @@ class UrlTestCase(TestCase):
path = 'dir/file.conf'
url = 'salt://' + path
escaped_url = 'salt://|' + path
if salt.utils.is_windows():
escaped_url = url
self.assertEqual(salt.utils.url.escape(url), escaped_url)