Merge "Always check cmd which does not exist"

This commit is contained in:
Jenkins 2017-02-13 08:04:42 +00:00 committed by Gerrit Code Review
commit 1f60ecbb9d
2 changed files with 13 additions and 2 deletions

View File

@ -39,7 +39,6 @@ class CommandFilter(object):
exec_dirs = exec_dirs or []
if self.real_exec is not None:
return self.real_exec
self.real_exec = ""
if os.path.isabs(self.exec_path):
if os.access(self.exec_path, os.X_OK):
self.real_exec = self.exec_path

View File

@ -18,6 +18,7 @@ import io
import logging
import os
import pwd
import shutil
import signal
import sys
import threading
@ -44,6 +45,7 @@ class _FunctionalBase(object):
super(_FunctionalBase, self).setUp()
tmpdir = self.useFixture(fixtures.TempDir()).path
self.config_file = os.path.join(tmpdir, 'rootwrap.conf')
self.later_cmd = os.path.join(tmpdir, 'later_install_cmd')
filters_dir = os.path.join(tmpdir, 'filters.d')
filters_file = os.path.join(tmpdir, 'filters.d', 'test.filters')
os.mkdir(filters_dir)
@ -58,7 +60,8 @@ cat: CommandFilter, /bin/cat, root
sh: CommandFilter, /bin/sh, root
id: CommandFilter, /usr/bin/id, nobody
unknown_cmd: CommandFilter, /unknown/unknown_cmd, root
""")
later_install_cmd: CommandFilter, %s, root
""" % self.later_cmd)
def _test_run_once(self, expect_byte=True):
code, out, err = self.execute(['echo', 'teststr'])
@ -192,6 +195,15 @@ class RootwrapDaemonTest(_FunctionalBase, testtools.TestCase):
def test_run_with_stdin(self):
self._test_run_with_stdin(expect_byte=False)
def test_run_with_later_install_cmd(self):
code, out, err = self.execute(['later_install_cmd'])
self.assertEqual(cmd.RC_NOEXECFOUND, code)
# Install cmd and try again
shutil.copy('/bin/echo', self.later_cmd)
code, out, err = self.execute(['later_install_cmd'])
# Expect successfully run the cmd
self.assertEqual(0, code)
def test_daemon_ressurection(self):
# Let the client start a daemon
self.execute(['cat'])