@@ -14,6 +14,7 @@ const testServerUrl = "http://localhost:5874";
1414const port = await getRandomPort ( ) ;
1515const port2 = await getRandomPort ( ) ;
1616const port3 = await getRandomPort ( ) ;
17+ const port4 = await getRandomPort ( ) ;
1718
1819test ( "it blocks request in blocking mode" , async ( ) => {
1920 const server = spawn (
@@ -237,3 +238,86 @@ test("it reports packages in heartbeat with ESM instrumentation", async () => {
237238 server . kill ( ) ;
238239 }
239240} ) ;
241+
242+ test ( "if bypass IP is set, attack waves are ignored for that IP" , async ( ) => {
243+ const response = await fetch ( `${ testServerUrl } /api/runtime/apps` , {
244+ method : "POST" ,
245+ } ) ;
246+ const body = await response . json ( ) ;
247+ const token = body . token ;
248+
249+ await fetch ( `${ testServerUrl } /api/runtime/config` , {
250+ method : "POST" ,
251+ headers : {
252+ "Content-Type" : "application/json" ,
253+ Authorization : token ,
254+ } ,
255+ body : JSON . stringify ( {
256+ allowedIPAddresses : [ "1.2.3.4" ] ,
257+ } ) ,
258+ } ) ;
259+
260+ const server = spawn (
261+ `node` ,
262+ [ "--require" , "@aikidosec/firewall/instrument" , "./app.js" , port4 ] ,
263+ {
264+ cwd : pathToAppDir ,
265+ env : {
266+ ...process . env ,
267+ AIKIDO_TOKEN : token ,
268+ AIKIDO_ENDPOINT : testServerUrl ,
269+ AIKIDO_DEBUG : "true" ,
270+ } ,
271+ }
272+ ) ;
273+
274+ try {
275+ server . on ( "error" , ( err ) => {
276+ fail ( err ) ;
277+ } ) ;
278+
279+ let stdout = "" ;
280+ server . stdout . on ( "data" , ( data ) => {
281+ stdout += data . toString ( ) ;
282+ } ) ;
283+
284+ let stderr = "" ;
285+ server . stderr . on ( "data" , ( data ) => {
286+ stderr += data . toString ( ) ;
287+ } ) ;
288+
289+ // Wait for the server to start
290+ await timeout ( 2000 ) ;
291+
292+ await Promise . all (
293+ Array . from ( { length : 15 } ) . map ( ( ) =>
294+ fetch ( `http://localhost:${ port4 } /.env` , {
295+ headers : {
296+ "x-forwarded-for" : "1.2.3.4" ,
297+ } ,
298+ } )
299+ )
300+ ) ;
301+
302+ // Wait for the attack wave event to be sent
303+ await timeout ( 2000 ) ;
304+
305+ const eventsResponse = await fetch ( `${ testServerUrl } /api/runtime/events` , {
306+ method : "GET" ,
307+ headers : {
308+ Authorization : token ,
309+ } ,
310+ signal : AbortSignal . timeout ( 5000 ) ,
311+ } ) ;
312+
313+ const events = await eventsResponse . json ( ) ;
314+ const attackWaveEvents = events . filter (
315+ ( event ) => event . type === "detected_attack_wave"
316+ ) ;
317+ equal ( attackWaveEvents . length , 0 ) ;
318+ } catch ( err ) {
319+ fail ( err ) ;
320+ } finally {
321+ server . kill ( ) ;
322+ }
323+ } ) ;
0 commit comments