@@ -146,31 +146,38 @@ describe("resolveAllowAlwaysPatterns", () => {
146146 expect ( second . allowlistSatisfied ) . toBe ( false ) ;
147147 }
148148
149- function expectPositionalArgvCarrierRejected ( command : string ) {
149+ function expectPositionalArgvCarrierResult ( params : {
150+ command : string ;
151+ expectPersisted : boolean ;
152+ } ) {
150153 const dir = makeTempDir ( ) ;
151154 const touch = makeExecutable ( dir , "touch" ) ;
152155 const env = { PATH : `${ dir } ${ path . delimiter } ${ process . env . PATH ?? "" } ` } ;
153156 const safeBins = resolveSafeBins ( undefined ) ;
154157 const marker = path . join ( dir , "marker" ) ;
155- const expandedCommand = command . replaceAll ( "{marker}" , marker ) ;
158+ const command = params . command . replaceAll ( "{marker}" , marker ) ;
156159
157160 const { persisted } = resolvePersistedPatterns ( {
158- command : expandedCommand ,
161+ command,
159162 dir,
160163 env,
161164 safeBins,
162165 } ) ;
163- expect ( persisted ) . toEqual ( [ ] ) ;
166+ if ( params . expectPersisted ) {
167+ expect ( persisted ) . toEqual ( [ touch ] ) ;
168+ } else {
169+ expect ( persisted ) . toEqual ( [ ] ) ;
170+ }
164171
165172 const second = evaluateShellAllowlist ( {
166- command : expandedCommand ,
173+ command,
167174 allowlist : [ { pattern : touch } ] ,
168175 safeBins,
169176 cwd : dir ,
170177 env,
171178 platform : process . platform ,
172179 } ) ;
173- expect ( second . allowlistSatisfied ) . toBe ( false ) ;
180+ expect ( second . allowlistSatisfied ) . toBe ( params . expectPersisted ) ;
174181 }
175182
176183 it ( "returns direct executable paths for non-shell segments" , ( ) => {
@@ -387,29 +394,41 @@ describe("resolveAllowAlwaysPatterns", () => {
387394 if ( process . platform === "win32" ) {
388395 return ;
389396 }
390- expectPositionalArgvCarrierRejected ( `sh -lc '$0 "$1"' touch {marker}` ) ;
397+ expectPositionalArgvCarrierResult ( {
398+ command : `sh -lc '$0 "$1"' touch {marker}` ,
399+ expectPersisted : true ,
400+ } ) ;
391401 } ) ;
392402
393403 it ( "rejects exec positional argv carriers" , ( ) => {
394404 if ( process . platform === "win32" ) {
395405 return ;
396406 }
397- expectPositionalArgvCarrierRejected ( `sh -lc 'exec -- "$0" "$1"' touch {marker}` ) ;
407+ expectPositionalArgvCarrierResult ( {
408+ command : `sh -lc 'exec -- "$0" "$1"' touch {marker}` ,
409+ expectPersisted : true ,
410+ } ) ;
398411 } ) ;
399412
400413 it ( "rejects positional argv carriers when $0 is single-quoted" , ( ) => {
401414 if ( process . platform === "win32" ) {
402415 return ;
403416 }
404- expectPositionalArgvCarrierRejected ( `sh -lc "'$0' "$1"" touch {marker}` ) ;
417+ expectPositionalArgvCarrierResult ( {
418+ command : `sh -lc "'$0' "$1"" touch {marker}` ,
419+ expectPersisted : false ,
420+ } ) ;
405421 } ) ;
406422
407423 it ( "rejects positional argv carriers when exec is separated from $0 by a newline" , ( ) => {
408424 if ( process . platform === "win32" ) {
409425 return ;
410426 }
411- expectPositionalArgvCarrierRejected ( `sh -lc "exec
412- $0 \\"$1\\"" touch {marker}` ) ;
427+ expectPositionalArgvCarrierResult ( {
428+ command : `sh -lc "exec
429+ $0 \\"$1\\"" touch {marker}` ,
430+ expectPersisted : false ,
431+ } ) ;
413432 } ) ;
414433
415434 it ( "rejects positional argv carriers when inline command contains extra shell operations" , ( ) => {
@@ -915,7 +934,7 @@ $0 \\"$1\\"" touch {marker}`);
915934 expect ( second . allowlistSatisfied ) . toBe ( false ) ;
916935 } ) ;
917936
918- it ( "rejects positional carrier when carried executable is an unknown dispatch carrier " , ( ) => {
937+ it ( "allows positional carriers for unknown carried executables when explicitly allowlisted " , ( ) => {
919938 if ( process . platform === "win32" ) {
920939 return ;
921940 }
@@ -940,6 +959,6 @@ $0 \\"$1\\"" touch {marker}`);
940959 env,
941960 platform : process . platform ,
942961 } ) ;
943- expect ( second . allowlistSatisfied ) . toBe ( false ) ;
962+ expect ( second . allowlistSatisfied ) . toBe ( true ) ;
944963 } ) ;
945964} ) ;
0 commit comments