Skip to content

Commit 0419897

Browse files
Replaced unused Mocks with Stubs in Iast
1 parent 7a1a4ca commit 0419897

28 files changed

+65
-65
lines changed

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/model/LocationTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class LocationTest extends DDSpecification {
77

88
void 'forStack'() {
99
given:
10-
final span = Mock(AgentSpan)
10+
final span = Stub(AgentSpan)
1111
final spanId = 123456
1212
span.getSpanId() >> spanId
1313
final stack = new StackTraceElement("declaringClass", "methodName", "fileName", 42)
@@ -24,7 +24,7 @@ class LocationTest extends DDSpecification {
2424

2525
void 'forSpanAndClassAndMethod'() {
2626
given:
27-
final span = Mock(AgentSpan)
27+
final span = Stub(AgentSpan)
2828
final spanId = 123456
2929
span.getSpanId() >> spanId
3030
final declaringClass = "declaringClass"

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/model/VulnerabilityTypeTest.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ class VulnerabilityTypeTest extends DDSpecification {
4545
}
4646

4747
private Location getSpanAndStackLocation(final long spanId) {
48-
final span = Mock(AgentSpan)
48+
final span = Stub(AgentSpan)
4949
span.getSpanId() >> spanId
5050
return Location.forSpanAndStack(span, new StackTraceElement("foo", "foo", "foo", 1))
5151
}
5252

5353
private Location getSpanAndClassAndMethodLocation(final long spanId) {
54-
final span = Mock(AgentSpan)
54+
final span = Stub(AgentSpan)
5555
span.getSpanId() >> spanId
5656
return Location.forSpanAndClassAndMethod(span, "foo", "foo")
5757
}
5858

5959
private Location getSpanLocation(final long spanId, final String serviceName) {
60-
final span = Mock(AgentSpan)
60+
final span = Stub(AgentSpan)
6161
span.getSpanId() >> spanId
6262
span.getServiceName() >> serviceName
6363
return Location.forSpan(span)

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/model/json/EvidenceRedactionTest.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class EvidenceRedactionTest extends DDSpecification {
5656

5757
void 'test empty value parts'() {
5858
given:
59-
final writer = Mock(JsonWriter)
59+
final writer = Stub(JsonWriter)
6060
final ctx = new AdapterFactory.Context()
6161

6262
when:
@@ -70,8 +70,8 @@ class EvidenceRedactionTest extends DDSpecification {
7070
new StringValuePart(null) | _
7171
new StringValuePart('') | _
7272
new RedactedValuePart(null) | _
73-
new TaintedValuePart(Mock(JsonAdapter), null, null, true) | _
74-
new TaintedValuePart(Mock(JsonAdapter), null, null, false) | _
73+
new TaintedValuePart(Stub(JsonAdapter), null, null, true) | _
74+
new TaintedValuePart(Stub(JsonAdapter), null, null, false) | _
7575
}
7676

7777
void 'test #suite'() {

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/model/json/VulnerabilityEncodingTest.groovy

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
4949

5050
void 'one vulnerability'() {
5151
given:
52-
final span = Mock(AgentSpan)
52+
final span = Stub(AgentSpan)
5353
final spanId = 123456
5454
span.getSpanId() >> spanId
5555
final value = new VulnerabilityBatch()
@@ -115,7 +115,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
115115

116116
void 'one vulnerability with one source'() {
117117
given:
118-
final span = Mock(AgentSpan)
118+
final span = Stub(AgentSpan)
119119
final spanId = 123456
120120
span.getSpanId() >> spanId
121121
final value = new VulnerabilityBatch()
@@ -160,7 +160,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
160160

161161
void 'one vulnerability with two sources'() {
162162
given:
163-
final span = Mock(AgentSpan)
163+
final span = Stub(AgentSpan)
164164
final spanId = 123456
165165
span.getSpanId() >> spanId
166166
final value = new VulnerabilityBatch()
@@ -214,7 +214,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
214214

215215
void 'one vulnerability with null source'() {
216216
given:
217-
final span = Mock(AgentSpan)
217+
final span = Stub(AgentSpan)
218218
final spanId = 123456
219219
span.getSpanId() >> spanId
220220
final value = new VulnerabilityBatch()
@@ -252,7 +252,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
252252

253253
void 'one vulnerability with no source type'() {
254254
given:
255-
final span = Mock(AgentSpan)
255+
final span = Stub(AgentSpan)
256256
final spanId = 123456
257257
span.getSpanId() >> spanId
258258
final value = new VulnerabilityBatch()
@@ -296,7 +296,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
296296

297297
void 'two vulnerabilities with one shared source'() {
298298
given:
299-
final span = Mock(AgentSpan)
299+
final span = Stub(AgentSpan)
300300
final spanId = 123456
301301
span.getSpanId() >> spanId
302302
final value = new VulnerabilityBatch()
@@ -363,7 +363,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
363363

364364
void 'two vulnerability with no shared sources'() {
365365
given:
366-
final span = Mock(AgentSpan)
366+
final span = Stub(AgentSpan)
367367
final spanId = 123456
368368
span.getSpanId() >> spanId
369369
final value = new VulnerabilityBatch()
@@ -434,7 +434,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
434434

435435
void 'one truncated vulnerability'() {
436436
given:
437-
final span = Mock(AgentSpan)
437+
final span = Stub(AgentSpan)
438438
final spanId = 123456
439439
span.getSpanId() >> spanId
440440
final value = new VulnerabilityBatch()
@@ -469,7 +469,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
469469

470470
void 'two truncated vulnerabilities'() {
471471
given:
472-
final span = Mock(AgentSpan)
472+
final span = Stub(AgentSpan)
473473
final spanId = 123456
474474
span.getSpanId() >> spanId
475475
final value = new VulnerabilityBatch()
@@ -522,7 +522,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
522522

523523
void 'when json is greater than 25kb VulnerabilityEncoding#getExceededTagSizeJson is called'(){
524524
given:
525-
final span = Mock(AgentSpan)
525+
final span = Stub(AgentSpan)
526526
final spanId = 123456
527527
span.getSpanId() >> spanId
528528
final value = new VulnerabilityBatch()
@@ -542,7 +542,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
542542
void 'exception during serialization is caught'() {
543543
given:
544544
final value = new VulnerabilityBatch()
545-
final type = Mock(VulnerabilityType) {
545+
final type = Stub(VulnerabilityType) {
546546
name() >> { throw new RuntimeException("ERROR") }
547547
}
548548
final vuln = new Vulnerability(type, null, null)

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/overhead/OverheadControllerTest.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class OverheadControllerTest extends DDSpecification {
141141
given:
142142
def taskSchedler = Stub(AgentTaskScheduler)
143143
def overheadController = OverheadController.build(Config.get(), taskSchedler)
144-
def overheadContext = Mock(OverheadContext)
144+
def overheadContext = Stub(OverheadContext)
145145
def iastRequestContext = Stub(IastRequestContext)
146146
iastRequestContext.getOverheadContext() >> overheadContext
147147
def requestContext = Stub(RequestContext)

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/AbstractSinkModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class AbstractSinkModuleTest extends IastModuleImplTestBase {
2424

2525
void setup() {
2626
ctx = new IastRequestContext()
27-
final reqCtx = Mock(RequestContext) {
27+
final reqCtx = Stub(RequestContext) {
2828
getData(RequestContextSlot.IAST) >> ctx
2929
}
30-
span = Mock(AgentSpan) {
30+
span = Stub(AgentSpan) {
3131
getRequestContext() >> reqCtx
3232
}
3333
tracer.activeSpan() >> span

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/CommandInjectionModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class CommandInjectionModuleTest extends IastModuleImplTestBase {
3030
module = new CommandInjectionModuleImpl(dependencies)
3131
objectHolder = []
3232
ctx = new IastRequestContext()
33-
final reqCtx = Mock(RequestContext) {
33+
final reqCtx = Stub(RequestContext) {
3434
getData(RequestContextSlot.IAST) >> ctx
3535
}
36-
span = Mock(AgentSpan) {
36+
span = Stub(AgentSpan) {
3737
getSpanId() >> 123456
3838
getRequestContext() >> reqCtx
3939
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/HstsMissingHeaderModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class HstsMissingHeaderModuleTest extends IastModuleImplTestBase {
2929
InstrumentationBridge.registerIastModule(module)
3030
objectHolder = []
3131
ctx = new IastRequestContext()
32-
final reqCtx = Mock(RequestContext) {
32+
final reqCtx = Stub(RequestContext) {
3333
getData(RequestContextSlot.IAST) >> ctx
3434
}
35-
span = Mock(AgentSpan) {
35+
span = Stub(AgentSpan) {
3636
getSpanId() >> 123456
3737
getRequestContext() >> reqCtx
3838
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/HttpResponseHeaderModuleTest.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class HttpResponseHeaderModuleTest extends IastModuleImplTestBase {
3434
InstrumentationBridge.registerIastModule(new UnvalidatedRedirectModuleImpl(dependencies))
3535
objectHolder = []
3636
ctx = new IastRequestContext()
37-
final reqCtx = Mock(RequestContext) {
37+
final reqCtx = Stub(RequestContext) {
3838
getData(RequestContextSlot.IAST) >> ctx
3939
}
4040
span = Mock(AgentSpan) {
@@ -100,7 +100,7 @@ class HttpResponseHeaderModuleTest extends IastModuleImplTestBase {
100100

101101
void 'exercise IastRequestController'(){
102102
given:
103-
final taintedObjects = Mock(TaintedObjects)
103+
final taintedObjects = Stub(TaintedObjects)
104104
IastRequestContext ctx = new IastRequestContext(taintedObjects)
105105

106106
when:
@@ -112,8 +112,8 @@ class HttpResponseHeaderModuleTest extends IastModuleImplTestBase {
112112

113113
void 'exercise IastRequestContext'(){
114114
given:
115-
final taintedObjects = Mock(TaintedObjects)
116-
final iastMetricsCollector = Mock(IastMetricCollector)
115+
final taintedObjects = Stub(TaintedObjects)
116+
final iastMetricsCollector = Stub(IastMetricCollector)
117117

118118
when:
119119
IastRequestContext ctx = new IastRequestContext(taintedObjects, iastMetricsCollector)

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/InsecureCookieModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class InsecureCookieModuleTest extends IastModuleImplTestBase {
2828
InstrumentationBridge.registerIastModule(new InsecureCookieModuleImpl())
2929
objectHolder = []
3030
ctx = new IastRequestContext()
31-
final reqCtx = Mock(RequestContext) {
31+
final reqCtx = Stub(RequestContext) {
3232
getData(RequestContextSlot.IAST) >> ctx
3333
}
34-
span = Mock(AgentSpan) {
34+
span = Stub(AgentSpan) {
3535
getSpanId() >> 123456
3636
getRequestContext() >> reqCtx
3737
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/LdapInjectionModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class LdapInjectionModuleTest extends IastModuleImplTestBase {
3030
module = new LdapInjectionModuleImpl(dependencies)
3131
objectHolder = []
3232
ctx = new IastRequestContext()
33-
final reqCtx = Mock(RequestContext) {
33+
final reqCtx = Stub(RequestContext) {
3434
getData(RequestContextSlot.IAST) >> ctx
3535
}
36-
span = Mock(AgentSpan) {
36+
span = Stub(AgentSpan) {
3737
getSpanId() >> 123456
3838
getRequestContext() >> reqCtx
3939
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/NoHttpCookieModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class NoHttpCookieModuleTest extends IastModuleImplTestBase {
2828
InstrumentationBridge.registerIastModule(new NoHttpOnlyCookieModuleImpl())
2929
objectHolder = []
3030
ctx = new IastRequestContext()
31-
final reqCtx = Mock(RequestContext) {
31+
final reqCtx = Stub(RequestContext) {
3232
getData(RequestContextSlot.IAST) >> ctx
3333
}
34-
span = Mock(AgentSpan) {
34+
span = Stub(AgentSpan) {
3535
getSpanId() >> 123456
3636
getRequestContext() >> reqCtx
3737
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/NoSameSiteCookieModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class NoSameSiteCookieModuleTest extends IastModuleImplTestBase {
2828
InstrumentationBridge.registerIastModule(new NoSameSiteCookieModuleImpl())
2929
objectHolder = []
3030
ctx = new IastRequestContext()
31-
final reqCtx = Mock(RequestContext) {
31+
final reqCtx = Stub(RequestContext) {
3232
getData(RequestContextSlot.IAST) >> ctx
3333
}
34-
span = Mock(AgentSpan) {
34+
span = Stub(AgentSpan) {
3535
getSpanId() >> 123456
3636
getRequestContext() >> reqCtx
3737
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/PathTraversalModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class PathTraversalModuleTest extends IastModuleImplTestBase {
3030
module = new PathTraversalModuleImpl(dependencies)
3131
objectHolder = []
3232
ctx = new IastRequestContext()
33-
final reqCtx = Mock(RequestContext) {
33+
final reqCtx = Stub(RequestContext) {
3434
getData(RequestContextSlot.IAST) >> ctx
3535
}
36-
final span = Mock(AgentSpan) {
36+
final span = Stub(AgentSpan) {
3737
getSpanId() >> 123456
3838
getRequestContext() >> reqCtx
3939
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/SqlInjectionModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class SqlInjectionModuleTest extends IastModuleImplTestBase {
2727
module = new SqlInjectionModuleImpl(dependencies)
2828
objectHolder = []
2929
ctx = new IastRequestContext()
30-
final reqCtx = Mock(RequestContext) {
30+
final reqCtx = Stub(RequestContext) {
3131
getData(RequestContextSlot.IAST) >> ctx
3232
}
33-
final span = Mock(AgentSpan) {
33+
final span = Stub(AgentSpan) {
3434
getSpanId() >> 123456
3535
getRequestContext() >> reqCtx
3636
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/SsrfModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class SsrfModuleTest extends IastModuleImplTestBase {
2828
module = new SsrfModuleImpl(dependencies)
2929
objectHolder = []
3030
ctx = new IastRequestContext()
31-
final reqCtx = Mock(RequestContext) {
31+
final reqCtx = Stub(RequestContext) {
3232
getData(RequestContextSlot.IAST) >> ctx
3333
}
34-
span = Mock(AgentSpan) {
34+
span = Stub(AgentSpan) {
3535
getSpanId() >> 123456
3636
getRequestContext() >> reqCtx
3737
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/TrustBoundaryViolationModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class TrustBoundaryViolationModuleTest extends IastModuleImplTestBase {
2828
module = new TrustBoundaryViolationModuleImpl(dependencies)
2929
objectHolder = []
3030
ctx = new IastRequestContext()
31-
final reqCtx = Mock(RequestContext) {
31+
final reqCtx = Stub(RequestContext) {
3232
getData(RequestContextSlot.IAST) >> ctx
3333
}
34-
span = Mock(AgentSpan) {
34+
span = Stub(AgentSpan) {
3535
getSpanId() >> 123456
3636
getRequestContext() >> reqCtx
3737
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/UnvalidatedRedirectModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class UnvalidatedRedirectModuleTest extends IastModuleImplTestBase {
3131
module = new UnvalidatedRedirectModuleImpl(dependencies)
3232
objectHolder = []
3333
ctx = new IastRequestContext()
34-
final reqCtx = Mock(RequestContext) {
34+
final reqCtx = Stub(RequestContext) {
3535
getData(RequestContextSlot.IAST) >> ctx
3636
}
37-
final span = Mock(AgentSpan) {
37+
final span = Stub(AgentSpan) {
3838
getSpanId() >> 123456
3939
getRequestContext() >> reqCtx
4040
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/WeakCipherModuleTest.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class WeakCipherModuleTest extends IastModuleImplTestBase {
6868

6969
void 'iast module not blocklisted cipher algorithm'(){
7070
given:
71-
final span = Mock(AgentSpan)
71+
final span = Stub(AgentSpan)
7272
tracer.activeSpan() >> span
7373

7474
when:

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/WeakHashModuleTest.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class WeakHashModuleTest extends IastModuleImplTestBase {
4949

5050
void 'iast module secure hash algorithm'(){
5151
given:
52-
final span = Mock(AgentSpan)
52+
final span = Stub(AgentSpan)
5353
tracer.activeSpan() >> span
5454

5555
when:

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/WeakRandomnessModuleTest.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class WeakRandomnessModuleTest extends IastModuleImplTestBase {
1515

1616
def setup() {
1717
module = new WeakRandomnessModuleImpl(dependencies)
18-
span = Mock(AgentSpan) {
18+
span = Stub(AgentSpan) {
1919
getSpanId() >> 123456
2020
}
2121
}

dd-java-agent/agent-iast/src/test/groovy/com/datadog/iast/sink/XContentTypeOptionsModuleTest.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public class XContentTypeOptionsModuleTest extends IastModuleImplTestBase {
2929
InstrumentationBridge.registerIastModule(module)
3030
objectHolder = []
3131
ctx = new IastRequestContext()
32-
final reqCtx = Mock(RequestContext) {
32+
final reqCtx = Stub(RequestContext) {
3333
getData(RequestContextSlot.IAST) >> ctx
3434
}
35-
span = Mock(AgentSpan) {
35+
span = Stub(AgentSpan) {
3636
getSpanId() >> 123456
3737
getRequestContext() >> reqCtx
3838
}

0 commit comments

Comments
 (0)