mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
devicedisk: fix _is_dir_searchable
And add a test case that would have caught this
This commit is contained in:
parent
a55abc8e89
commit
1994b4cf2d
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user