11import datadog.trace.agent.test.AgentTestRunner
2+ import datadog.trace.agent.tooling.InstrumenterModule
23import datadog.trace.api.Config
4+ import datadog.trace.api.ProductActivation
35import datadog.trace.api.config.AppSecConfig
46import datadog.trace.api.config.IastConfig
57import datadog.trace.instrumentation.iastinstrumenter.IastInstrumentation
@@ -10,24 +12,50 @@ class IastInstrumentationForkedTest extends AgentTestRunner {
1012 @Shared
1113 boolean iastEnabled = false
1214
15+ @Shared
16+ def appSecActivation = ProductActivation . ENABLED_INACTIVE
17+
1318 @Shared
1419 boolean raspEnabled = false
1520
21+ @Shared
22+ boolean applicable = false
23+
1624 @Shared
1725 Set<Class<?> > expectedCallSites = []
1826
27+ Set<InstrumenterModule.TargetSystem > enabledSystems
28+
1929 @Override
2030 protected void configurePreAgent () {
2131 injectSysConfig(IastConfig . IAST_ENABLED , iastEnabled. toString())
2232 injectSysConfig(AppSecConfig . APPSEC_RASP_ENABLED , raspEnabled. toString())
33+ enabledSystems = new HashSet<> ()
34+ if (iastEnabled) {
35+ enabledSystems. add(InstrumenterModule.TargetSystem . IAST )
36+ }
37+ if (appSecActivation == ProductActivation . ENABLED_INACTIVE ) {
38+ enabledSystems. add(InstrumenterModule.TargetSystem . APPSEC )
39+ } else if (appSecActivation == ProductActivation . FULLY_ENABLED ) {
40+ enabledSystems. add(InstrumenterModule.TargetSystem . APPSEC )
41+ injectSysConfig(AppSecConfig . APPSEC_ENABLED , " true" )
42+ } else {
43+ injectSysConfig(AppSecConfig . APPSEC_ENABLED , " false" )
44+ }
2345 }
2446
2547 void ' test Iast Instrumentation call site supplier' () {
2648 given :
2749 final instrumentation = new IastInstrumentation ()
2850
2951 when :
30- final callSites = instrumentation. callSites(). get(). toList()
52+ final shouldApply = instrumentation. isApplicable(enabledSystems)
53+
54+ then :
55+ shouldApply == applicable
56+
57+ when :
58+ final callSites = ! applicable ? [] : instrumentation. callSites(). get(). toList()
3159
3260 then :
3361 callSites. size() == expectedCallSites. size()
@@ -47,25 +75,63 @@ class IastForkedTest extends IastInstrumentationForkedTest {
4775
4876 boolean iastEnabled = true
4977
78+ def appSecActivation = ProductActivation . ENABLED_INACTIVE
79+
5080 boolean raspEnabled = false
5181
82+ boolean applicable = true
83+
5284 Set<Class<?> > expectedCallSites = [MockCallSites , MockCallSitesWithTelemetry ]
5385}
5486
55- class RaspForkedTest extends IastInstrumentationForkedTest {
87+ class AppSecInactiveRaspForkedTest extends IastInstrumentationForkedTest {
5688
5789 boolean iastEnabled = false
5890
91+ def appSecActivation = ProductActivation . ENABLED_INACTIVE
92+
5993 boolean raspEnabled = true
6094
95+ boolean applicable = false
96+
97+ Set<Class<?> > expectedCallSites = []
98+ }
99+
100+ class AppSecDisabledRaspForkedTest extends IastInstrumentationForkedTest {
101+
102+ boolean iastEnabled = false
103+
104+ def appSecActivation = ProductActivation . FULLY_DISABLED
105+
106+ boolean raspEnabled = true
107+
108+ boolean applicable = false
109+
110+ Set<Class<?> > expectedCallSites = []
111+ }
112+
113+ class AppSecEnabledRaspForkedTest extends IastInstrumentationForkedTest {
114+
115+ boolean iastEnabled = false
116+
117+ def appSecActivation = ProductActivation . FULLY_ENABLED
118+
119+ boolean raspEnabled = true
120+
121+ boolean applicable = true
122+
61123 Set<Class<?> > expectedCallSites = [MockRaspCallSites ]
62124}
63125
64126class AllCallSitesForkedTest extends IastInstrumentationForkedTest {
65127
66128 boolean iastEnabled = true
67129
130+ def appSecActivation = ProductActivation . FULLY_ENABLED
131+
68132 boolean raspEnabled = true
69133
134+ boolean applicable = true
135+
70136 Set<Class<?> > expectedCallSites = [MockCallSites , MockCallSitesWithTelemetry , MockRaspCallSites ]
71137}
0 commit comments