mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Treat empty whitelist/blacklist as no whitelist/blacklist
This commit is contained in:
parent
bcccaf2621
commit
ca936de372
2 changed files with 117 additions and 10 deletions
|
@ -361,7 +361,8 @@ def check_whitelist_blacklist(value, whitelist=None, blacklist=None):
|
|||
in the blacklist, then the whitelist is checked. If the value isn't
|
||||
found in the whitelist, the function returns ``False``.
|
||||
'''
|
||||
if blacklist is not None:
|
||||
# Normalize the input so that we have a list
|
||||
if blacklist:
|
||||
if isinstance(blacklist, six.string_types):
|
||||
blacklist = [blacklist]
|
||||
if not hasattr(blacklist, '__iter__'):
|
||||
|
@ -370,11 +371,10 @@ def check_whitelist_blacklist(value, whitelist=None, blacklist=None):
|
|||
type(blacklist).__name__, blacklist
|
||||
)
|
||||
)
|
||||
for expr in blacklist:
|
||||
if expr_match(value, expr):
|
||||
return False
|
||||
else:
|
||||
blacklist = []
|
||||
|
||||
if whitelist is not None:
|
||||
if whitelist:
|
||||
if isinstance(whitelist, six.string_types):
|
||||
whitelist = [whitelist]
|
||||
if not hasattr(whitelist, '__iter__'):
|
||||
|
@ -383,13 +383,24 @@ def check_whitelist_blacklist(value, whitelist=None, blacklist=None):
|
|||
type(whitelist).__name__, whitelist
|
||||
)
|
||||
)
|
||||
for expr in whitelist:
|
||||
if expr_match(value, expr):
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
whitelist = []
|
||||
|
||||
return False
|
||||
_blacklist_match = any(expr_match(value, expr) for expr in blacklist)
|
||||
_whitelist_match = any(expr_match(value, expr) for expr in whitelist)
|
||||
|
||||
if blacklist and not whitelist:
|
||||
# Blacklist but no whitelist
|
||||
return not _blacklist_match
|
||||
elif whitelist and not blacklist:
|
||||
# Whitelist but no blacklist
|
||||
return _whitelist_match
|
||||
elif blacklist and whitelist:
|
||||
# Both whitelist and blacklist
|
||||
return not _blacklist_match and _whitelist_match
|
||||
else:
|
||||
# No blacklist or whitelist passed
|
||||
return True
|
||||
|
||||
|
||||
def check_include_exclude(path_str, include_pat=None, exclude_pat=None):
|
||||
|
|
|
@ -217,23 +217,55 @@ class StringutilsTestCase(TestCase):
|
|||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_one',
|
||||
whitelist=whitelist[1],
|
||||
blacklist=None,
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_one',
|
||||
whitelist=whitelist[1],
|
||||
blacklist=[],
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web1',
|
||||
whitelist=whitelist[1],
|
||||
blacklist=None,
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web1',
|
||||
whitelist=whitelist[1],
|
||||
blacklist=[],
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web5',
|
||||
whitelist=None,
|
||||
blacklist=blacklist[1],
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web5',
|
||||
whitelist=[],
|
||||
blacklist=blacklist[1],
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_five',
|
||||
whitelist=None,
|
||||
blacklist=blacklist[1],
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_five',
|
||||
whitelist=[],
|
||||
blacklist=blacklist[1],
|
||||
)
|
||||
)
|
||||
|
@ -257,23 +289,55 @@ class StringutilsTestCase(TestCase):
|
|||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_one',
|
||||
whitelist=whitelist,
|
||||
blacklist=None,
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_one',
|
||||
whitelist=whitelist,
|
||||
blacklist=[],
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web1',
|
||||
whitelist=whitelist,
|
||||
blacklist=None,
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web1',
|
||||
whitelist=whitelist,
|
||||
blacklist=[],
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web5',
|
||||
whitelist=None,
|
||||
blacklist=blacklist,
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web5',
|
||||
whitelist=[],
|
||||
blacklist=blacklist,
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_five',
|
||||
whitelist=None,
|
||||
blacklist=blacklist,
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_five',
|
||||
whitelist=[],
|
||||
blacklist=blacklist,
|
||||
)
|
||||
)
|
||||
|
@ -297,23 +361,55 @@ class StringutilsTestCase(TestCase):
|
|||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_one',
|
||||
whitelist=set(whitelist),
|
||||
blacklist=None,
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_one',
|
||||
whitelist=set(whitelist),
|
||||
blacklist=set(),
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web1',
|
||||
whitelist=set(whitelist),
|
||||
blacklist=None,
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web1',
|
||||
whitelist=set(whitelist),
|
||||
blacklist=set(),
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web5',
|
||||
whitelist=None,
|
||||
blacklist=set(blacklist),
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web5',
|
||||
whitelist=set(),
|
||||
blacklist=set(blacklist),
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_five',
|
||||
whitelist=None,
|
||||
blacklist=set(blacklist),
|
||||
)
|
||||
)
|
||||
self.assertTrue(
|
||||
salt.utils.stringutils.check_whitelist_blacklist(
|
||||
'web_five',
|
||||
whitelist=set(),
|
||||
blacklist=set(blacklist),
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue