@@ -140,3 +140,76 @@ t.test("it does not block in dry mode", (t) => {
140
140
server . kill ( ) ;
141
141
} ) ;
142
142
} ) ;
143
+
144
+ t . test ( "it blocks in blocking mode (with dd-trace)" , ( t ) => {
145
+ const server = spawn (
146
+ `node` ,
147
+ [ "--preserve-symlinks" , "--require" , "dd-trace/init" , pathToApp , "4002" ] ,
148
+ {
149
+ env : { ...process . env , AIKIDO_DEBUG : "true" , AIKIDO_BLOCKING : "true" } ,
150
+ cwd : resolve ( __dirname , "../../sample-apps/express-postgres" ) ,
151
+ }
152
+ ) ;
153
+
154
+ server . on ( "close" , ( ) => {
155
+ t . end ( ) ;
156
+ } ) ;
157
+
158
+ server . on ( "error" , ( err ) => {
159
+ t . fail ( err . message ) ;
160
+ } ) ;
161
+
162
+ let stdout = "" ;
163
+ server . stdout . on ( "data" , ( data ) => {
164
+ stdout += data . toString ( ) ;
165
+ } ) ;
166
+
167
+ let stderr = "" ;
168
+ server . stderr . on ( "data" , ( data ) => {
169
+ stderr += data . toString ( ) ;
170
+ } ) ;
171
+
172
+ // Wait for the server to start
173
+ timeout ( 2000 )
174
+ . then ( ( ) => {
175
+ return Promise . all ( [
176
+ fetch (
177
+ `http://localhost:4002/?petname=${ encodeURIComponent ( "Njuska'); DELETE FROM cats_2;-- H" ) } ` ,
178
+ {
179
+ signal : AbortSignal . timeout ( 5000 ) ,
180
+ }
181
+ ) ,
182
+ fetch ( `http://localhost:4002/string-concat` , {
183
+ method : "POST" ,
184
+ headers : { "Content-Type" : "application/json" } ,
185
+ body : JSON . stringify ( { petname : [ "'" , "1)" , "(0,1)" , "(1" , "'" ] } ) ,
186
+ signal : AbortSignal . timeout ( 5000 ) ,
187
+ } ) ,
188
+ fetch (
189
+ `http://localhost:4002/string-concat?petname='&petname=1)&petname=(0,1)&petname=(1&petname='` ,
190
+ {
191
+ signal : AbortSignal . timeout ( 5000 ) ,
192
+ }
193
+ ) ,
194
+ fetch ( "http://localhost:4002/?petname=Njuska" , {
195
+ signal : AbortSignal . timeout ( 5000 ) ,
196
+ } ) ,
197
+ ] ) ;
198
+ } )
199
+ . then (
200
+ async ( [ sqlInjection , sqlInjection2 , sqlInjection3 , normalSearch ] ) => {
201
+ t . equal ( sqlInjection . status , 500 ) ;
202
+ t . equal ( sqlInjection2 . status , 500 ) ;
203
+ t . equal ( sqlInjection3 . status , 500 ) ;
204
+ t . equal ( normalSearch . status , 200 ) ;
205
+ t . match ( stdout , / S t a r t i n g a g e n t / ) ;
206
+ t . match ( stderr , / Z e n h a s b l o c k e d a n S Q L i n j e c t i o n / ) ;
207
+ }
208
+ )
209
+ . catch ( ( error ) => {
210
+ t . fail ( error ) ;
211
+ } )
212
+ . finally ( ( ) => {
213
+ server . kill ( ) ;
214
+ } ) ;
215
+ } ) ;
0 commit comments