2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-02 15:25:27 +00:00

ProfileList: add get_profile_and_childs()

... and a test for it
This commit is contained in:
Christian Boltz
2021-04-05 14:21:44 +02:00
parent b1a1b5dc1b
commit 179168f566
2 changed files with 24 additions and 0 deletions

View File

@@ -165,6 +165,14 @@ class ProfileList:
return deleted
def get_profile_and_childs(self, profile_name):
found = {}
for prof in self.profiles:
if prof == profile_name or prof.startswith('%s//' % profile_name):
found[prof] = self.profiles[prof]
return found
def get_raw(self, filename, depth=0):
''' Get the preamble for the given profile filename (in original formatting) '''
if not self.files.get(filename):

View File

@@ -400,6 +400,22 @@ class AaTest_get_all_merged_variables(AATest):
with self.assertRaises(AppArmorBug):
apparmor.aa.active_profiles.get_all_merged_variables(os.path.join(self.profile_dir, 'file.not.found'), list())
class TestGet_profile_and_childs(AATest):
def AASetup(self):
self.pl = ProfileList()
self.dummy_profile = ProfileStorage('TEST DUMMY', 'AATest_no_file', 'TEST')
def testGet_profile_and_childs1(self):
self.pl.add_profile('/etc/apparmor.d/bin.foo', 'bafoo', '/bin/bafoo', self.dummy_profile)
self.pl.add_profile('/etc/apparmor.d/bin.foo', 'foo', '/bin/foo', self.dummy_profile)
self.pl.add_profile('/etc/apparmor.d/bin.foo', 'foobar', '/bin/foobar', self.dummy_profile)
self.pl.add_profile('/etc/apparmor.d/bin.foo', 'foo//bar', '/bin/foo//bar', self.dummy_profile)
self.pl.add_profile('/etc/apparmor.d/bin.foo', 'foo//xy', '/bin/foo//xy', self.dummy_profile)
expected = ['foo', 'foo//bar', 'foo//xy']
self.assertEqual(list(self.pl.get_profile_and_childs('foo')), expected)
setup_aa(apparmor.aa)
setup_all_loops(__name__)