Skip to content

Commit cf855f7

Browse files
committed
Add another test
1 parent 996ab77 commit cf855f7

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

dd-java-agent/instrumentation/java-lang/src/test/groovy/datadog/trace/instrumentation/java/lang/RuntimeInstrumentationForkedTest.groovy

+33-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class RuntimeInstrumentationForkedTest extends AgentTestRunner{
6363
// ignore
6464
}
6565

66-
6766
then:
6867
cmdiExpected * callbackProvider.getCallback(EVENTS.execCmd()) >> listener
6968
shiExpected * callbackProvider.getCallback(EVENTS.shellCmd()) >> listener
@@ -78,4 +77,37 @@ class RuntimeInstrumentationForkedTest extends AgentTestRunner{
7877
[['/bin/evilCommand'] as String[], ['test'] as String[]] | 1 | 0
7978
[['/bin/evilCommand'] as String[], ['test'] as String[], new File('')] | 1 | 0
8079
}
80+
81+
void 'test shiCheck reset'() {
82+
83+
setup:
84+
final callbackProvider = Mock(CallbackProvider)
85+
final listener = Mock(BiFunction)
86+
final flow = Mock(Flow)
87+
tracer.getCallbackProvider(RequestContextSlot.APPSEC) >> callbackProvider
88+
89+
when:
90+
try {
91+
Runtime.getRuntime().exec('$(cat /etc/passwd 1>&2 ; echo .)')
92+
}catch (Exception e){
93+
// ignore
94+
}
95+
96+
then:
97+
0 * callbackProvider.getCallback(EVENTS.execCmd()) >> listener
98+
1 * callbackProvider.getCallback(EVENTS.shellCmd()) >> listener
99+
1 * listener.apply(reqCtx, _) >> flow
100+
101+
when:
102+
try {
103+
Runtime.getRuntime().exec(['/bin/evilCommand'] as String[])
104+
}catch (Exception e){
105+
// ignore
106+
}
107+
108+
then:
109+
1 * callbackProvider.getCallback(EVENTS.execCmd()) >> listener
110+
0 * callbackProvider.getCallback(EVENTS.shellCmd()) >> listener
111+
1 * listener.apply(reqCtx, _) >> flow
112+
}
81113
}

0 commit comments

Comments
 (0)