mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
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:
parent
973d288eca
commit
7f5ee55f57
2 changed files with 20 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue