[apparmor] test-aa-easyprof.py fails because of UsrMove

Steve Beattie steve at nxnw.org
Mon Mar 3 19:03:20 UTC 2014


On Sat, Mar 01, 2014 at 09:41:38PM +0100, Christian Boltz wrote:
> Hello,
> 
> Am Sonntag, 2. März 2014 schrieb Kshitij Gupta:
> > On Sat, Mar 1, 2014 at 3:41 AM, Christian Boltz wrote:
> > > test-aa-easyprof.py depends on /bin/ls being a real binary.
> > > In practise, it is a symlink to /usr/bin/ls on some distributions.
> > > 
> > > The patch below fixes this for me, but I know it isn't a good
> > > solution because it breaks on systems that didn't follow UsrMove
> > > and still have /bin/ls as real binary.
> > 
> > How about using os.path.islink() to determine if the given system
> > followed UsrMove or not and accordingly setting test up?
> > 
> > Something on the lines of:
> > 
> > ls_path='/bin/ls'
> > if os.path.islink(ls_path):
> >     ls_path='/usr/bin/ls'
> > 
> > and then use ls_path everywhere.
> 
> That sounds like a plan, even if it means we replace a hardcoded value 
> with two hardcoded values ;-)  [1]
> 
> Here's a patch that should work for everybody:

Stylistically, I'd rather do something like the following patch. I'd
prefer not to add more code to the __main__ section, because it acts
as an impediment to getting tools like nosetests[1] functioning for
the tests, which lets you cherry pick out an individual test or two,
useful for debugging a failing test without needing to run them
all. While test-aa-easyprof.py has other things going in __main__
that prevent this from working, we shouldn't add to it.

[1] See https://nose.readthedocs.org/en/latest/

Signed-off-by: Steve Beattie <steve at nxnw.org>
---
 utils/test/test-aa-easyprof.py |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Index: b/utils/test/test-aa-easyprof.py
===================================================================
--- a/utils/test/test-aa-easyprof.py
+++ b/utils/test/test-aa-easyprof.py
@@ -100,6 +100,10 @@ class Manifest(object):
 # Our test class
 #
 class T(unittest.TestCase):
+
+    # work around UsrMove
+    ls = os.path.realpath('/bin/ls')
+
     def setUp(self):
         '''Setup for tests'''
         global topdir
@@ -424,14 +428,14 @@ POLICYGROUPS_DIR="%s/templates"
 #
     def test_binary_without_profile_name(self):
         '''Test binary (<binary> { })'''
-        easyprof.AppArmorEasyProfile('/bin/ls', self.options)
+        easyprof.AppArmorEasyProfile(self.ls, self.options)
 
     def test_binary_with_profile_name(self):
         '''Test binary (profile <name> <binary> { })'''
         args = self.full_args
         args += ['--profile-name=some-profile-name']
         (self.options, self.args) = easyprof.parse_args(args)
-        easyprof.AppArmorEasyProfile('/bin/ls', self.options)
+        easyprof.AppArmorEasyProfile(self.ls, self.options)
 
     def test_binary_omitted_with_profile_name(self):
         '''Test binary (profile <name> { })'''
@@ -1206,7 +1210,7 @@ POLICYGROUPS_DIR="%s/templates"
     def test_gen_manifest_policy_with_binary_with_profile_name(self):
         '''Test gen_manifest_policy (binary with profile name)'''
         m = Manifest("test_gen_manifest_policy")
-        m.add_binary('/bin/ls')
+        m.add_binary(self.ls)
         self._gen_manifest_policy(m)
 
     def test_gen_manifest_policy_without_binary_with_profile_name(self):

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140303/1b2f0fa5/attachment.pgp>


More information about the AppArmor mailing list