Commit d0edb879 authored by Steve Beattie's avatar Steve Beattie

utils/easyprof: fix regression test when apparmor-easyprof is not installed

Bug: https://bugs.launchpad.net/bugs/1294848

This patch fixes the testsuite for aa-easyprof when the easyprof
utilities and configuration files are not installed in the system.
What was happening was that verify_manifest was calling parse_args()
without the synthetic arguments created by the test case and passing
the result to AppArmorEasyProfile(). Because parse_args() didn't
have the synthetic arguments, it would parse the actual command line
arguments passed to the testscript, which of course didn't specify the
alternate configuration file location. This would work when easyprof
had been installed in the system, because the fallback configuration
file in /etc/apparmor/easyprof.conf would exist and specify template
and policy group locations. Without that, though, the tests would abort
due to not knowing the location of the templates and policy groups.

This patch fixes the issue by passing the synthetic argument list
to verify_manifest, which uses that when calling parse_args(). A
debugging statement that states which conffile is being used when
AppArmorEasyProfile is being instantiated.
Signed-off-by: Steve Beattie's avatarSteve Beattie <steve@nxnw.org>
Acked-by: Tyler Hicks's avatarTyler Hicks <tyhicks@canonical.com>
parent 5f3fc904
...@@ -296,6 +296,7 @@ class AppArmorEasyProfile: ...@@ -296,6 +296,7 @@ class AppArmorEasyProfile:
verify_options(opt) verify_options(opt)
opt.ensure_value("conffile", "/etc/apparmor/easyprof.conf") opt.ensure_value("conffile", "/etc/apparmor/easyprof.conf")
self.conffile = os.path.abspath(opt.conffile) self.conffile = os.path.abspath(opt.conffile)
debug("Examining confile=%s" % (self.conffile))
self.dirs = dict() self.dirs = dict()
if os.path.isfile(self.conffile): if os.path.isfile(self.conffile):
...@@ -1085,10 +1086,10 @@ def verify_options(opt, strict=False): ...@@ -1085,10 +1086,10 @@ def verify_options(opt, strict=False):
raise AppArmorException("Invalid write path '%s'" % i) raise AppArmorException("Invalid write path '%s'" % i)
def verify_manifest(params): def verify_manifest(params, args=None):
'''Verify manifest for safe and unsafe options''' '''Verify manifest for safe and unsafe options'''
err_str = "" err_str = ""
(opt, args) = parse_args() (opt, args) = parse_args(args)
fake_easyp = AppArmorEasyProfile(None, opt) fake_easyp = AppArmorEasyProfile(None, opt)
unsafe_keys = ['read_path', 'write_path'] unsafe_keys = ['read_path', 'write_path']
......
...@@ -1644,9 +1644,9 @@ POLICYGROUPS_DIR="%s/templates" ...@@ -1644,9 +1644,9 @@ POLICYGROUPS_DIR="%s/templates"
raise raise
params = easyprof.gen_policy_params(binary, options) params = easyprof.gen_policy_params(binary, options)
if expected: if expected:
self.assertTrue(easyprof.verify_manifest(params), "params=%s\nmanifest=%s" % (params,m)) self.assertTrue(easyprof.verify_manifest(params, args), "params=%s\nmanifest=%s" % (params,m))
else: else:
self.assertFalse(easyprof.verify_manifest(params), "params=%s\nmanifest=%s" % (params,m)) self.assertFalse(easyprof.verify_manifest(params, args), "params=%s\nmanifest=%s" % (params,m))
def test_verify_manifest_full(self): def test_verify_manifest_full(self):
'''Test verify_manifest (full)''' '''Test verify_manifest (full)'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment