From 8b95b1e91d46f1bc7a37d210dc15e6f4072afaaa Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Sat, 18 May 2013 12:17:59 +0200 Subject: Handle relative path arguments in Killfilter KillFilter currently expects an absolute path to be specified for the process name to kill. This is inconvenient when the exact location of the running binary is not known or differs accross installs. Extend KillFilter to accept also commands in $PATH to be killed if the given argument is not absolute. Change-Id: I6b90206b587ff3f949af2c256a78ca21af31867a --- tests/unit/test_rootwrap.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/unit/test_rootwrap.py b/tests/unit/test_rootwrap.py index 25b2051..0e08b5e 100644 --- a/tests/unit/test_rootwrap.py +++ b/tests/unit/test_rootwrap.py @@ -107,6 +107,20 @@ class RootwrapTestCase(utils.BaseTestCase): usercmd = ['kill', p.pid] # Providing no signal should work self.assertTrue(f.match(usercmd) or f2.match(usercmd)) + + # verify that relative paths are matched against $PATH + f = filters.KillFilter("root", "cat") + # Our own PID does not match so it should fail + usercmd = ['kill', os.getpid()] + self.assertFalse(f.match(usercmd)) + # Filter should find cat in /bin or /usr/bin + usercmd = ['kill', p.pid] + self.assertTrue(f.match(usercmd)) + # Filter shouldn't be able to find binary in $PATH, so fail + with fixtures.EnvironmentVariable("PATH", "/foo:/bar"): + self.assertFalse(f.match(usercmd)) + pass + finally: # Terminate the "cat" process and wait for it to finish p.terminate() -- cgit