コード例 #1
0
ファイル: test_rootwrap.py プロジェクト: whitekid/quantum
    def test_KillFilter(self):
        p = utils.subprocess_popen(["/bin/sleep", "5"])
        f = filters.KillFilter("root", "/bin/sleep", "-9", "-HUP")
        f2 = filters.KillFilter("root", "/usr/bin/sleep", "-9", "-HUP")
        usercmd = ['kill', '-ALRM', p.pid]
        # Incorrect signal should fail
        self.assertFalse(f.match(usercmd) or f2.match(usercmd))
        usercmd = ['kill', p.pid]
        # Providing no signal should fail
        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))

        f = filters.KillFilter("root", "/bin/sleep")
        f2 = filters.KillFilter("root", "/usr/bin/sleep")
        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))
        usercmd = ['kill', 999999]
        # Nonexistant PID should fail
        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))
コード例 #2
0
ファイル: test_rootwrap.py プロジェクト: soheilhy/quantum
    def test_KillFilter(self):
        if not os.path.exists("/proc/%d" % os.getpid()):
            self.skipTest("Test requires /proc filesystem (procfs)")
        p = subprocess.Popen(["cat"],
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        try:
            f = filters.KillFilter("root", "/bin/cat", "-9", "-HUP")
            f2 = filters.KillFilter("root", "/usr/bin/cat", "-9", "-HUP")
            usercmd = ['kill', '-ALRM', p.pid]
            # Incorrect signal should fail
            self.assertFalse(f.match(usercmd) or f2.match(usercmd))
            usercmd = ['kill', p.pid]
            # Providing no signal should fail
            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))

            f = filters.KillFilter("root", "/bin/cat")
            f2 = filters.KillFilter("root", "/usr/bin/cat")
            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))
            usercmd = ['kill', 999999]
            # Nonexistent PID should fail
            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))
        finally:
            # Terminate the "cat" process and wait for it to finish
            p.terminate()
            p.wait()
コード例 #3
0
ファイル: test_rootwrap.py プロジェクト: whitekid/quantum
 def test_KillFilter_deleted_exe(self):
     """Makes sure deleted exe's are killed correctly"""
     # See bug #1073768.
     with mock.patch('os.readlink') as mock_readlink:
         mock_readlink.return_value = '/bin/commandddddd (deleted)'
         f = filters.KillFilter("root", "/bin/commandddddd")
         usercmd = ['kill', 1234]
         self.assertTrue(f.match(usercmd))
         mock_readlink.assert_called_once_with("/proc/1234/exe")
コード例 #4
0
ファイル: test_rootwrap.py プロジェクト: whitekid/quantum
 def test_KillFilter_no_raise(self):
     """Makes sure ValueError from bug 926412 is gone"""
     f = filters.KillFilter("root", "")
     # Providing anything other than kill should be False
     usercmd = ['notkill', 999999]
     self.assertFalse(f.match(usercmd))
     # Providing something that is not a pid should be False
     usercmd = ['kill', 'notapid']
     self.assertFalse(f.match(usercmd))
コード例 #5
0
ファイル: test_rootwrap.py プロジェクト: soheilhy/quantum
    def test_KillFilter_deleted_exe(self):
        """Makes sure deleted exe's are killed correctly."""

        # See bug #967931.
        def fake_readlink(blah):
            return '/bin/commandddddd (deleted)'

        f = filters.KillFilter("root", "/bin/commandddddd")
        usercmd = ['kill', 1234]
        # Providing no signal should work
        self.stubs.Set(os, 'readlink', fake_readlink)
        self.assertTrue(f.match(usercmd))