Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ testing {
suites {
val test by getting(JvmTestSuite::class) {
dependencies {
implementation(libs.spock.core)
implementation(libs.groovy)
implementation(libs.spock.core)
}
targets.configureEach {
testTask.configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ dependencies {
implementation("com.github.javaparser", "javaparser-symbol-solver-core", "3.24.4")

testImplementation(libs.bytebuddy)
testImplementation(libs.spock.core)
testImplementation("org.objenesis", "objenesis", "3.0.1")
testImplementation(libs.groovy)
testImplementation(libs.bundles.spock)
testImplementation("javax.servlet", "javax.servlet-api", "3.0.1")
testImplementation("com.github.spotbugs", "spotbugs-annotations", "4.2.0")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package datadog.communication.http

import static org.junit.jupiter.api.Assertions.assertThrows

import org.junit.jupiter.api.Test

import java.util.concurrent.ExecutorService
import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.TimeUnit

import static groovy.test.GroovyAssert.shouldFail

class RejectingExecutorServiceTest {
ExecutorService executorService = new RejectingExecutorService()

@Test
void 'execute throws exception'() {
shouldFail(RejectedExecutionException) {
assertThrows(RejectedExecutionException) {
executorService.execute({})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.datadog.iast.test
import com.datadog.iast.model.VulnerabilityType
import com.datadog.iast.overhead.Operation
import com.datadog.iast.overhead.OverheadController
import com.github.javaparser.quality.Nullable
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
import groovy.transform.CompileStatic
import javax.annotation.Nullable

@CompileStatic
class NoopOverheadController implements OverheadController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ abstract class InstrumentationSpecification extends DDSpecification implements A
def sw = new StringWriter()
PrintWriter pw = new PrintWriter(sw)
entry.value.eachWithIndex { Exception e, int i ->
pw.write('\n' as char)
pw.write((char)'\n')
pw.write "Location $i:\n"
def st = e.stackTrace
int loc = st.findIndexOf {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class HttpServerTest extends InstrumentationSpecification {

then:
clientResponse.code() == 500
IOUtils.readFully (clientResponse.body().byteStream()).contains("assert body != null")
IOUtils.readFully(clientResponse.body().byteStream()).contains("assert body != null")

cleanup:
server.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TimerTaskContinuationTest extends InstrumentationSpecification {
def "test continuation activated when TimerTask runs (date)"() {
when:
runUnderTrace("parent", {
timer.schedule(timerTask, Instant.now().plusMillis(100).toDate())
timer.schedule(timerTask, Date.from(Instant.now().plusMillis(100)))
})
runLatch.await()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
import static datadog.trace.agent.test.utils.TraceUtils.runnableUnderTrace
import static java.time.Instant.now
import static java.time.temporal.ChronoUnit.SECONDS

import datadog.trace.agent.test.InstrumentationSpecification
import datadog.trace.api.Trace

import java.util.concurrent.Callable
import java.util.concurrent.StructuredTaskScope

import static datadog.trace.agent.test.utils.TraceUtils.runUnderTrace
import static datadog.trace.agent.test.utils.TraceUtils.runnableUnderTrace
import static java.time.Instant.now

class StructuredConcurrencyTest extends InstrumentationSpecification {
/**
* Tests the structured task scope with a single task.
Expand All @@ -26,7 +26,7 @@ class StructuredConcurrencyTest extends InstrumentationSpecification {
return true
}
})
taskScope.joinUntil(now() + 10) // Wait for 10 seconds at maximum
taskScope.joinUntil(now().plus(10, SECONDS))
result = task.get()
}
taskScope.close()
Expand Down Expand Up @@ -73,7 +73,7 @@ class StructuredConcurrencyTest extends InstrumentationSpecification {
taskScope.fork {
runnableUnderTrace("child3") {}
}
taskScope.joinUntil(now() + 10) // Wait for 10 seconds at maximum
taskScope.joinUntil(now().plus(10, SECONDS))
}
taskScope.close()

Expand Down Expand Up @@ -132,7 +132,7 @@ class StructuredConcurrencyTest extends InstrumentationSpecification {
taskScope.fork {
runnableUnderTrace("child2") {}
}
taskScope.joinUntil(now() + 10) // Wait for 10 seconds at maximum
taskScope.joinUntil(now().plus(10, SECONDS))
}
taskScope.close()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply from: "$rootDir/gradle/java.gradle"
dependencies {
compileOnly group: 'javax.ws.rs', name: 'jsr311-api', version: '1.1.1'

testImplementation libs.spock.junit4 // This legacy module still needs JUnit4.
testImplementation libs.spock.junit4 // This module still needs Spock with JUnit4.
testImplementation group: 'io.dropwizard', name: 'dropwizard-testing', version: '0.7.1'
testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3'
}
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/junit/junit-5.3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {

testImplementation project(':dd-java-agent:agent-ci-visibility:civisibility-instrumentation-test-fixtures')

testImplementation libs.junit4 // This module still needs JUnit4.

// versions used below are not the minimum ones that we support,
// but the tests need to use them in order to be compliant with Spock 2.x
testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: libs.versions.junit.platform.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class TestAssumptionLegacy {

@Test
public void test_fail_assumption_legacy() {
// Throw exception from legacy JUnit4 library.
throw new AssumptionViolatedException("assumption is not fulfilled");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
compileOnly group: 'org.apache.kafka', name: 'kafka-clients', version: '0.11.0.0'
implementation project(':dd-java-agent:instrumentation:kafka:kafka-common')

testImplementation libs.spock.junit4 // This legacy module still needs JUnit4.
testImplementation libs.spock.junit4 // This module still needs Spock with JUnit4.
testImplementation group: 'org.apache.kafka', name: 'kafka-clients', version: '0.11.0.0'
testImplementation group: 'org.springframework.kafka', name: 'spring-kafka', version: '1.3.3.RELEASE'
testImplementation group: 'org.springframework.kafka', name: 'spring-kafka-test', version: '1.3.3.RELEASE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {

// Include latest version of kafka itself along with latest version of client libs.
// This seems to help with jar compatibility hell.
latestDepTestImplementation libs.spock.junit4 // This module still needs Spock with JUnit4.
latestDepTestImplementation group: 'org.apache.kafka', name: 'kafka_2.13', version: '2.+'
latestDepTestImplementation group: 'org.apache.kafka', name: 'kafka-clients', version: '2.+'
latestDepTestImplementation group: 'org.apache.kafka', name: 'kafka-streams', version: '2.+'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies {
testImplementation project(':dd-java-agent:instrumentation:reactor-core-3.1')
testImplementation project(':dd-java-agent:instrumentation:reactive-streams')
testImplementation project(':dd-java-agent:instrumentation:reactor-netty-1')
testImplementation group: 'org.spockframework', name: 'spock-spring', version: '1.1-groovy-2.4'
testImplementation libs.spock.spring

testImplementation group: 'org.springframework', name: 'spring-webflux', version: '5.0.0.RELEASE'
testImplementation group: 'io.projectreactor.ipc', name: 'reactor-netty', version: '0.7.0.RELEASE'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import dd.trace.instrumentation.springwebflux.server.SpringWebFluxTestApplication
import org.junit.AfterClass
import org.junit.BeforeClass
import org.springframework.boot.test.context.SpringBootTest

/**
Expand All @@ -11,13 +9,11 @@ import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [SpringWebFluxTestApplication, ForceNettyAutoConfiguration])
class SingleThreadedSpringWebfluxTest extends SpringWebfluxTest {

@BeforeClass
static void init() {
def setup() {
System.setProperty("reactor.netty.ioWorkerCount", "1")
}

@AfterClass
static void teardown() {
def cleanup() {
System.clearProperty("reactor.netty.ioWorkerCount")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ abstract class AbstractIastSpringBootTest extends AbstractIastServerSmokeTest {
void 'untrusted deserialization for snakeyaml with a string'() {
setup:
final String yaml = "test"
final url = "http://localhost:${httpPort}/untrusted_deserialization/snakeyaml?yaml=${yaml}"
final url = "http://localhost:${httpPort}/untrusted_deserialization/snakeyaml?yaml=${yaml}".toString()
final request = new Request.Builder().url(url).get().build()

when:
Expand Down
4 changes: 0 additions & 4 deletions gradle/codenarc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ dependencies {
codenarc {
configFile = rootProject.file('gradle/enforcement/codenarc.groovy')
}

//codenarcTest {
// configFile rootProject.file('gradle/enforcement/codenarcTest.groovy')
//}
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ okio = "1.17.6" # Datadog fork

spock = "2.4-M6-groovy-3.0"
groovy = "3.0.24"
junit4 = "4.13.2"
junit5 = "5.12.2"
junit-platform = "1.12.2"
logback = "1.2.13"
Expand Down Expand Up @@ -75,6 +76,8 @@ objenesis = { module = "org.objenesis:objenesis", version = "3.3" } # Used by Sp

groovy = { module = "org.codehaus.groovy:groovy-all", version.ref = "groovy" }
groovy-yaml = { module = "org.codehaus.groovy:groovy-yaml", version.ref = "groovy" }

junit4 = { module = "junit:junit", version.ref = "junit4" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit5" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit5" }
junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platform" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package datadog.telemetry.dependency

import org.apache.tools.ant.taskdefs.Classloader
import spock.lang.TempDir

import java.nio.charset.Charset
Expand Down Expand Up @@ -136,8 +135,8 @@ class DependencyResolverSpecification extends DepSpecification {

void 'spring boot dependency'() throws IOException {
when:
String zipPath = Classloader.classLoader.getResource('datadog/telemetry/dependencies/spring-boot-app.jar').path
URI uri = new URI("jar:file:$zipPath!/BOOT-INF/lib/opentracing-util-0.33.0.jar!/")
URI zipPath = zipPath('datadog/telemetry/dependencies/spring-boot-app.jar')
URI uri = new URI("jar:$zipPath!/BOOT-INF/lib/opentracing-util-0.33.0.jar!/")

Dependency dep = DependencyResolver.resolve(uri).get(0)

Expand All @@ -151,8 +150,8 @@ class DependencyResolverSpecification extends DepSpecification {

void 'spring boot dependency without trailing slash'() throws IOException {
when:
String zipPath = Classloader.classLoader.getResource('datadog/telemetry/dependencies/spring-boot-app.jar').path
URI uri = new URI("jar:file:$zipPath!/BOOT-INF/lib/opentracing-util-0.33.0.jar!")
URI zipPath = zipPath('datadog/telemetry/dependencies/spring-boot-app.jar')
URI uri = new URI("jar:$zipPath!/BOOT-INF/lib/opentracing-util-0.33.0.jar!")

Dependency dep = DependencyResolver.resolve(uri).get(0)

Expand All @@ -166,8 +165,8 @@ class DependencyResolverSpecification extends DepSpecification {

void 'spring boot dependency new style'() throws IOException {
when:
String zipPath = Classloader.classLoader.getResource('datadog/telemetry/dependencies/spring-boot-app.jar').path
URI uri = new URI("jar:nested:$zipPath/!BOOT-INF/lib/opentracing-util-0.33.0.jar!/")
String zipPath = zipPath('datadog/telemetry/dependencies/spring-boot-app.jar').toString().replace("file:", "nested:")
URI uri = new URI("jar:$zipPath/!BOOT-INF/lib/opentracing-util-0.33.0.jar!/")

Dependency dep = DependencyResolver.resolve(uri).get(0)

Expand Down Expand Up @@ -235,7 +234,7 @@ class DependencyResolverSpecification extends DepSpecification {

void 'fat jar with multiple pom.properties'() throws IOException {
when:
URI uri = Classloader.classLoader.getResource('datadog/telemetry/dependencies/budgetapp.jar').toURI()
URI uri = zipPath('datadog/telemetry/dependencies/budgetapp.jar')

List<Dependency> deps = DependencyResolver.resolve(uri)

Expand All @@ -246,7 +245,7 @@ class DependencyResolverSpecification extends DepSpecification {

void 'fat jar with two pom.properties'() throws IOException {
when:
URI uri = Classloader.classLoader.getResource('datadog/telemetry/dependencies/budgetappreduced.jar').toURI()
URI uri = zipPath('datadog/telemetry/dependencies/budgetappreduced.jar')

List<Dependency> deps = DependencyResolver.resolve(uri)
Dependency dep1 = deps.get(0)
Expand All @@ -260,7 +259,7 @@ class DependencyResolverSpecification extends DepSpecification {

void 'fat jar with two pom.properties one of them bad'() throws IOException {
when:
URI uri = Classloader.classLoader.getResource('datadog/telemetry/dependencies/budgetappreducedbadproperties.jar').toURI()
URI uri = zipPath('datadog/telemetry/dependencies/budgetappreducedbadproperties.jar')

List<Dependency> deps = DependencyResolver.resolve(uri)
Dependency dep1 = deps.get(0)
Expand Down Expand Up @@ -352,4 +351,14 @@ class DependencyResolverSpecification extends DepSpecification {
then:
deps.size() == 1
}

private static URI zipPath(String outerJar) {
URL outerJarUrl = Thread.currentThread()
.contextClassLoader
.getResource(outerJar)

assert outerJarUrl != null : "Resource not found: ${outerJar}"

outerJarUrl.toURI()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MultipartRequestParser {
String getCharacterEncoding() {
ParameterParser parser = new ParameterParser()
parser.setLowerCaseNames(true)
String charset = parser.parse(contentType, ';' as char).get("charset")
String charset = parser.parse(contentType, (char)';').get("charset")
return charset != null ? charset : "UTF-8"
}

Expand Down