mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +00:00
ProfileStorage: store correct name
Instead of always storing the name of the main profile, store the child profile/hat name if we are in a child profile or hat. As a result, we always get the correct "profile xy" header even for child profiles when dumping the ProfileStorage object. Also extend the tests to check that the name gets stored correctly.
This commit is contained in:
@@ -141,28 +141,29 @@ class AaTest_repr(AATest):
|
||||
|
||||
class AaTest_parse_profile_start(AATest):
|
||||
tests = (
|
||||
# profile start line profile hat profile hat attachment xattrs flags pps_set_hat_external
|
||||
(('/foo {', None, None), ('/foo', '/foo', '', '', None, False)),
|
||||
(('/foo (complain) {', None, None), ('/foo', '/foo', '', '', 'complain', False)),
|
||||
(('profile foo /foo {', None, None), ('foo', 'foo', '/foo', '', None, False)), # named profile
|
||||
(('profile /foo {', '/bar', None), ('/bar', '/foo', '', '', None, False)), # child profile
|
||||
(('/foo//bar {', None, None), ('/foo', 'bar', '', '', None, True)), # external hat
|
||||
(('profile "/foo" (complain) {', None, None), ('/foo', '/foo', '', '', 'complain', False)),
|
||||
(('profile "/foo" xattrs=(user.bar=bar) {', None, None), ('/foo', '/foo', '', 'user.bar=bar', None, False)),
|
||||
(('profile "/foo" xattrs=(user.bar=bar user.foo=*) {', None, None), ('/foo', '/foo', '', 'user.bar=bar user.foo=*', None, False)),
|
||||
(('/usr/bin/xattrs-test xattrs=(myvalue="foo.bar") {', None, None), ('/usr/bin/xattrs-test', '/usr/bin/xattrs-test', '', 'myvalue="foo.bar"', None, False)),
|
||||
# profile start line profile hat name profile hat attachment xattrs flags pps_set_hat_external
|
||||
(('/foo {', None, None), ('/foo', '/foo', '/foo', '', '', None, False)),
|
||||
(('/foo (complain) {', None, None), ('/foo', '/foo', '/foo', '', '', 'complain', False)),
|
||||
(('profile foo /foo {', None, None), ('foo', 'foo', 'foo', '/foo', '', None, False)), # named profile
|
||||
(('profile /foo {', '/bar', None), ('/foo', '/bar', '/foo', '', '', None, False)), # child profile
|
||||
(('/foo//bar {', None, None), ('/foo//bar', '/foo', 'bar', '', '', None, True)), # external hat
|
||||
(('profile "/foo" (complain) {', None, None), ('/foo', '/foo', '/foo', '', '', 'complain', False)),
|
||||
(('profile "/foo" xattrs=(user.bar=bar) {', None, None), ('/foo', '/foo', '/foo', '', 'user.bar=bar', None, False)),
|
||||
(('profile "/foo" xattrs=(user.bar=bar user.foo=*) {', None, None), ('/foo', '/foo', '/foo', '', 'user.bar=bar user.foo=*', None, False)),
|
||||
(('/usr/bin/xattrs-test xattrs=(myvalue="foo.bar") {', None, None), ('/usr/bin/xattrs-test', '/usr/bin/xattrs-test', '/usr/bin/xattrs-test', '', 'myvalue="foo.bar"', None, False)),
|
||||
)
|
||||
|
||||
def _run_test(self, params, expected):
|
||||
(profile, hat, prof_storage) = ProfileStorage.parse(params[0], 'somefile', 1, params[1], params[2])
|
||||
|
||||
self.assertEqual(profile, expected[0])
|
||||
self.assertEqual(hat, expected[1])
|
||||
self.assertEqual(prof_storage['attachment'], expected[2])
|
||||
self.assertEqual(prof_storage['xattrs'], expected[3])
|
||||
self.assertEqual(prof_storage['flags'], expected[4])
|
||||
self.assertEqual(prof_storage['name'], expected[0])
|
||||
self.assertEqual(profile, expected[1])
|
||||
self.assertEqual(hat, expected[2])
|
||||
self.assertEqual(prof_storage['attachment'], expected[3])
|
||||
self.assertEqual(prof_storage['xattrs'], expected[4])
|
||||
self.assertEqual(prof_storage['flags'], expected[5])
|
||||
self.assertEqual(prof_storage['is_hat'], False)
|
||||
self.assertEqual(prof_storage['external'], expected[5])
|
||||
self.assertEqual(prof_storage['external'], expected[6])
|
||||
|
||||
|
||||
class AaTest_parse_profile_start_errors(AATest):
|
||||
|
Reference in New Issue
Block a user