@@ -44,15 +44,18 @@ describe("managed binary archive utilities", () => {
4444
4545 it ( "kills a process that exceeds its timeout" , async ( ) => {
4646 vi . useFakeTimers ( )
47- const child = createChild ( )
48- mockSpawn . mockReturnValue ( child as unknown as ReturnType < typeof spawn > )
49- const processResult = runProcess ( "tool" , [ ] , 100 )
50- const assertion = expect ( processResult ) . rejects . toThrow ( "tool timed out" )
51-
52- await vi . advanceTimersByTimeAsync ( 100 )
53- await assertion
54- expect ( child . kill ) . toHaveBeenCalledWith ( "SIGKILL" )
55- vi . useRealTimers ( )
47+ try {
48+ const child = createChild ( )
49+ mockSpawn . mockReturnValue ( child as unknown as ReturnType < typeof spawn > )
50+ const processResult = runProcess ( "tool" , [ ] , 100 )
51+ const assertion = expect ( processResult ) . rejects . toThrow ( "tool timed out" )
52+
53+ await vi . advanceTimersByTimeAsync ( 100 )
54+ await assertion
55+ expect ( child . kill ) . toHaveBeenCalledWith ( "SIGKILL" )
56+ } finally {
57+ vi . useRealTimers ( )
58+ }
5659 } )
5760
5861 it ( "extracts tar.gz archives with hardened flags" , async ( ) => {
@@ -112,7 +115,7 @@ describe("managed binary archive utilities", () => {
112115 mockSpawn . mockReturnValueOnce ( listing as unknown as ReturnType < typeof spawn > )
113116 mockSpawn . mockReturnValueOnce ( extraction as unknown as ReturnType < typeof spawn > )
114117 const result = extractSingleFileTarXzArchive ( "/tmp/archive.tar.xz" , "/tmp/output" , "binary" , "Tool" )
115- listing . stdout . write ( "./binary\n" )
118+ listing . stdout . write ( "-rwxr-xr-x user/group 1 2026-01-01 00:00 ./binary\n" )
116119 listing . emit ( "close" , 0 )
117120 await new Promise < void > ( ( resolve ) => setImmediate ( resolve ) )
118121 extraction . emit ( "close" , 0 )
@@ -121,11 +124,36 @@ describe("managed binary archive utilities", () => {
121124 expect ( mockSpawn ) . toHaveBeenNthCalledWith (
122125 2 ,
123126 "tar" ,
124- [ "-xJf" , "/tmp/archive.tar.xz" , "-C" , "/tmp/output" , "./binary" ] ,
127+ [
128+ "-xJf" ,
129+ "/tmp/archive.tar.xz" ,
130+ "-C" ,
131+ "/tmp/output" ,
132+ "--no-same-owner" ,
133+ ...( process . platform === "linux" ? [ "--no-overwrite-dir" ] : [ ] ) ,
134+ "./binary" ,
135+ ] ,
125136 expect . any ( Object ) ,
126137 )
127138 } )
128139
140+ it . each ( [
141+ [ "-rwxr-xr-x user/group 1 2026-01-01 00:00 ./other\n" , "an unexpected filename" ] ,
142+ [
143+ "-rwxr-xr-x user/group 1 2026-01-01 00:00 ./binary\n-rwxr-xr-x user/group 1 2026-01-01 00:00 ./other\n" ,
144+ "multiple entries" ,
145+ ] ,
146+ [ "lrwxrwxrwx user/group 0 2026-01-01 00:00 ./binary\n" , "a non-regular entry" ] ,
147+ ] ) ( "rejects a tar.xz archive with %s" , async ( listingOutput ) => {
148+ const listing = createChild ( )
149+ mockSpawn . mockReturnValue ( listing as unknown as ReturnType < typeof spawn > )
150+ const result = extractSingleFileTarXzArchive ( "/tmp/archive.tar.xz" , "/tmp/output" , "binary" , "Tool" )
151+ listing . stdout . write ( listingOutput )
152+ listing . emit ( "close" , 0 )
153+
154+ await expect ( result ) . rejects . toThrow ( "Tool archive has an unexpected layout" )
155+ } )
156+
129157 it ( "builds a single-entry-validated PowerShell ZIP extraction" , async ( ) => {
130158 const child = createChild ( )
131159 mockSpawn . mockReturnValue ( child as unknown as ReturnType < typeof spawn > )
0 commit comments