2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 14:25:52 +00:00

IncludeRuleset: add get_all_full_paths()

This function returns a list of full paths of all includes.

Also add some tests.
This commit is contained in:
Christian Boltz
2020-05-16 23:24:11 +02:00
parent 057c916032
commit 0cfef21713
2 changed files with 32 additions and 1 deletions

View File

@@ -156,4 +156,12 @@ class IncludeRule(BaseRule):
class IncludeRuleset(BaseRuleset):
'''Class to handle and store a collection of include rules'''
pass
def get_all_full_paths(self, profile_dir):
''' get full path of all includes '''
paths = []
for rule_obj in self.rules:
paths += rule_obj.get_full_paths(profile_dir)
return paths

View File

@@ -381,6 +381,15 @@ class IncludeFullPathsTest(AATest):
## --- tests for IncludeRuleset --- #
class IncludeRulesTest(AATest):
def AASetup(self):
self.createTmpdir()
#copy the local profiles to the test directory
self.profile_dir = '%s/profiles' % self.tmpdir
shutil.copytree('../../profiles/apparmor.d/', self.profile_dir, symlinks=True)
write_file(self.profile_dir, 'baz', '/baz r,')
def test_empty_ruleset(self):
ruleset = IncludeRuleset()
ruleset_2 = IncludeRuleset()
@@ -389,6 +398,7 @@ class IncludeRulesTest(AATest):
self.assertEqual([], ruleset_2.get_raw(2))
self.assertEqual([], ruleset_2.get_clean(2))
self.assertEqual([], ruleset_2.get_clean_unsorted(2))
self.assertEqual([], ruleset.get_all_full_paths(self.profile_dir))
def test_ruleset_1(self):
ruleset = IncludeRuleset()
@@ -415,12 +425,18 @@ class IncludeRulesTest(AATest):
'',
]
expected_fullpaths = [
os.path.join(self.profile_dir, 'foo'),
'/bar'
]
for rule in rules:
ruleset.add(IncludeRule.parse(rule))
self.assertEqual(expected_raw, ruleset.get_raw())
self.assertEqual(expected_clean, ruleset.get_clean())
self.assertEqual(expected_clean_unsorted, ruleset.get_clean_unsorted())
self.assertEqual(expected_fullpaths, ruleset.get_all_full_paths(self.profile_dir))
def test_ruleset_2(self):
ruleset = IncludeRuleset()
@@ -455,12 +471,19 @@ class IncludeRulesTest(AATest):
'',
]
expected_fullpaths = [
os.path.join(self.profile_dir, 'baz'),
os.path.join(self.profile_dir, 'foo'),
'/bar',
]
for rule in rules:
ruleset.add(IncludeRule.parse(rule))
self.assertEqual(expected_raw, ruleset.get_raw())
self.assertEqual(expected_clean, ruleset.get_clean())
self.assertEqual(expected_clean_unsorted, ruleset.get_clean_unsorted())
self.assertEqual(expected_fullpaths, ruleset.get_all_full_paths(self.profile_dir))
class IncludeGlobTestAATest(AATest):
def setUp(self):