@@ -30,28 +30,19 @@ def sha(path: Path) -> str:
3030 return hashlib .sha256 (path .read_bytes ()).hexdigest ()
3131
3232
33- def host_system_tool_paths () -> dict [str , Path ]:
33+ def host_system_tool_paths (fallback : Path ) -> dict [str , Path ]:
3434 def usable (path : Path ) -> bool :
3535 try :
36- metadata = path .lstat ()
37- except OSError :
36+ builder ._require_regular (
37+ path ,
38+ "fixture system tool" ,
39+ executable = True ,
40+ allow_root_owner = True ,
41+ )
42+ except (OSError , builder .BuildError ):
3843 return False
39- return (
40- stat .S_ISREG (metadata .st_mode )
41- and metadata .st_uid == 0
42- and not stat .S_IMODE (metadata .st_mode ) & 0o022
43- and Path (os .path .realpath (path )) == path
44- and os .access (path , os .X_OK )
45- )
44+ return Path (os .path .realpath (path )) == path
4645
47- fallback = next (
48- path
49- for path in map (
50- Path ,
51- ("/usr/bin/true" , "/bin/true" , "/usr/bin/env" , "/bin/echo" ),
52- )
53- if usable (path )
54- )
5546 return {
5647 name : path if usable (path ) else fallback
5748 for name , path in builder .SYSTEM_TOOL_PATHS .items ()
@@ -180,8 +171,11 @@ class SealedRuntimeBuilderTests(unittest.TestCase):
180171 def setUp (self ) -> None :
181172 self .temporary = tempfile .TemporaryDirectory (prefix = "sealed-builder-test-" )
182173 self .root = Path (os .path .realpath (self .temporary .name ))
174+ fallback = self .root / "system-tool"
175+ fallback .write_text ("#!/bin/sh\n exit 0\n " , encoding = "utf-8" )
176+ fallback .chmod (0o700 )
183177 self .system_tools_patch = mock .patch .object (
184- builder , "SYSTEM_TOOL_PATHS" , host_system_tool_paths ()
178+ builder , "SYSTEM_TOOL_PATHS" , host_system_tool_paths (fallback )
185179 )
186180 self .system_tools_patch .start ()
187181 self .fixture = ManifestFixture (self .root )
0 commit comments