@@ -6,12 +6,24 @@ import { LinuxAppBundler } from "../../lib/services/linux-app-bundle";
66import * as stubs from "../stubs" ;
77
88/** Fakes ns-bundle: `pack` writes the bundle and patches the executable. */
9- function fakeTool ( exitCode = 0 ) {
9+ function fakeTool ( exitCode = 0 , keyFromEnv = true ) {
1010 const calls : string [ ] [ ] = [ ] ;
11+ const envs : ( NodeJS . ProcessEnv | undefined ) [ ] = [ ] ;
1112 return {
1213 calls,
13- spawnFromEvent : async ( _command : string , args : string [ ] ) => {
14+ envs,
15+ spawnFromEvent : async (
16+ _command : string ,
17+ args : string [ ] ,
18+ _event : string ,
19+ options : { env ?: NodeJS . ProcessEnv } ,
20+ ) => {
21+ if ( args [ 0 ] === "--help" ) {
22+ const stdout = keyFromEnv ? "usage ... $NS_BUNDLE_KEY_HEX" : "usage" ;
23+ return { exitCode : 0 , stdout, stderr : "" } ;
24+ }
1425 calls . push ( args ) ;
26+ envs . push ( options ?. env ) ;
1527 if ( exitCode === 0 && args [ 0 ] === "pack" ) {
1628 const output = args [ args . indexOf ( "--output" ) + 1 ] ;
1729 fs . writeFileSync ( output , "NSB2" ) ;
@@ -83,12 +95,20 @@ describe("linuxAppBundle", () => {
8395 const [ args ] = proc . calls ;
8496 assert . includeMembers ( args , [
8597 "--seal" ,
86- "--key-hex" ,
87- "ab" . repeat ( 32 ) ,
8898 "--no-default-unpack" ,
8999 "data/**" ,
90100 "inspector=on" ,
91101 ] ) ;
102+ // not on argv, where other local users can read it
103+ assert . notInclude ( args , "ab" . repeat ( 32 ) ) ;
104+ assert . equal ( proc . envs [ 0 ] . NS_BUNDLE_KEY_HEX , "ab" . repeat ( 32 ) ) ;
105+ } ) ;
106+
107+ it ( "passes the key on argv to tools without NS_BUNDLE_KEY_HEX" , async ( ) => {
108+ const proc = fakeTool ( 0 , false ) ;
109+ await pack ( proc , { sourceProtect : true , keyHex : "cd" . repeat ( 32 ) } ) ;
110+ assert . includeMembers ( proc . calls [ 0 ] , [ "--key-hex" , "cd" . repeat ( 32 ) ] ) ;
111+ assert . isUndefined ( proc . envs [ 0 ] ) ;
92112 } ) ;
93113
94114 it ( "only sets fuses with bundle: false" , async ( ) => {
0 commit comments