mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-05 00:35:13 +00:00
add_or_remove_flag(): allow to add or remove multiple flags
Multiple flags can be given as string (will be split) or as array. Also add some tests confirming that everything works as expected.
This commit is contained in:
@@ -181,16 +181,21 @@ def split_flags(flags):
|
||||
# sort and remove duplicates
|
||||
return sorted(set(flags_list))
|
||||
|
||||
def add_or_remove_flag(flags, flag_to_change, set_flag):
|
||||
'''add (if set_flag == True) or remove the given flag_to_change to flags'''
|
||||
def add_or_remove_flag(flags, flags_to_change, set_flag):
|
||||
'''add (if set_flag == True) or remove the given flags_to_change to flags'''
|
||||
|
||||
if type_is_str(flags) or flags is None:
|
||||
flags = split_flags(flags)
|
||||
|
||||
if type_is_str(flags_to_change) or flags_to_change is None:
|
||||
flags_to_change = split_flags(flags_to_change)
|
||||
|
||||
if set_flag:
|
||||
for flag_to_change in flags_to_change:
|
||||
if flag_to_change not in flags:
|
||||
flags.append(flag_to_change)
|
||||
else:
|
||||
for flag_to_change in flags_to_change:
|
||||
if flag_to_change in flags:
|
||||
flags.remove(flag_to_change)
|
||||
|
||||
|
@@ -50,6 +50,14 @@ class AaTest_add_or_remove_flag(AATest):
|
||||
([ None, 'audit', False ], [] ),
|
||||
([ 'complain', 'audit', True ], ['audit', 'complain'] ),
|
||||
([ ' complain ', 'audit', False ], ['complain'] ),
|
||||
([ 'audit complain', ['audit', 'complain'], False ], [] ),
|
||||
([ 'audit complain', 'audit complain', False ], [] ),
|
||||
([ 'audit complain', ['audit', 'enforce'], False ], ['complain'] ),
|
||||
([ 'audit complain', 'audit enforce', False ], ['complain'] ),
|
||||
([ '', ['audit', 'complain'], True ], ['audit', 'complain'] ),
|
||||
([ '', 'audit complain', True ], ['audit', 'complain'] ),
|
||||
([ 'audit', ['audit', 'enforce'], True ], ['audit', 'enforce'] ),
|
||||
([ 'audit', 'audit enforce', True ], ['audit', 'enforce'] ),
|
||||
]
|
||||
|
||||
def _run_test(self, params, expected):
|
||||
|
Reference in New Issue
Block a user