67
67
"Test requires /proc filesystem (procfs)")
68
68
def test_KillFilter(self):
69
69
p = subprocess.Popen(["/bin/sleep", "5"])
70
f = filters.KillFilter("/bin/kill", "root",
72
["/bin/sleep", "/usr/bin/sleep"])
73
usercmd = ['kill', '-9', p.pid]
70
f = filters.KillFilter("root", "/bin/sleep", "-9", "-HUP")
71
f2 = filters.KillFilter("root", "/usr/bin/sleep", "-9", "-HUP")
72
usercmd = ['kill', '-ALRM', p.pid]
74
73
# Incorrect signal should fail
75
self.assertFalse(f.match(usercmd))
74
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
76
75
usercmd = ['kill', p.pid]
77
76
# Providing no signal should fail
78
self.assertFalse(f.match(usercmd))
77
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
78
# Providing matching signal should be allowed
79
usercmd = ['kill', '-9', p.pid]
80
self.assertTrue(f.match(usercmd) or f2.match(usercmd))
80
f = filters.KillFilter("/bin/kill", "root",
82
["/bin/sleep", "/usr/bin/sleep"])
83
usercmd = ['kill', '-9', os.getpid()]
82
f = filters.KillFilter("root", "/bin/sleep")
83
f2 = filters.KillFilter("root", "/usr/bin/sleep")
84
usercmd = ['kill', os.getpid()]
84
85
# Our own PID does not match /bin/sleep, so it should fail
85
self.assertFalse(f.match(usercmd))
86
usercmd = ['kill', '-9', 999999]
86
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
87
usercmd = ['kill', 999999]
87
88
# Nonexistant PID should fail
88
self.assertFalse(f.match(usercmd))
89
self.assertFalse(f.match(usercmd) or f2.match(usercmd))
89
90
usercmd = ['kill', p.pid]
90
91
# Providing no signal should work
91
self.assertTrue(f.match(usercmd))
92
usercmd = ['kill', '-9', p.pid]
93
# Providing -9 signal should work
94
self.assertTrue(f.match(usercmd))
92
self.assertTrue(f.match(usercmd) or f2.match(usercmd))
96
94
def test_KillFilter_no_raise(self):
97
95
"""Makes sure ValueError from bug 926412 is gone"""
98
f = filters.KillFilter("/bin/kill", "root", [""])
96
f = filters.KillFilter("root", "")
99
97
# Providing anything other than kill should be False
100
98
usercmd = ['notkill', 999999]
101
99
self.assertFalse(f.match(usercmd))