mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-03 07:45:50 +00:00
add split_to_merged()
... to convert a traditional compat['foo']['bar'] to a profile['foo//bar'] list
This commit is contained in:
@@ -2113,6 +2113,22 @@ def merged_to_split(profile_data):
|
||||
|
||||
return compat
|
||||
|
||||
def split_to_merged(profile_data):
|
||||
''' (temporary) helper function to convert a traditional compat['foo']['bar'] to a profile['foo//bar'] list '''
|
||||
|
||||
merged = {}
|
||||
|
||||
for profile in profile_data:
|
||||
for hat in profile_data[profile]:
|
||||
if profile == hat:
|
||||
merged_name = profile
|
||||
else:
|
||||
merged_name = combine_profname([profile, hat])
|
||||
|
||||
merged[merged_name] = profile_data[profile][hat]
|
||||
|
||||
return merged
|
||||
|
||||
def parse_mount_rule(line):
|
||||
# XXX Do real parsing here
|
||||
return aarules.Raw_Mount_Rule(line)
|
||||
|
@@ -21,7 +21,7 @@ import apparmor.aa # needed to set global vars in some tests
|
||||
from apparmor.aa import (check_for_apparmor, get_output, get_reqs, get_interpreter_and_abstraction, create_new_profile,
|
||||
get_profile_flags, change_profile_flags, set_options_audit_mode, set_options_owner_mode, is_skippable_file,
|
||||
parse_profile_start, parse_profile_start_to_storage, parse_profile_data,
|
||||
get_file_perms, propose_file_rules, merged_to_split)
|
||||
get_file_perms, propose_file_rules, merged_to_split, split_to_merged)
|
||||
from apparmor.aare import AARE
|
||||
from apparmor.common import AppArmorException, AppArmorBug
|
||||
from apparmor.rule.file import FileRule
|
||||
@@ -759,6 +759,24 @@ class AaTest_merged_to_split(AATest):
|
||||
self.assertEqual(list(result[profile].keys()), [hat])
|
||||
self.assertTrue(result[profile][hat])
|
||||
|
||||
class AaTest_split_to_merged(AATest):
|
||||
tests = [
|
||||
(("foo", "foo"), "foo"),
|
||||
(("foo", "bar"), "foo//bar"),
|
||||
]
|
||||
|
||||
def _run_test(self, params, expected):
|
||||
old = {}
|
||||
profile = params[0]
|
||||
hat = params[1]
|
||||
|
||||
old[profile] = {}
|
||||
old[profile][hat] = True # simplified, but enough for this test
|
||||
result = split_to_merged(old)
|
||||
|
||||
self.assertEqual(list(result.keys()), [expected])
|
||||
self.assertTrue(result[expected])
|
||||
|
||||
setup_aa(apparmor.aa)
|
||||
setup_all_loops(__name__)
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user