mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +00:00
ProfileList: add __getitem__()
... and add some tests for it.
This commit is contained in:
@@ -52,6 +52,12 @@ class ProfileList:
|
||||
name = type(self).__name__
|
||||
return '\n<%s>\n%s\n</%s>\n' % (name, '\n'.join(self.files), name)
|
||||
|
||||
def __getitem__(self, key):
|
||||
if key in self.profiles:
|
||||
return self.profiles[key]
|
||||
else:
|
||||
raise AppArmorBug('attempt to read unknown profile %s' % key)
|
||||
|
||||
def init_file(self, filename):
|
||||
if self.files.get(filename):
|
||||
return # don't re-initialize / overwrite existing data
|
||||
|
@@ -47,6 +47,11 @@ class TestAdd_profile(AATest):
|
||||
self.assertEqual(self.pl.profiles_in_file('/etc/apparmor.d/bin.foo'), ['foo'])
|
||||
self.assertEqual(str(self.pl), '\n<ProfileList>\n/etc/apparmor.d/bin.foo\n</ProfileList>\n')
|
||||
|
||||
# test __getitem__()
|
||||
self.assertEqual(self.pl['foo'], self.dummy_profile)
|
||||
with self.assertRaises(AppArmorBug):
|
||||
self.pl['does_not_exist']
|
||||
|
||||
def testAdd_profile_2(self):
|
||||
self.assertFalse(self.pl.profile_exists('foo'))
|
||||
self.assertFalse(self.pl.profile_exists('/bin/foo'))
|
||||
|
Reference in New Issue
Block a user