Skip to content

Commit

Permalink
Replaced unused Mocks with Stubs in Iast (#6377)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinZakharov authored Dec 18, 2023
1 parent 326dfc5 commit ce0c8c4
Show file tree
Hide file tree
Showing 27 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class LocationTest extends DDSpecification {

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

void 'forSpanAndClassAndMethod'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final declaringClass = "declaringClass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ class VulnerabilityTypeTest extends DDSpecification {
}

private Location getSpanAndStackLocation(final long spanId) {
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
span.getSpanId() >> spanId
return Location.forSpanAndStack(span, new StackTraceElement("foo", "foo", "foo", 1))
}

private Location getSpanAndClassAndMethodLocation(final long spanId) {
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
span.getSpanId() >> spanId
return Location.forSpanAndClassAndMethod(span, "foo", "foo")
}

private Location getSpanLocation(final long spanId, final String serviceName) {
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
span.getSpanId() >> spanId
span.getServiceName() >> serviceName
return Location.forSpan(span)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EvidenceRedactionTest extends DDSpecification {

void 'test empty value parts'() {
given:
final writer = Mock(JsonWriter)
final writer = Stub(JsonWriter)
final ctx = new AdapterFactory.Context()

when:
Expand All @@ -70,8 +70,8 @@ class EvidenceRedactionTest extends DDSpecification {
new StringValuePart(null) | _
new StringValuePart('') | _
new RedactedValuePart(null) | _
new TaintedValuePart(Mock(JsonAdapter), null, null, true) | _
new TaintedValuePart(Mock(JsonAdapter), null, null, false) | _
new TaintedValuePart(Stub(JsonAdapter), null, null, true) | _
new TaintedValuePart(Stub(JsonAdapter), null, null, false) | _
}

void 'test #suite'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'one vulnerability'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -115,7 +115,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'one vulnerability with one source'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -160,7 +160,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'one vulnerability with two sources'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -214,7 +214,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'one vulnerability with null source'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -252,7 +252,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'one vulnerability with no source type'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -296,7 +296,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'two vulnerabilities with one shared source'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -363,7 +363,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'two vulnerability with no shared sources'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -434,7 +434,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'one truncated vulnerability'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -469,7 +469,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'two truncated vulnerabilities'() {
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand Down Expand Up @@ -522,7 +522,7 @@ class VulnerabilityEncodingTest extends DDSpecification {

void 'when json is greater than 25kb VulnerabilityEncoding#getExceededTagSizeJson is called'(){
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
final spanId = 123456
span.getSpanId() >> spanId
final value = new VulnerabilityBatch()
Expand All @@ -542,7 +542,7 @@ class VulnerabilityEncodingTest extends DDSpecification {
void 'exception during serialization is caught'() {
given:
final value = new VulnerabilityBatch()
final type = Mock(VulnerabilityType) {
final type = Stub(VulnerabilityType) {
name() >> { throw new RuntimeException("ERROR") }
}
final vuln = new Vulnerability(type, null, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class OverheadControllerTest extends DDSpecification {
given:
def taskSchedler = Stub(AgentTaskScheduler)
def overheadController = OverheadController.build(Config.get(), taskSchedler)
def overheadContext = Mock(OverheadContext)
def overheadContext = Stub(OverheadContext)
def iastRequestContext = Stub(IastRequestContext)
iastRequestContext.getOverheadContext() >> overheadContext
def requestContext = Stub(RequestContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class AbstractSinkModuleTest extends IastModuleImplTestBase {

void setup() {
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getRequestContext() >> reqCtx
}
tracer.activeSpan() >> span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class CommandInjectionModuleTest extends IastModuleImplTestBase {
module = new CommandInjectionModuleImpl(dependencies)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class HstsMissingHeaderModuleTest extends IastModuleImplTestBase {
InstrumentationBridge.registerIastModule(module)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HttpResponseHeaderModuleTest extends IastModuleImplTestBase {
InstrumentationBridge.registerIastModule(new UnvalidatedRedirectModuleImpl(dependencies))
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
Expand Down Expand Up @@ -100,7 +100,7 @@ class HttpResponseHeaderModuleTest extends IastModuleImplTestBase {

void 'exercise IastRequestController'(){
given:
final taintedObjects = Mock(TaintedObjects)
final taintedObjects = Stub(TaintedObjects)
IastRequestContext ctx = new IastRequestContext(taintedObjects)

when:
Expand All @@ -112,8 +112,8 @@ class HttpResponseHeaderModuleTest extends IastModuleImplTestBase {

void 'exercise IastRequestContext'(){
given:
final taintedObjects = Mock(TaintedObjects)
final iastMetricsCollector = Mock(IastMetricCollector)
final taintedObjects = Stub(TaintedObjects)
final iastMetricsCollector = Stub(IastMetricCollector)

when:
IastRequestContext ctx = new IastRequestContext(taintedObjects, iastMetricsCollector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class InsecureCookieModuleTest extends IastModuleImplTestBase {
InstrumentationBridge.registerIastModule(new InsecureCookieModuleImpl())
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class LdapInjectionModuleTest extends IastModuleImplTestBase {
module = new LdapInjectionModuleImpl(dependencies)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class NoHttpCookieModuleTest extends IastModuleImplTestBase {
InstrumentationBridge.registerIastModule(new NoHttpOnlyCookieModuleImpl())
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class NoSameSiteCookieModuleTest extends IastModuleImplTestBase {
InstrumentationBridge.registerIastModule(new NoSameSiteCookieModuleImpl())
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class PathTraversalModuleTest extends IastModuleImplTestBase {
module = new PathTraversalModuleImpl(dependencies)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
final span = Mock(AgentSpan) {
final span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class SqlInjectionModuleTest extends IastModuleImplTestBase {
module = new SqlInjectionModuleImpl(dependencies)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
final span = Mock(AgentSpan) {
final span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class SsrfModuleTest extends IastModuleImplTestBase {
module = new SsrfModuleImpl(dependencies)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class TrustBoundaryViolationModuleTest extends IastModuleImplTestBase {
module = new TrustBoundaryViolationModuleImpl(dependencies)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class UnvalidatedRedirectModuleTest extends IastModuleImplTestBase {
module = new UnvalidatedRedirectModuleImpl(dependencies)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
final span = Mock(AgentSpan) {
final span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WeakCipherModuleTest extends IastModuleImplTestBase {

void 'iast module not blocklisted cipher algorithm'(){
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
tracer.activeSpan() >> span

when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WeakHashModuleTest extends IastModuleImplTestBase {

void 'iast module secure hash algorithm'(){
given:
final span = Mock(AgentSpan)
final span = Stub(AgentSpan)
tracer.activeSpan() >> span

when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WeakRandomnessModuleTest extends IastModuleImplTestBase {

def setup() {
module = new WeakRandomnessModuleImpl(dependencies)
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class XContentTypeOptionsModuleTest extends IastModuleImplTestBase {
InstrumentationBridge.registerIastModule(module)
objectHolder = []
ctx = new IastRequestContext()
final reqCtx = Mock(RequestContext) {
final reqCtx = Stub(RequestContext) {
getData(RequestContextSlot.IAST) >> ctx
}
span = Mock(AgentSpan) {
span = Stub(AgentSpan) {
getSpanId() >> 123456
getRequestContext() >> reqCtx
}
Expand Down
Loading

0 comments on commit ce0c8c4

Please sign in to comment.