diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py index 1781d8133..2b4907d8d 100644 --- a/tests/xmlconfig.py +++ b/tests/xmlconfig.py @@ -15,8 +15,9 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA. -import unittest import os +import tempfile +import unittest import virtinst from virtinst import VirtualDisk @@ -329,3 +330,16 @@ class TestXMLMisc(unittest.TestCase): self._compare(g, "install-hyperv-noclock", True) finally: CLIConfig.stable_defaults = False + + def test_dir_searchable(self): + # Normally the dir searchable test is skipped in the unittest, + # but let's contrive an example that should trigger all the code + from virtinst.devicedisk import _is_dir_searchable + oldtest = os.environ.pop("VIRTINST_TEST_SUITE") + try: + uid = -1 + username = "fakeuser-zzzz" + with tempfile.TemporaryDirectory() as tmpdir: + self.assertFalse(_is_dir_searchable(uid, username, tmpdir)) + finally: + os.environ["VIRTINST_TEST_SUITE"] = oldtest diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py index 646f33d9c..e0b3a6231 100644 --- a/virtinst/devicedisk.py +++ b/virtinst/devicedisk.py @@ -87,7 +87,8 @@ def _is_dir_searchable(uid, username, path): logging.debug("Cmd '%s' failed: %s", cmd, err) return False - return bool(re.search("user:%s:..x" % username, out)) + pattern = "user:%s:..x" % username + return bool(re.search(pattern.encode("utf-8", "replace"), out)) class _Host(XMLBuilder):