From 206151c7326cb7e1537b0e7f376bfec24845b88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Tue, 26 Sep 2023 10:18:31 +0200 Subject: [PATCH] Add coreutils as valid value to fix KillFilter test In containerized RHEL 9 environment the KillFilter test started to fail because `os.readlink("/proc/")` return /usr/bin/coreutils. Indeed cat is part of the coreutils package and the symlink of this file point toward coreutils. Fixing this bug by adding coreutils as a possible returned value for our tests. Closes-Bug: #2037383 Change-Id: I141eb15efa30c7df3ca5419b594097f4b683663c (cherry picked from commit 43ab5ad7a7e6ad8aa17e7abe5957bfe15cc043ac) --- oslo_rootwrap/tests/test_rootwrap.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/oslo_rootwrap/tests/test_rootwrap.py b/oslo_rootwrap/tests/test_rootwrap.py index e89f49d..d5c8b73 100644 --- a/oslo_rootwrap/tests/test_rootwrap.py +++ b/oslo_rootwrap/tests/test_rootwrap.py @@ -200,6 +200,7 @@ class RootwrapTestCase(testtools.TestCase): try: f = filters.KillFilter("root", "/bin/cat", "-9", "-HUP") f2 = filters.KillFilter("root", "/usr/bin/cat", "-9", "-HUP") + f3 = filters.KillFilter("root", "/usr/bin/coreutils", "-9", "-HUP") usercmd = ['kill', '-ALRM', p.pid] # Incorrect signal should fail self.assertFalse(f.match(usercmd) or f2.match(usercmd)) @@ -208,10 +209,13 @@ class RootwrapTestCase(testtools.TestCase): self.assertFalse(f.match(usercmd) or f2.match(usercmd)) # Providing matching signal should be allowed usercmd = ['kill', '-9', p.pid] - self.assertTrue(f.match(usercmd) or f2.match(usercmd)) + self.assertTrue(f.match(usercmd) or + f2.match(usercmd) or + f3.match(usercmd)) f = filters.KillFilter("root", "/bin/cat") f2 = filters.KillFilter("root", "/usr/bin/cat") + f3 = filters.KillFilter("root", "/usr/bin/coreutils") usercmd = ['kill', os.getpid()] # Our own PID does not match /bin/sleep, so it should fail self.assertFalse(f.match(usercmd) or f2.match(usercmd)) @@ -220,16 +224,19 @@ class RootwrapTestCase(testtools.TestCase): self.assertFalse(f.match(usercmd) or f2.match(usercmd)) usercmd = ['kill', p.pid] # Providing no signal should work - self.assertTrue(f.match(usercmd) or f2.match(usercmd)) + self.assertTrue(f.match(usercmd) or + f2.match(usercmd) or + f3.match(usercmd)) # verify that relative paths are matched against $PATH f = filters.KillFilter("root", "cat") + f2 = filters.KillFilter("root", "coreutils") # 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)) + self.assertTrue(f.match(usercmd) or f2.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))