@@ -25,13 +25,35 @@ describe('Standalone ASM', () => {
25
25
await sandbox . remove ( )
26
26
} )
27
27
28
+ function assertKeep ( { meta, metrics } ) {
29
+ assert . propertyVal ( meta , '_dd.p.ts' , '02' )
30
+
31
+ assert . propertyVal ( metrics , '_sampling_priority_v1' , USER_KEEP )
32
+ assert . propertyVal ( metrics , '_dd.apm.enabled' , 0 )
33
+ }
34
+
35
+ function assertDrop ( { meta, metrics } ) {
36
+ assert . notProperty ( meta , '_dd.p.ts' )
37
+
38
+ assert . propertyVal ( metrics , '_sampling_priority_v1' , AUTO_REJECT )
39
+ assert . propertyVal ( metrics , '_dd.apm.enabled' , 0 )
40
+ }
41
+
42
+ async function doWarmupRequests ( procOrUrl , number = 3 ) {
43
+ for ( let i = number ; i > 0 ; i -- ) {
44
+ await curl ( procOrUrl )
45
+ }
46
+ }
47
+
28
48
describe ( 'enabled' , ( ) => {
29
49
beforeEach ( async ( ) => {
30
50
agent = await new FakeAgent ( ) . start ( )
31
51
32
52
env = {
33
53
AGENT_PORT : agent . port ,
34
- DD_EXPERIMENTAL_APPSEC_STANDALONE_ENABLED : 'true'
54
+ DD_APM_TRACING_ENABLED : 'false' ,
55
+ DD_APPSEC_ENABLED : 'true' ,
56
+ DD_API_SECURITY_ENABLED : 'false'
35
57
}
36
58
37
59
const execArgv = [ ]
@@ -44,28 +66,6 @@ describe('Standalone ASM', () => {
44
66
await agent . stop ( )
45
67
} )
46
68
47
- function assertKeep ( payload ) {
48
- const { meta, metrics } = payload
49
-
50
- assert . propertyVal ( meta , '_dd.p.ts' , '02' )
51
-
52
- assert . propertyVal ( metrics , '_sampling_priority_v1' , USER_KEEP )
53
- assert . propertyVal ( metrics , '_dd.apm.enabled' , 0 )
54
- }
55
-
56
- function assertDrop ( payload ) {
57
- const { metrics } = payload
58
- assert . propertyVal ( metrics , '_sampling_priority_v1' , AUTO_REJECT )
59
- assert . propertyVal ( metrics , '_dd.apm.enabled' , 0 )
60
- assert . notProperty ( metrics , '_dd.p.ts' )
61
- }
62
-
63
- async function doWarmupRequests ( procOrUrl , number = 3 ) {
64
- for ( let i = number ; i > 0 ; i -- ) {
65
- await curl ( procOrUrl )
66
- }
67
- }
68
-
69
69
// first req initializes the waf and reports the first appsec event adding manual.keep tag
70
70
it ( 'should send correct headers and tags on first req' , async ( ) => {
71
71
return curlAndAssertMessage ( agent , proc , ( { headers, payload } ) => {
@@ -254,6 +254,58 @@ describe('Standalone ASM', () => {
254
254
} )
255
255
} )
256
256
257
+ describe ( 'With API Security enabled' , ( ) => {
258
+ beforeEach ( async ( ) => {
259
+ agent = await new FakeAgent ( ) . start ( )
260
+
261
+ env = {
262
+ AGENT_PORT : agent . port ,
263
+ DD_APM_TRACING_ENABLED : 'false' ,
264
+ DD_APPSEC_ENABLED : 'true'
265
+ }
266
+
267
+ const execArgv = [ ]
268
+
269
+ proc = await spawnProc ( startupTestFile , { cwd, env, execArgv } )
270
+ } )
271
+
272
+ afterEach ( async ( ) => {
273
+ proc . kill ( )
274
+ await agent . stop ( )
275
+ } )
276
+
277
+ it ( 'should keep fifth req because of api security sampler' , async ( ) => {
278
+ const promise = curlAndAssertMessage ( agent , proc , ( { headers, payload } ) => {
279
+ assert . propertyVal ( headers , 'datadog-client-computed-stats' , 'yes' )
280
+ assert . isArray ( payload )
281
+ if ( payload . length === 4 ) {
282
+ assertKeep ( payload [ 0 ] [ 0 ] )
283
+ assertDrop ( payload [ 1 ] [ 0 ] )
284
+ assertDrop ( payload [ 2 ] [ 0 ] )
285
+ assertDrop ( payload [ 3 ] [ 0 ] )
286
+
287
+ // req after 30s
288
+ } else {
289
+ const fifthReq = payload [ 0 ]
290
+ assert . isArray ( fifthReq )
291
+ assert . strictEqual ( fifthReq . length , 5 )
292
+ assertKeep ( fifthReq [ 0 ] )
293
+ }
294
+ } , 40000 , 2 )
295
+
296
+ // 1st req kept because waf init
297
+ // next in the 30s are dropped
298
+ // 5nd req manual kept because of api security sampler
299
+ await doWarmupRequests ( proc )
300
+
301
+ await new Promise ( resolve => setTimeout ( resolve , 30000 ) )
302
+
303
+ await curl ( proc )
304
+
305
+ return promise
306
+ } ) . timeout ( 40000 )
307
+ } )
308
+
257
309
describe ( 'disabled' , ( ) => {
258
310
beforeEach ( async ( ) => {
259
311
agent = await new FakeAgent ( ) . start ( )
0 commit comments