mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +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:
@@ -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
|
||||
|
@@ -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):
|
||||
|
Reference in New Issue
Block a user