@@ -88,3 +88,49 @@ describe("postject CLI", () => {
88
88
}
89
89
} ) . timeout ( 30000 ) ;
90
90
} ) ;
91
+
92
+ describe ( "Inject data into Node.js" , ( ) => {
93
+ let filename ;
94
+ let tempDir ;
95
+ let resourceContents ;
96
+ let resourceFilename ;
97
+
98
+ beforeEach ( async ( ) => {
99
+ tempDir = temporaryDirectory ( ) ;
100
+ await fs . ensureDir ( tempDir ) ;
101
+
102
+ filename = path . join ( tempDir , path . basename ( process . execPath ) ) ;
103
+
104
+ await fs . copy ( process . execPath , filename ) ;
105
+
106
+ resourceContents = crypto . randomBytes ( 64 ) . toString ( "hex" ) ;
107
+ resourceFilename = path . join ( tempDir , "resource.bin" ) ;
108
+ await fs . writeFile ( resourceFilename , resourceContents ) ;
109
+ } ) ;
110
+
111
+ afterEach ( ( ) => {
112
+ rimraf . sync ( tempDir ) ;
113
+ } ) ;
114
+
115
+ it ( "should inject a resource successfully" , async ( ) => {
116
+ {
117
+ const { status, stdout, stderr } = spawnSync (
118
+ "node" ,
119
+ [ "./dist/main.js" , filename , "foobar" , resourceFilename ] ,
120
+ { encoding : "utf-8" }
121
+ ) ;
122
+ // TODO(dsanders11) - Enable this once we squelch LIEF warnings
123
+ // expect(stderr).to.be.empty;
124
+ expect ( stdout ) . to . be . empty ;
125
+ expect ( status ) . to . equal ( 0 ) ;
126
+ }
127
+
128
+ // After injection
129
+ {
130
+ const { status } = spawnSync ( filename , [ "-e" , "process.exit()" ] , {
131
+ encoding : "utf-8" ,
132
+ } ) ;
133
+ expect ( status ) . to . equal ( 0 ) ;
134
+ }
135
+ } ) . timeout ( 60000 ) ;
136
+ } ) ;
0 commit comments