diff --git a/.github/actions/setup-environment-inst-verifier/action.yml b/.github/actions/setup-environment-inst-verifier/action.yml index 3ec3aadd7..cef000f44 100644 --- a/.github/actions/setup-environment-inst-verifier/action.yml +++ b/.github/actions/setup-environment-inst-verifier/action.yml @@ -17,8 +17,8 @@ runs: with: distribution: 'temurin' java-version: | + 23 21 - 20 17 11 8 @@ -30,8 +30,8 @@ runs: sed -i -e "s|jdk8=8|jdk8=${JAVA_HOME_8_X64}| s|jdk11=11|jdk11=${JAVA_HOME_11_X64}| s|jdk17=17|jdk17=${JAVA_HOME_17_X64}| - s|jdk20=20|jdk20=${JAVA_HOME_20_X64}| - s|jdk21=21|jdk20=${JAVA_HOME_21_X64}|" gradle.properties.gha + s|jdk21=21|jdk21=${JAVA_HOME_21_X64}| + s|jdk23=23|jdk23=${JAVA_HOME_23_X64}|" gradle.properties.gha cat gradle.properties.gha >> gradle.properties - name: Setup Gradle diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml index c9971074c..e6403a643 100644 --- a/.github/actions/setup-environment/action.yml +++ b/.github/actions/setup-environment/action.yml @@ -32,12 +32,12 @@ runs: steps: - name: Set up Javas - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: | + 23 21 - 20 17 11 8 @@ -49,8 +49,8 @@ runs: sed -i -e "s|jdk8=8|jdk8=${JAVA_HOME_8_X64}| s|jdk11=11|jdk11=${JAVA_HOME_11_X64}| s|jdk17=17|jdk17=${JAVA_HOME_17_X64}| - s|jdk20=20|jdk20=${JAVA_HOME_20_X64}| - s|jdk21=21|jdk21=${JAVA_HOME_21_X64}|" gradle.properties.gha + s|jdk21=21|jdk21=${JAVA_HOME_21_X64}| + s|jdk23=23|jdk23=${JAVA_HOME_23_X64}|" gradle.properties.gha cat gradle.properties.gha >> gradle.properties - name: Setup Gradle @@ -58,7 +58,7 @@ runs: - name: Setup Gradle options shell: bash - run: echo "GRADLE_OPTIONS=-Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_19_X64,JAVA_HOME_20_X64 -Prelease=${{ inputs.is-release }} -Prelease-suffix=${{ inputs.version-suffix }} " >> $GITHUB_ENV + run: echo "GRADLE_OPTIONS=-Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_19_X64,JAVA_HOME_21_X64,JAVA_HOME_23_X64 -Prelease=${{ inputs.is-release }} -Prelease-suffix=${{ inputs.version-suffix }} " >> $GITHUB_ENV # Restore the maven cache - name: Cache local Maven repository diff --git a/.github/actions/unit-test/action.yml b/.github/actions/unit-test/action.yml index 06ab3371d..5dc15fe72 100644 --- a/.github/actions/unit-test/action.yml +++ b/.github/actions/unit-test/action.yml @@ -5,18 +5,32 @@ inputs: description: 'The JVM Version to use' required: true default: '8' + csec-run-scala-unittest: + description: 'Whether to run CSEC scala instrumentation unit tests' + required: true + default: 'false' runs: using: composite steps: + # Run Scala unit tests if java version is 8 and csec-run-scala-unittest is enabled. + - name: Run scala instrumentation unit tests + id: run_scala_unit_tests + shell: bash + continue-on-error: true + if: (inputs.csec-run-scala-unittest == 'true' && inputs.java-version == '8') + run: | + ./gradlew $GRADLE_OPTIONS test -PincludeScala --continue + - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 1 id: run_tests_1 shell: bash continue-on-error: true + if: ( steps.run_scala_unit_tests.outcome == 'skipped' || steps.run_scala_unit_tests.outcome == 'failure' ) run: | - echo "Running attempt 1" - ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue + echo "Running attempt 1 with ${{ inputs.java-version }}" + ./gradlew ${GRADLE_OPTIONS} test -Ptest${{ inputs.java-version }} --continue - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 2 id: run_tests_2 @@ -24,8 +38,8 @@ runs: continue-on-error: true if: steps.run_tests_1.outcome == 'failure' run: | - echo "Running attempt 2" - ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue + echo "Running attempt 2 with ${{ inputs.java-version }}" + ./gradlew ${GRADLE_OPTIONS} test -Ptest${{ inputs.java-version }} --continue - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 3 id: run_tests_3 @@ -33,13 +47,13 @@ runs: continue-on-error: true if: steps.run_tests_2.outcome == 'failure' run: | - echo "Running attempt 3" - ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue + echo "Running attempt 3 with ${{ inputs.java-version }}" + ./gradlew ${GRADLE_OPTIONS} test -Ptest${{ inputs.java-version }} --continue - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 4 id: run_tests_4 shell: bash if: steps.run_tests_3.outcome == 'failure' run: | - echo "Running attempt 4" + echo "Running attempt 4 with ${{ inputs.java-version }}" ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue \ No newline at end of file diff --git a/.github/workflows/X-Reusable-Build-Security-Agent.yml b/.github/workflows/GHA-Unit-Tests.yml similarity index 70% rename from .github/workflows/X-Reusable-Build-Security-Agent.yml rename to .github/workflows/GHA-Unit-Tests.yml index e158ed0d1..2d3b1820b 100644 --- a/.github/workflows/X-Reusable-Build-Security-Agent.yml +++ b/.github/workflows/GHA-Unit-Tests.yml @@ -1,4 +1,7 @@ -name: X - Reusable Build Security Agent +# Workflow: Run Unit tests +# +# Trigger: This workflow runs on every merge to the main branch and on pull request. +name: Unit Tests on: workflow_call: inputs: @@ -26,6 +29,16 @@ on: description: 'version suffix to be added, if any' default: '' type: string + csec-run-scala-unittest: + description: 'Whether to run CSEC scala instrumentation unit tests' + required: false + default: false + type: boolean + unit-test-java-version: + description: 'Run Unit test on java version, default java versions are [ 8 ] ' + required: false + default: '[ 8 ]' + type: string workflow_dispatch: inputs: @@ -42,8 +55,8 @@ on: run-unit-test: description: 'Run instrumentation unit tests ?' required: true - type: string - default: 'true' + type: boolean + default: true is-release: description: 'Is this a release run' required: true @@ -53,6 +66,16 @@ on: description: 'version suffix to be added, if any' default: '' type: string + csec-run-scala-unittest: + description: 'Run scala instrumentation unit tests ?' + required: true + type: boolean + default: true + unit-test-java-version: + description: 'Run Unit test on java version, default java versions are [ 8, 11, 17, 21 ] ' + required: true + default: '[ 8, 11, 17, 21 ]' + type: string jobs: # this job reads the directories in csec-java-agent/instrumentation-security and creates a JSON with the list of the modules @@ -61,8 +84,7 @@ jobs: runs-on: ubuntu-24.04 strategy: matrix: - java-version: [ 8 ] -# java-version: [ 8, 11, 17 ] + java-version: ${{ fromJson(inputs.unit-test-java-version) }} steps: - name: Checkout CSEC Repo @@ -85,5 +107,7 @@ jobs: - name: Run CSEC unit tests if: ${{ inputs.run-unit-test == 'true' }} uses: ./.github/actions/unit-test + continue-on-error: true with: + csec-run-scala-unittest: ${{ inputs.csec-run-scala-unittest }} java-version: ${{ matrix.java-version }} \ No newline at end of file diff --git a/.github/workflows/TestSuite-PR.yml b/.github/workflows/TestSuite-PR.yml new file mode 100644 index 000000000..130683934 --- /dev/null +++ b/.github/workflows/TestSuite-PR.yml @@ -0,0 +1,39 @@ +# Workflow: Run Unit tests +# +# Trigger: This workflow runs on every merge to the main branch and on pull request. +name: Unit Tests +on: + + pull_request: + branches: [ main ] + +jobs: + # this job reads the directories in csec-java-agent/instrumentation-security and creates a JSON with the list of the modules + # this list is paginated and will be used in the verify-module job. + build-agent: + runs-on: ubuntu-24.04 + strategy: + matrix: + java-version: [ 8, 11, 17, 21 ] + + steps: + - name: Checkout CSEC Repo + uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + + - name: Setup environment + uses: ./.github/actions/setup-environment + with: + apm-aws-access-key-id: ${{ secrets.APM_AWS_ACCESS_KEY_ID }} + apm-aws-secret-access-key: ${{ secrets.APM_AWS_SECRET_ACCESS_KEY }} + apm-aws-region: us-east-2 + + - name: Publish CSEC to local + uses: ./.github/actions/publish-csec-local + + - name: Run CSEC unit tests + uses: ./.github/actions/unit-test + with: + csec-run-scala-unittest: true + java-version: ${{ matrix.java-version }} \ No newline at end of file diff --git a/.github/workflows/build-integrated-jar.yml b/.github/workflows/build-integrated-jar.yml index 53e726a05..7e83c5763 100644 --- a/.github/workflows/build-integrated-jar.yml +++ b/.github/workflows/build-integrated-jar.yml @@ -14,14 +14,22 @@ on: description: 'Whether to run CSEC instrumentation unit tests' required: true default: true + type: boolean + csec-run-scala-unittest: + description: 'Whether to run CSEC scala instrumentation unit tests ?' + required: true + type: boolean + default: false csec-run-instrumentation-verify: description: 'Whether to run CSEC instrumentation verifier' required: true default: true + type: boolean slack-notify: description: 'Whether to notify build status on slack' required: true default: true + type: boolean description: description: "A description for the custom jar that will be generated. It will appear in the summary." required: true @@ -34,12 +42,13 @@ permissions: jobs: build-csec-agent: name: Build CSEC agent artifacts - uses: ./.github/workflows/X-Reusable-Build-Security-Agent.yml + uses: ./.github/workflows/GHA-Unit-Tests.yml with: apm-repo: ${{ inputs.apm-repo }} apm-source-ref: ${{ inputs.apm-source-ref }} run-unit-test: ${{ inputs.csec-run-unittest }} is-release: false + csec-run-scala-unittest: ${{ inputs.csec-run-scala-unittest }} secrets: inherit verify-instrumentation: diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml index 6fea77078..43035e171 100644 --- a/.github/workflows/dependency-submission.yml +++ b/.github/workflows/dependency-submission.yml @@ -1,8 +1,16 @@ +# Workflow: Dependency Graph Submission and Vulnerability Reporting +# +# Trigger: This workflow runs on every merge to the main branch and on pull request. +# +# Purpose: It generates and submits a dependency graph to the GitHub Dependency Submission API. The graph is used to +# trigger Dependabot Alerts for vulnerable dependencies, and to populate the Dependency Graph insights view in GitHub. + name: Dependency Submission on: push: branches: ['main'] + pull_request: permissions: contents: write @@ -12,9 +20,9 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout sources - uses: actions/checkout@v4 + uses: actions/checkout@v3 - name: Setup Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: 8 diff --git a/.github/workflows/repolinter.yml b/.github/workflows/repolinter.yml index 83e94db2e..bc1926fe5 100644 --- a/.github/workflows/repolinter.yml +++ b/.github/workflows/repolinter.yml @@ -22,7 +22,7 @@ jobs: return data.data && data.data.default_branch === context.ref.split('/').slice(-1)[0] - name: Checkout Self if: ${{ steps.default-branch.outputs.result == 'true' }} - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Run Repolinter if: ${{ steps.default-branch.outputs.result == 'true' }} uses: newrelic/repolinter-action@v1 diff --git a/gradle.properties.gha b/gradle.properties.gha index 4f03c5151..1eb380879 100644 --- a/gradle.properties.gha +++ b/gradle.properties.gha @@ -2,5 +2,5 @@ jdk8=8 jdk11=11 jdk17=17 jdk19=19 -jdk20=20 - +jdk21=21 +jdk23=23 \ No newline at end of file diff --git a/gradle/script/java.gradle b/gradle/script/java.gradle index f7c6663cf..2ef9f251a 100644 --- a/gradle/script/java.gradle +++ b/gradle/script/java.gradle @@ -81,6 +81,24 @@ compileJava.options.bootstrapClasspath = files("${jdkPath}/jre/lib/rt.jar", "${j // their own build.gradle to force the use of a specific version of Java (e.g. instrumentation/async-http-client-2.0.0). // This could lead to an "Unrecognized option" with the failure "Could not create the Java Virtual Machine". test { + + // To keep test times reasonable we only test against supported LTS Java releases as well as the latest non-LTS release of Java. + // This method determines if we should run tests with the Java version configured by the -PtestN gradle property. + ext.configuredWithValidTestJDK = { + if (project.hasProperty("test9") || project.hasProperty("test10") || project.hasProperty("test12") || project.hasProperty("test13") || + project.hasProperty("test14") || project.hasProperty("test15") || project.hasProperty("test16") || project.hasProperty("test18") || + project.hasProperty("test19") || project.hasProperty("test20") || project.hasProperty("test22")) { + logger.lifecycle("The csec-java-agent project does not support testing with the Java version configured by the -PtestN gradle property.") + return false + } + // The -PtestN gradle property was configured with a valid test JDK or not provided at all. + return true + } + + onlyIf { + configuredWithValidTestJDK() + } + ext.configureTest = { String jdkName, Closure configuration -> // Add an input property so that we differentiate between JDKs with the same version inputs.property("test.jdk", jdkName) @@ -89,6 +107,38 @@ test { executable = project.property(jdkName) + '/bin/java' configuration.call() } + if (project.hasProperty("test23")) { + configureTest("jdk23") { + jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED', + '--add-opens=java.base/java.util=ALL-UNNAMED', + '--add-opens=java.base/java.net=ALL-UNNAMED', + '--add-opens=java.base/java.io=ALL-UNNAMED', + '--add-opens=java.base/sun.net.spi=ALL-UNNAMED', + '--add-exports=java.base/sun.net.spi=ALL-UNNAMED', + '--add-exports=java.xml/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED' + useJUnit { + excludeCategories 'com.newrelic.security.test.marker.Java23IncompatibleTest' + } + } + // mockito uses a version of bytebuddy that has experimental support for Java 21 + systemProperty("net.bytebuddy.experimental", "true") + } + if (project.hasProperty("test21")) { + configureTest("jdk21") { + jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED', + '--add-opens=java.base/java.util=ALL-UNNAMED', + '--add-opens=java.base/java.net=ALL-UNNAMED', + '--add-opens=java.base/java.io=ALL-UNNAMED', + '--add-opens=java.base/sun.net.spi=ALL-UNNAMED', + '--add-exports=java.base/sun.net.spi=ALL-UNNAMED', + '--add-exports=java.xml/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED' + useJUnit { + excludeCategories 'com.newrelic.security.test.marker.Java21IncompatibleTest' + } + } + // mockito uses a version of bytebuddy that has experimental support for Java 21 + systemProperty("net.bytebuddy.experimental", "true") + } if (project.hasProperty("test19")) { configureTest("jdk19") { jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED', diff --git a/instrumentation-security/apache-tomcat-7/build.gradle b/instrumentation-security/apache-tomcat-7/build.gradle index 8614e74a0..49164ebfa 100644 --- a/instrumentation-security/apache-tomcat-7/build.gradle +++ b/instrumentation-security/apache-tomcat-7/build.gradle @@ -16,6 +16,13 @@ verifyInstrumentation { excludeRegex '.*-(b|gfa|beta|RC)[0-9]*' } +test { + onlyIf { + // test is incompatible with version of java greater than 1.8 + project.hasProperty("test8") + } +} + site { title 'Tomcat' type 'Appserver' diff --git a/instrumentation-security/cassandra-datastax-3/build.gradle b/instrumentation-security/cassandra-datastax-3/build.gradle index c520cbf9a..79aef8f5e 100644 --- a/instrumentation-security/cassandra-datastax-3/build.gradle +++ b/instrumentation-security/cassandra-datastax-3/build.gradle @@ -18,6 +18,13 @@ verifyInstrumentation { excludeRegex('com.datastax.cassandra:cassandra-driver-core:2.*') } +test { + onlyIf { + // test is incompatible with version of java greater than 1.8 + !project.hasProperty("test21") + } +} + site { title 'Cassandra' type 'Datastore' diff --git a/instrumentation-security/cassandra-datastax-4/build.gradle b/instrumentation-security/cassandra-datastax-4/build.gradle index 21ce0743e..e13f9571d 100644 --- a/instrumentation-security/cassandra-datastax-4/build.gradle +++ b/instrumentation-security/cassandra-datastax-4/build.gradle @@ -22,6 +22,13 @@ site { type 'Datastore' } +test { + onlyIf { + // test is incompatible with version of java greater than 1.8 + !project.hasProperty("test21") + } +} + test { jvmArgs(["-Djava.library.path=src/test/resources/libs/"]) } \ No newline at end of file diff --git a/instrumentation-security/file-low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/FileTest.java b/instrumentation-security/file-low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/FileTest.java index 2a6de2409..022a687e6 100644 --- a/instrumentation-security/file-low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/FileTest.java +++ b/instrumentation-security/file-low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/FileTest.java @@ -7,10 +7,12 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.FileOperation; +import com.newrelic.security.test.marker.*; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.io.File; @@ -20,6 +22,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.random", "java.io"}) +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class FileTest { private static final String FILE_NAME = "/tmp/test-" + UUID.randomUUID(); diff --git a/instrumentation-security/file-operation/src/test/java/com/nr/agent/security/instrumentation/javaio/FileTest.java b/instrumentation-security/file-operation/src/test/java/com/nr/agent/security/instrumentation/javaio/FileTest.java index 9c85a5b22..8124fcc11 100644 --- a/instrumentation-security/file-operation/src/test/java/com/nr/agent/security/instrumentation/javaio/FileTest.java +++ b/instrumentation-security/file-operation/src/test/java/com/nr/agent/security/instrumentation/javaio/FileTest.java @@ -7,11 +7,13 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.FileOperation; +import com.newrelic.security.test.marker.Java17IncompatibleTest; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.io.File; @@ -23,6 +25,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"java.io", "java.nio"}) +@Category({ Java17IncompatibleTest.class }) public class FileTest { private static final String FILE_NAME = "/tmp/test-" + UUID.randomUUID(); diff --git a/instrumentation-security/java-io-inputstream-jdk8/src/test/java/com/nr/agent/security/instrumentation/javaio/InputStreamJdk8Test.java b/instrumentation-security/java-io-inputstream-jdk8/src/test/java/com/nr/agent/security/instrumentation/javaio/InputStreamJdk8Test.java index eaf99a847..99c985c4f 100644 --- a/instrumentation-security/java-io-inputstream-jdk8/src/test/java/com/nr/agent/security/instrumentation/javaio/InputStreamJdk8Test.java +++ b/instrumentation-security/java-io-inputstream-jdk8/src/test/java/com/nr/agent/security/instrumentation/javaio/InputStreamJdk8Test.java @@ -6,6 +6,8 @@ import com.newrelic.agent.security.introspec.SecurityIntrospector; import com.newrelic.api.agent.security.schema.SecurityMetaData; import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -33,7 +35,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"java.io","com.newrelic.agent.security.instrumentation.javaio"}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({Java17IncompatibleTest.class}) +@Category({Java17IncompatibleTest.class, Java23IncompatibleTest.class, Java21IncompatibleTest.class}) public class InputStreamJdk8Test { private static String FILE; private static String FILE_TEMP; diff --git a/instrumentation-security/java-lang/src/test/java/com/nr/agent/security/instrumentation/java/lang/ProcessImplTest.java b/instrumentation-security/java-lang/src/test/java/com/nr/agent/security/instrumentation/java/lang/ProcessImplTest.java index 28a81f395..224995dad 100644 --- a/instrumentation-security/java-lang/src/test/java/com/nr/agent/security/instrumentation/java/lang/ProcessImplTest.java +++ b/instrumentation-security/java-lang/src/test/java/com/nr/agent/security/instrumentation/java/lang/ProcessImplTest.java @@ -7,8 +7,10 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.ForkExecOperation; +import com.newrelic.security.test.marker.*; import org.junit.Assert; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.io.BufferedReader; @@ -18,6 +20,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "java.lang.ProcessImpl_Instrumentation") +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class ProcessImplTest { private String cmd = "/bin/sh -c ls"; private String cmd2 = "ls"; diff --git a/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextRmiTest.java b/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextRmiTest.java index a2d2a52ed..beadc73d6 100644 --- a/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextRmiTest.java +++ b/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextRmiTest.java @@ -7,9 +7,12 @@ import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.SSRFOperation; import javax.naming.JNDIUtils; + +import com.newrelic.security.test.marker.*; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; @@ -30,6 +33,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "javax.naming", "com.newrelic.agent.security.instrumentation.javax.jndi" } ) @FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class ContextRmiTest { private final int PORT = getRandomPort(); diff --git a/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextTest.java b/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextTest.java index e21071234..a695536b7 100644 --- a/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextTest.java +++ b/instrumentation-security/javax-jndi/src/test/java/com/nr/agent/security/instrumentation/javax/jndi/ContextTest.java @@ -7,12 +7,19 @@ import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.SSRFOperation; import javax.naming.JNDIUtils; + +import com.newrelic.security.test.marker.Java11IncompatibleTest; +import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; +import com.newrelic.security.test.marker.Java9IncompatibleTest; import com.unboundid.ldap.sdk.LDAPException; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.zapodot.junit.ldap.EmbeddedLdapRule; @@ -30,6 +37,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "javax.naming", "com.newrelic.agent.security.instrumentation.javax.jndi" } ) @FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class ContextTest { public static final String DOMAIN_DSN = "dc=example,dc=com"; @ClassRule diff --git a/instrumentation-security/javax-xpath/src/test/java/com/nr/agent/security/instrumentation/xpath/javax/internal/XPathInternalTest.java b/instrumentation-security/javax-xpath/src/test/java/com/nr/agent/security/instrumentation/xpath/javax/internal/XPathInternalTest.java index b6cb2dd49..e9b3367f7 100644 --- a/instrumentation-security/javax-xpath/src/test/java/com/nr/agent/security/instrumentation/xpath/javax/internal/XPathInternalTest.java +++ b/instrumentation-security/javax-xpath/src/test/java/com/nr/agent/security/instrumentation/xpath/javax/internal/XPathInternalTest.java @@ -7,6 +7,8 @@ import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.XPathOperation; import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; import com.sun.org.apache.xml.internal.utils.DefaultErrorHandler; import com.sun.org.apache.xml.internal.utils.PrefixResolver; import com.sun.org.apache.xml.internal.utils.PrefixResolverDefault; @@ -34,7 +36,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @InstrumentationTestConfig(includePrefixes = { "javax.xml.xpath", "com.sun.org.apache.xpath.internal" }) -@Category({ Java17IncompatibleTest.class}) +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class XPathInternalTest { private final String XML_DOC = "src/test/resources/Customer.xml"; private final String EXPRESSION = "/Customers/Customer"; diff --git a/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/JavaxWsRsApiTest.java b/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/JavaxWsRsApiTest.java index d73b39901..ca1694ea2 100644 --- a/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/JavaxWsRsApiTest.java +++ b/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/JavaxWsRsApiTest.java @@ -4,13 +4,20 @@ import com.newrelic.agent.security.introspec.SecurityInstrumentationTestRunner; import com.newrelic.agent.security.introspec.SecurityIntrospector; import com.newrelic.api.agent.security.schema.AgentMetaData; +import com.newrelic.security.test.marker.Java11IncompatibleTest; +import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; +import com.newrelic.security.test.marker.Java9IncompatibleTest; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.App; import org.junit.Assert; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "com.newrelic.agent.security.instrumentation.javax.ws.rs.api") +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class JavaxWsRsApiTest { @Test public void testPut() { diff --git a/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java b/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java index a67197b37..d0b0e93b6 100644 --- a/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java +++ b/instrumentation-security/jax-rs-1.0/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java @@ -1,5 +1,10 @@ package com.nr.agent.security.instrumentation.javax.ws.rs.api.test; +import com.newrelic.security.test.marker.Java11IncompatibleTest; +import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; +import com.newrelic.security.test.marker.Java9IncompatibleTest; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.CustomerLocatorResource; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.IdSubResource; import com.newrelic.agent.security.introspec.InstrumentationTestConfig; @@ -13,6 +18,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import javax.ws.rs.client.Entity; @@ -21,6 +27,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "com.newrelic.agent.security.instrumentation.javax.ws.rs.api") +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class SubresourceTest extends JerseyTest { @BeforeClass public static void bringUp() { diff --git a/instrumentation-security/jdbc-mysql-6.0.2/build.gradle b/instrumentation-security/jdbc-mysql-6.0.2/build.gradle index b7300629e..775cb6647 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/build.gradle +++ b/instrumentation-security/jdbc-mysql-6.0.2/build.gradle @@ -16,6 +16,13 @@ verifyInstrumentation { excludeRegex 'mysql:mysql-connector-java:8.*' } +test { + onlyIf { + // test is incompatible with java version 8 above + project.hasProperty("test8") + } +} + site { title 'MySQL' type 'Datastore' diff --git a/instrumentation-security/jdbc-mysql-connection-6.0.2/build.gradle b/instrumentation-security/jdbc-mysql-connection-6.0.2/build.gradle index c5734ca81..79eba107a 100644 --- a/instrumentation-security/jdbc-mysql-connection-6.0.2/build.gradle +++ b/instrumentation-security/jdbc-mysql-connection-6.0.2/build.gradle @@ -18,6 +18,13 @@ verifyInstrumentation { exclude 'mysql:mysql-connector-java:8.0.9' } +test { + onlyIf { + // test is incompatible with java version 8 above + project.hasProperty("test8") + } +} + site { title 'MySQL' type 'Datastore' diff --git a/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/build.gradle b/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/build.gradle index 15ebe04fa..d6740997d 100644 --- a/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/build.gradle +++ b/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/build.gradle @@ -18,6 +18,13 @@ verifyInstrumentation { exclude 'mysql:mysql-connector-java:8.0.9' } +test { + onlyIf { + // test is incompatible with java version 8 above + project.hasProperty("test8") + } +} + site { title 'MySQL' type 'Datastore' diff --git a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/build.gradle b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/build.gradle index 240eb8cbb..aee0f7a6c 100644 --- a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/build.gradle +++ b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/build.gradle @@ -3,7 +3,7 @@ dependencies { implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") implementation("postgresql:postgresql:8.0-312.jdbc3") - testImplementation("ru.yandex.qatools.embed:postgresql-embedded:2.10") + testImplementation('org.testcontainers:postgresql:1.20.6') } jar { diff --git a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DataStoreTest.java b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DataStoreTest.java index 413309216..c630a8036 100644 --- a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DataStoreTest.java +++ b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DataStoreTest.java @@ -26,38 +26,40 @@ import org.postgresql.jdbc3.Jdbc3ConnectionPool; import org.postgresql.jdbc3.Jdbc3PoolingDataSource; import org.postgresql.jdbc3.Jdbc3SimpleDataSource; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; +import org.testcontainers.containers.PostgreSQLContainer; import java.io.IOException; import java.net.ServerSocket; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DataStoreTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final String HOST = "localhost"; - private static final List QUERIES = new ArrayList<>(); private static final int PORT = getRandomPort(); @BeforeClass - public static void setup() throws Exception { - QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); - QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'Max', 'Power')"); - QUERIES.add("SELECT * FROM USERS"); + public static void setup() { + + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); } @After diff --git a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DriverTest.java b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DriverTest.java index 52a165ea4..2e02fcb0a 100644 --- a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DriverTest.java +++ b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/DriverTest.java @@ -16,7 +16,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; +import org.testcontainers.containers.PostgreSQLContainer; import java.io.IOException; import java.net.ServerSocket; @@ -24,32 +24,34 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Properties; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DriverTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final String HOST = "localhost"; - private static final List QUERIES = new ArrayList<>(); private static final int PORT = getRandomPort(); @BeforeClass - public static void setup() throws Exception { - QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); - QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'Max', 'Power')"); - QUERIES.add("SELECT * FROM USERS"); + public static void setup() { + + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); } @After diff --git a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/PgStatementTest.java b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/PgStatementTest.java index 63c84079e..36e118737 100644 --- a/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/PgStatementTest.java +++ b/instrumentation-security/jdbc-postgresql-8.0-312.jdbc3/src/test/java/com/nr/agent/security/instrumentation/postgresql80312/PgStatementTest.java @@ -8,7 +8,6 @@ import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.SQLOperation; import com.newrelic.security.test.marker.Java12IncompatibleTest; -import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -17,7 +16,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; +import org.testcontainers.containers.PostgreSQLContainer; import java.io.IOException; import java.math.BigDecimal; @@ -31,33 +30,37 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; - -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class PgStatementTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; + public static Connection CONNECTION; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final String HOST = "localhost"; private static final List QUERIES = new ArrayList<>(); private static final int PORT = getRandomPort(); @BeforeClass public static void setup() throws Exception { - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); getConnection(); - QUERIES.add( - "CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255), dob date, dot time, dotz timestamptz, active boolean, arr bytea)"); + QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255), dob date, dot time, dotz timestamptz, active boolean, arr bytea)"); QUERIES.add("TRUNCATE TABLE USERS"); QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'john', 'doe')"); QUERIES.add("SELECT * FROM USERS"); diff --git a/instrumentation-security/jdbc-postgresql-9.4.1207/build.gradle b/instrumentation-security/jdbc-postgresql-9.4.1207/build.gradle index 772304e09..594ec6a90 100644 --- a/instrumentation-security/jdbc-postgresql-9.4.1207/build.gradle +++ b/instrumentation-security/jdbc-postgresql-9.4.1207/build.gradle @@ -3,7 +3,7 @@ dependencies { implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") implementation("org.postgresql:postgresql:9.4.1207") - testImplementation("ru.yandex.qatools.embed:postgresql-embedded:2.10") + testImplementation('org.testcontainers:postgresql:1.20.6') } jar { diff --git a/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DataStoreTest.java b/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DataStoreTest.java index f99de0c46..82e4e54c8 100644 --- a/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DataStoreTest.java +++ b/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DataStoreTest.java @@ -27,38 +27,37 @@ import org.postgresql.jdbc3.Jdbc3PoolingDataSource; import org.postgresql.jdbc3.Jdbc3SimpleDataSource; import org.postgresql.xa.PGXADataSource; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; +import org.testcontainers.containers.PostgreSQLContainer; import java.io.IOException; import java.net.ServerSocket; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; - -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DataStoreTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; - private static final String HOST = "localhost"; - private static final List QUERIES = new ArrayList<>(); + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final int PORT = getRandomPort(); @BeforeClass public static void setup() throws Exception { - QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); - QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'Max', 'Power')"); - QUERIES.add("SELECT * FROM USERS"); - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); } @After diff --git a/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DriverTest.java b/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DriverTest.java index 92a741464..5ae3dbf83 100644 --- a/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DriverTest.java +++ b/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/DriverTest.java @@ -16,7 +16,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; +import org.testcontainers.containers.PostgreSQLContainer; import java.io.IOException; import java.net.ServerSocket; @@ -24,32 +24,32 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Properties; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; - -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DriverTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final String HOST = "localhost"; - private static final List QUERIES = new ArrayList<>(); private static final int PORT = getRandomPort(); @BeforeClass - public static void setup() throws Exception { - QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); - QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'Max', 'Power')"); - QUERIES.add("SELECT * FROM USERS"); + public static void setup() { - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); } @After diff --git a/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/PgStatementTest.java b/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/PgStatementTest.java index 48b935998..6d4e4aa40 100644 --- a/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/PgStatementTest.java +++ b/instrumentation-security/jdbc-postgresql-9.4.1207/src/test/java/com/nr/agent/security/instrumentation/postgresql941207/PgStatementTest.java @@ -11,13 +11,12 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.ClassRule; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; +import org.testcontainers.containers.PostgreSQLContainer; import java.io.IOException; import java.math.BigDecimal; @@ -31,29 +30,34 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; - -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class PgStatementTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; + public static Connection CONNECTION; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final String HOST = "localhost"; private static final List QUERIES = new ArrayList<>(); private static final int PORT = getRandomPort(); @BeforeClass public static void setup() throws Exception { - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); getConnection(); QUERIES.add( @@ -76,8 +80,10 @@ public static void setup() throws Exception { @AfterClass public static void stop() throws SQLException { - if (postgres!=null) + if (postgres!=null) { + postgres.close(); postgres.stop(); + } if (CONNECTION != null) { CONNECTION.close(); } diff --git a/instrumentation-security/jdbc-postgresql-9.4.1208/build.gradle b/instrumentation-security/jdbc-postgresql-9.4.1208/build.gradle index 78ca1b7a8..6981059fa 100644 --- a/instrumentation-security/jdbc-postgresql-9.4.1208/build.gradle +++ b/instrumentation-security/jdbc-postgresql-9.4.1208/build.gradle @@ -3,8 +3,7 @@ dependencies { implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") implementation("org.postgresql:postgresql:9.4.1208") - testImplementation("ru.yandex.qatools.embed:postgresql-embedded:2.10") - + testImplementation('org.testcontainers:postgresql:1.20.6') } jar { diff --git a/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DataStoreTest.java b/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DataStoreTest.java index 336e52ad7..653b210b5 100644 --- a/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DataStoreTest.java +++ b/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DataStoreTest.java @@ -26,46 +26,39 @@ import org.postgresql.jdbc3.Jdbc3ConnectionPool; import org.postgresql.jdbc3.Jdbc3PoolingDataSource; import org.postgresql.jdbc3.Jdbc3SimpleDataSource; +import org.testcontainers.containers.PostgreSQLContainer; import org.postgresql.xa.PGXADataSource; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; import java.io.IOException; import java.net.ServerSocket; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DataStoreTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; - private static final String HOST = "localhost"; - private static final List QUERIES = new ArrayList<>(); + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final int PORT = getRandomPort(); @BeforeClass public static void setup() throws Exception { - QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); - QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'Max', 'Power')"); - QUERIES.add("SELECT * FROM USERS"); - - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); - } - @After - public void teardown() throws SQLException { - if (connection!=null) { - connection.close(); - } + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); } @AfterClass diff --git a/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DriverTest.java b/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DriverTest.java index 1dc172a07..72dc50018 100644 --- a/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DriverTest.java +++ b/instrumentation-security/jdbc-postgresql-9.4.1208/src/test/java/com/nr/agent/security/instrumentation/postgresql941208/DriverTest.java @@ -15,8 +15,8 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; +import org.testcontainers.containers.PostgreSQLContainer; import org.junit.runners.MethodSorters; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; import java.io.IOException; import java.net.ServerSocket; @@ -24,40 +24,31 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Properties; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.V11_1; - -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DriverTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); + + public static PostgreSQLContainer postgres; public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; - private static final String HOST = "localhost"; - private static final List QUERIES = new ArrayList<>(); + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final int PORT = getRandomPort(); @BeforeClass public static void setup() throws Exception { - QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); - QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'Max', 'Power')"); - QUERIES.add("SELECT * FROM USERS"); - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); - } - - @After - public void teardown() throws SQLException { - if (connection!=null) { - connection.close(); - } + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); } @AfterClass @@ -89,7 +80,7 @@ private void getConnection() throws SQLException { Connection c = null; try { Class.forName("org.postgresql.Driver"); - c = DriverManager.getConnection(String.format("jdbc:postgresql://%s:%s/%s", HOST, PORT, DB_NAME), DB_USER, DB_PASSWORD); + c = DriverManager.getConnection(String.format("jdbc:postgresql://localhost:%s/%s", PORT, DB_NAME), DB_USER, DB_PASSWORD); } catch (Exception e) { System.out.println("Error in DB connection: " + e); } finally { @@ -107,7 +98,7 @@ private void getConnection1() throws SQLException { Properties info = new Properties(); info.put("user", DB_USER); info.put("password", DB_PASSWORD); - c = DriverManager.getConnection(String.format("jdbc:postgresql://%s:%s/%s", HOST, PORT, DB_NAME), info); + c = DriverManager.getConnection(String.format("jdbc:postgresql://localhost:%s/%s", PORT, DB_NAME), info); } catch (Exception e) { System.out.println("Error in DB connection: " + e); } finally { diff --git a/instrumentation-security/jersey-2.16/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java b/instrumentation-security/jersey-2.16/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java index 6e0a51a57..8e7f9f035 100644 --- a/instrumentation-security/jersey-2.16/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java +++ b/instrumentation-security/jersey-2.16/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java @@ -20,6 +20,8 @@ import com.newrelic.api.agent.security.schema.operation.RXSSOperation; import com.newrelic.security.test.marker.Java11IncompatibleTest; import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; import com.newrelic.security.test.marker.Java9IncompatibleTest; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.util.Header; @@ -58,7 +60,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.jersey2"}) -@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class }) +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class JerseyTests { private static HttpServer server; @@ -119,7 +121,7 @@ public void asyncHandleHeaderTest() { SecurityIntrospector introspector = SecurityInstrumentationTestRunner.getIntrospector(); assertTrue(introspector.getSecurityMetaData().getMetaData().isUserLevelServiceMethodEncountered()); - assertOperation(introspector.getOperations(), true, introspector.getRequestInStreamHash(), responseBody); + assertOperation(introspector.getOperations(), false, introspector.getRequestInStreamHash(), responseBody); } private String[] fireRequest(final String path) { diff --git a/instrumentation-security/jersey-2/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java b/instrumentation-security/jersey-2/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java index 792b93ced..e6251b01e 100644 --- a/instrumentation-security/jersey-2/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java +++ b/instrumentation-security/jersey-2/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java @@ -20,6 +20,8 @@ import com.newrelic.api.agent.security.schema.operation.RXSSOperation; import com.newrelic.security.test.marker.Java11IncompatibleTest; import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; import com.newrelic.security.test.marker.Java9IncompatibleTest; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.util.Header; @@ -57,7 +59,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.jersey2"}) -@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class }) +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class JerseyTests { private static HttpServer server; @@ -117,7 +119,7 @@ public void asyncHandleHeaderTest() { SecurityIntrospector introspector = SecurityInstrumentationTestRunner.getIntrospector(); assertTrue(introspector.getSecurityMetaData().getMetaData().isUserLevelServiceMethodEncountered()); - assertOperation(introspector.getOperations(), true, introspector.getRequestInStreamHash(), responseBody); + assertOperation(introspector.getOperations(), false, introspector.getRequestInStreamHash(), responseBody); } private String[] fireRequest(final String path) { diff --git a/instrumentation-security/jersey-3/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java b/instrumentation-security/jersey-3/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java index 5f7bf1163..daafe45b9 100644 --- a/instrumentation-security/jersey-3/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java +++ b/instrumentation-security/jersey-3/src/test/java/com/nr/agent/security/instrumentation/jersey2/JerseyTests.java @@ -16,9 +16,11 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.HttpRequest; import com.newrelic.api.agent.security.schema.HttpResponse; +import com.newrelic.api.agent.security.schema.StringUtils; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.RXSSOperation; import com.newrelic.security.test.marker.Java11IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; import com.newrelic.security.test.marker.Java8IncompatibleTest; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.util.Header; @@ -56,7 +58,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.jersey2"}) -@Category({Java8IncompatibleTest.class, Java11IncompatibleTest.class}) +@Category({Java8IncompatibleTest.class}) public class JerseyTests { private static HttpServer server; @@ -116,7 +118,7 @@ public void asyncHandleHeaderTest() { SecurityIntrospector introspector = SecurityInstrumentationTestRunner.getIntrospector(); assertTrue(introspector.getSecurityMetaData().getMetaData().isUserLevelServiceMethodEncountered()); - assertOperation(introspector.getOperations(), true, introspector.getRequestInStreamHash(), responseBody); + assertOperation(introspector.getOperations(), false, introspector.getRequestInStreamHash(), responseBody); } private String[] fireRequest(final String path) { @@ -200,7 +202,7 @@ private void assertOperation(List operations, boolean hasHead // assert the security response HttpResponse response = operation.getResponse(); assertFalse(response.isEmpty()); - assertEquals(MediaType.TEXT_HTML, response.getResponseContentType()); + assertFalse(StringUtils.isEmpty(response.getResponseContentType())); assertEquals(2, responseBody.length); assertEquals(responseBody[0], response.getBody().toString()); assertFalse(hashCode.isEmpty()); diff --git a/instrumentation-security/jersey/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java b/instrumentation-security/jersey/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java index d7a42e4c1..e1558bf01 100644 --- a/instrumentation-security/jersey/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java +++ b/instrumentation-security/jersey/src/test/java/com/nr/agent/security/instrumentation/javax/ws/rs/api/test/SubresourceTest.java @@ -4,6 +4,7 @@ import com.newrelic.agent.security.introspec.SecurityInstrumentationTestRunner; import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper; import com.newrelic.api.agent.security.schema.ApplicationURLMapping; +import com.newrelic.security.test.marker.*; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.CustomerLocatorResource; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.IdSubResource; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.OrdersSubResource; @@ -15,6 +16,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import javax.ws.rs.core.Application; @@ -22,6 +24,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "com.newrelic.agent.security", "org.glassfish.jersey" }) +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class SubresourceTest extends JerseyTest { @BeforeClass public static void bringUp() { diff --git a/instrumentation-security/jetty-12/build.gradle b/instrumentation-security/jetty-12/build.gradle index d5a7f7742..beaad9f9e 100644 --- a/instrumentation-security/jetty-12/build.gradle +++ b/instrumentation-security/jetty-12/build.gradle @@ -23,9 +23,9 @@ java { } test { - // These instrumentation tests only run on Java 17+ regardless of the -PtestN gradle property that is set. + // These instrumentation tests only run on Java 17 regardless of the -PtestN gradle property that is set. onlyIf { - !project.hasProperty('test8') && !project.hasProperty('test11') + project.hasProperty('test17') } } diff --git a/instrumentation-security/low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/random/RandomTest.java b/instrumentation-security/low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/random/RandomTest.java index f2cca8cfe..30e62e9a2 100644 --- a/instrumentation-security/low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/random/RandomTest.java +++ b/instrumentation-security/low-priority-instrumentation/src/test/java/com/nr/agent/security/instrumentation/random/RandomTest.java @@ -8,6 +8,8 @@ import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.RandomOperation; import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; import org.bouncycastle.crypto.prng.FixedSecureRandom; import org.junit.Assert; import org.junit.BeforeClass; @@ -22,7 +24,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "com.newrelic.agent.security.instrumentation.random") -@Category({ Java17IncompatibleTest.class}) +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class}) public class RandomTest { private static final String SECURE_RANDOM = "SECURERANDOM"; private static final String WEAK_RANDOM = "WEAKRANDOM"; diff --git a/instrumentation-security/nashorn-jsinjection/src/test/java/com/nr/agent/security/instrumentation/nashorn/NashornScriptEngineTest.java b/instrumentation-security/nashorn-jsinjection/src/test/java/com/nr/agent/security/instrumentation/nashorn/NashornScriptEngineTest.java index d37b1d0e3..35177c52c 100644 --- a/instrumentation-security/nashorn-jsinjection/src/test/java/com/nr/agent/security/instrumentation/nashorn/NashornScriptEngineTest.java +++ b/instrumentation-security/nashorn-jsinjection/src/test/java/com/nr/agent/security/instrumentation/nashorn/NashornScriptEngineTest.java @@ -12,6 +12,8 @@ import com.newrelic.security.test.marker.Java17IncompatibleTest; import com.newrelic.security.test.marker.Java18IncompatibleTest; import com.newrelic.security.test.marker.Java19IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; import jdk.nashorn.api.scripting.NashornScriptEngine; import org.junit.Assert; import org.junit.FixMethodOrder; @@ -30,7 +32,7 @@ import java.net.URISyntaxException; import java.util.List; -@Category({ Java15IncompatibleTest.class, Java16IncompatibleTest.class, Java17IncompatibleTest.class, Java18IncompatibleTest.class, Java19IncompatibleTest.class }) +@Category({ Java15IncompatibleTest.class, Java16IncompatibleTest.class, Java17IncompatibleTest.class, Java18IncompatibleTest.class, Java19IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "jdk.nashorn") @FixMethodOrder(MethodSorters.NAME_ASCENDING) diff --git a/instrumentation-security/netty-reactor-0.7.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java b/instrumentation-security/netty-reactor-0.7.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java index eda51ef07..9416a7608 100644 --- a/instrumentation-security/netty-reactor-0.7.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java +++ b/instrumentation-security/netty-reactor-0.7.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java @@ -7,11 +7,13 @@ import com.newrelic.api.agent.security.schema.ApplicationURLMapping; import com.newrelic.api.agent.security.schema.Framework; import com.newrelic.api.agent.security.schema.SecurityMetaData; +import com.newrelic.security.test.marker.*; import io.netty.handler.codec.http.HttpMethod; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import reactor.core.publisher.Mono; import reactor.ipc.netty.http.server.HttpServer; @@ -27,6 +29,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "reactor.ipc.netty.http.server") +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class APIEndpointTest { private static BlockingNettyContext server; diff --git a/instrumentation-security/netty-reactor-0.8.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java b/instrumentation-security/netty-reactor-0.8.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java index 7f8ed55b0..e132ab584 100644 --- a/instrumentation-security/netty-reactor-0.8.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java +++ b/instrumentation-security/netty-reactor-0.8.0/src/test/java/com/nr/agent/security/instrumentation/netty_reactor/APIEndpointTest.java @@ -7,11 +7,13 @@ import com.newrelic.api.agent.security.schema.ApplicationURLMapping; import com.newrelic.api.agent.security.schema.Framework; import com.newrelic.api.agent.security.schema.SecurityMetaData; +import com.newrelic.security.test.marker.*; import io.netty.handler.codec.http.HttpMethod; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import reactor.core.publisher.Mono; import reactor.netty.DisposableServer; @@ -27,6 +29,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "reactor.netty.http.server") +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class APIEndpointTest { private static DisposableServer server; diff --git a/instrumentation-security/play-2.13_2.7/build.gradle b/instrumentation-security/play-2.13_2.7/build.gradle index 23b3cf874..87040408c 100644 --- a/instrumentation-security/play-2.13_2.7/build.gradle +++ b/instrumentation-security/play-2.13_2.7/build.gradle @@ -68,6 +68,12 @@ compileTestScala { } } +test { + onlyIf { + !project.hasProperty('includeScala') + } +} + clean { // Clean up any residual generated Routes files to avoid duplicate classes delete 'src/test/scala/router' diff --git a/instrumentation-security/play-2.6/build.gradle b/instrumentation-security/play-2.6/build.gradle index b3fecafda..afc8c5ae9 100644 --- a/instrumentation-security/play-2.6/build.gradle +++ b/instrumentation-security/play-2.6/build.gradle @@ -65,6 +65,12 @@ compileTestScala { } } +test { + onlyIf { + !project.hasProperty('includeScala') + } +} + clean { // Clean up any residual generated Routes files to avoid duplicate classes delete 'src/test/scala/router' diff --git a/instrumentation-security/r2dbc-generic/build.gradle b/instrumentation-security/r2dbc-generic/build.gradle index d383f5462..646444e36 100644 --- a/instrumentation-security/r2dbc-generic/build.gradle +++ b/instrumentation-security/r2dbc-generic/build.gradle @@ -4,7 +4,7 @@ dependencies { implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") implementation("io.r2dbc:r2dbc-h2:0.8.4.RELEASE") testImplementation("com.h2database:h2:1.4.200") - testImplementation("ru.yandex.qatools.embed:postgresql-embedded:2.10") + testImplementation('org.testcontainers:postgresql:1.20.6') testImplementation("org.mariadb:r2dbc-mariadb:1.0.2") testImplementation("dev.miku:r2dbc-mysql:0.8.2.RELEASE") testImplementation("org.postgresql:r2dbc-postgresql:0.9.1.RELEASE") diff --git a/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresStatementTest.java b/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresStatementTest.java index 7ad8a7f9a..82043f251 100644 --- a/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresStatementTest.java +++ b/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresStatementTest.java @@ -18,48 +18,41 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import org.testcontainers.containers.PostgreSQLContainer; import reactor.core.publisher.Mono; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; import java.io.IOException; import java.net.ServerSocket; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; - @RunWith(SecurityInstrumentationTestRunner.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @InstrumentationTestConfig(includePrefixes = "io.r2dbc.spi") public class PostgresStatementTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); - public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; - private static final String HOST = "localhost"; + private static PostgreSQLContainer postgres; + private static Connection connection; private static final List QUERIES = new ArrayList<>(); - private static final int PORT = getRandomPort(); + private static String DB_CONNECTION; @BeforeClass - public static void setup() throws Exception { + public static void setup() { QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); QUERIES.add("INSERT INTO USERS VALUES(1, 'Max', 'John')"); QUERIES.add("SELECT * FROM USERS where first_name = $1"); QUERIES.add("SELECT * FROM USERS where first_name = $1 AND last_name = $2"); - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(SecurityInstrumentationTestRunner.getIntrospector().getRandomPort() + ":5432")); + postgres.start(); - String DB_CONNECTION = ""; - if (postgres.getConnectionUrl().isPresent()){ - DB_CONNECTION = postgres.getConnectionUrl().get() - .replace("jdbc", "r2dbc") - .replace(HOST, "user:password@localhost") - .replace("?user=user&password=password", ""); - } + DB_CONNECTION = postgres.getJdbcUrl() + .replace("jdbc", "r2dbc") + .replace("localhost", String.format("%s:%s@localhost", postgres.getUsername(), postgres.getPassword())); ConnectionFactory connectionFactory = ConnectionFactories.get(DB_CONNECTION); connection = Mono.from(connectionFactory.create()).block(); diff --git a/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresTest.java b/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresTest.java index e54d93ba6..c69e1cc2c 100644 --- a/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresTest.java +++ b/instrumentation-security/r2dbc-generic/src/test/java/com/nr/agent/security/instrumentation/r2dbc/PostgresTest.java @@ -19,43 +19,37 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import org.testcontainers.containers.PostgreSQLContainer; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; import java.io.IOException; import java.net.ServerSocket; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; @RunWith(SecurityInstrumentationTestRunner.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @InstrumentationTestConfig(includePrefixes = "io.r2dbc.spi") public class PostgresTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); - public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; - private static final String HOST = "localhost"; + private static PostgreSQLContainer postgres; + private static Connection connection; private static final List QUERIES = new ArrayList<>(); - private static final int PORT = getRandomPort(); private static String DB_CONNECTION; @BeforeClass - public static void setup() throws IOException { + public static void setup() { QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(SecurityInstrumentationTestRunner.getIntrospector().getRandomPort() + ":5432")); + postgres.start(); - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); - if(postgres.getConnectionUrl().isPresent()){ - DB_CONNECTION = postgres.getConnectionUrl().get() - .replace("jdbc", "r2dbc") - .replace(HOST, "user:password@localhost") - .replace("?user=user&password=password", ""); - } + DB_CONNECTION = postgres.getJdbcUrl() + .replace("jdbc", "r2dbc") + .replace("localhost", String.format("%s:%s@localhost", postgres.getUsername(), postgres.getPassword())); } @AfterClass @@ -196,15 +190,4 @@ private void connection5() { connection.createBatch().add(QUERIES.get(0)).execute(); } - private static int getRandomPort() { - int port; - try { - ServerSocket socket = new ServerSocket(0); - port = socket.getLocalPort(); - socket.close(); - } catch (IOException e) { - throw new RuntimeException("Unable to allocate ephemeral port"); - } - return port; - } } diff --git a/instrumentation-security/r2dbc-postgresql/build.gradle b/instrumentation-security/r2dbc-postgresql/build.gradle index 5b7770bdc..fbc56a408 100644 --- a/instrumentation-security/r2dbc-postgresql/build.gradle +++ b/instrumentation-security/r2dbc-postgresql/build.gradle @@ -3,7 +3,7 @@ dependencies { implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}") implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}") implementation("org.postgresql:r2dbc-postgresql:0.9.1.RELEASE") - testImplementation("ru.yandex.qatools.embed:postgresql-embedded:2.10") + testImplementation('org.testcontainers:postgresql:1.20.6') } jar { diff --git a/instrumentation-security/r2dbc-postgresql/src/test/java/com/nr/agent/security/instrumentation/r2dbc/postgres/ConnectionTest.java b/instrumentation-security/r2dbc-postgresql/src/test/java/com/nr/agent/security/instrumentation/r2dbc/postgres/ConnectionTest.java index d2718cc16..57a5e574f 100644 --- a/instrumentation-security/r2dbc-postgresql/src/test/java/com/nr/agent/security/instrumentation/r2dbc/postgres/ConnectionTest.java +++ b/instrumentation-security/r2dbc-postgresql/src/test/java/com/nr/agent/security/instrumentation/r2dbc/postgres/ConnectionTest.java @@ -20,37 +20,42 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import org.testcontainers.containers.PostgreSQLContainer; import reactor.core.publisher.Mono; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; import java.io.IOException; import java.net.ServerSocket; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; - @RunWith(SecurityInstrumentationTestRunner.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) @InstrumentationTestConfig(includePrefixes = "io.r2dbc.postgresql") public class ConnectionTest { - public static final EmbeddedPostgres postgres = new EmbeddedPostgres(V9_6); - public static Connection connection; - private static final String DB_USER = "user"; - private static final String DB_PASSWORD = "password"; - private static final String DB_NAME = "test"; + private static PostgreSQLContainer postgres; + private static Connection connection; + private static String DB_USER = "user"; + private static String DB_PASSWORD = "password"; + private static String DB_NAME = "test"; private static final String HOST = "localhost"; private static final List QUERIES = new ArrayList<>(); - private static final int PORT = getRandomPort(); + private static int PORT; @BeforeClass - public static void setup() throws Exception { + public static void setup() { + PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); QUERIES.add("CREATE TABLE IF NOT EXISTS USERS(id int primary key, first_name varchar(255), last_name varchar(255))"); QUERIES.add("INSERT INTO USERS(id, first_name, last_name) VALUES(1, 'Max', 'Power')"); QUERIES.add("SELECT * FROM USERS"); - postgres.start(HOST, PORT, DB_NAME, DB_USER, DB_PASSWORD); + postgres = new PostgreSQLContainer<>("postgres:9.6"); + postgres.setPortBindings(Collections.singletonList(PORT + ":5432")); + postgres.start(); + DB_NAME = postgres.getDatabaseName(); + DB_USER = postgres.getUsername(); + DB_PASSWORD = postgres.getPassword(); } @After @@ -139,27 +144,11 @@ private void connect1() { Mono.from(connection.createStatement(QUERIES.get(0)).execute()).block(); } private void connect2() { - if (postgres.getConnectionUrl().isPresent()){ - String url = postgres.getConnectionUrl().get() + String url = postgres.getJdbcUrl() .replace("jdbc", "r2dbc") - .replace(HOST, "user:password@localhost") - .replace("?user=user&password=password", ""); - + .replace(HOST, String.format("%s:%s@%s", DB_USER, DB_PASSWORD, HOST)); ConnectionFactory connectionFactory = ConnectionFactories.get(url); connection = Mono.from(connectionFactory.create()).block(); Mono.from(connection.createStatement(QUERIES.get(0)).execute()).block(); - } - } - - private static int getRandomPort() { - int port; - try { - ServerSocket socket = new ServerSocket(0); - port = socket.getLocalPort(); - socket.close(); - } catch (IOException e) { - throw new RuntimeException("Unable to allocate ephemeral port"); - } - return port; } } \ No newline at end of file diff --git a/instrumentation-security/resteasy-2.2/src/test/java/com/nr/instrumentation/resteasy2_2/test/APIEndpointTest.java b/instrumentation-security/resteasy-2.2/src/test/java/com/nr/instrumentation/resteasy2_2/test/APIEndpointTest.java index 03dea225e..5cd3fa035 100644 --- a/instrumentation-security/resteasy-2.2/src/test/java/com/nr/instrumentation/resteasy2_2/test/APIEndpointTest.java +++ b/instrumentation-security/resteasy-2.2/src/test/java/com/nr/instrumentation/resteasy2_2/test/APIEndpointTest.java @@ -5,6 +5,7 @@ import com.newrelic.api.agent.Trace; import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper; import com.newrelic.api.agent.security.schema.ApplicationURLMapping; +import com.newrelic.security.test.marker.*; import com.nr.instrumentation.resteasy2_2.app.CustomerLocatorResource; import com.nr.instrumentation.resteasy2_2.app.TestMapping; import org.apache.catalina.LifecycleException; @@ -12,6 +13,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.io.IOException; @@ -23,6 +25,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.resteasy2", "org.jboss.resteasy.core.registry"}) +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class APIEndpointTest { private final String handler = TestMapping.class.getName(); diff --git a/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java b/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java index 23bbc0e74..66987c86c 100644 --- a/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java +++ b/instrumentation-security/resteasy-3/src/test/java/com/nr/instrumentation/resteasy3/test/APIEndpointTest.java @@ -5,6 +5,7 @@ import com.newrelic.api.agent.Trace; import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper; import com.newrelic.api.agent.security.schema.ApplicationURLMapping; +import com.newrelic.security.test.marker.*; import com.nr.instrumentation.resteasy3.app.CustomerLocatorResource; import com.nr.instrumentation.resteasy3.app.TestMapping; import org.apache.catalina.LifecycleException; @@ -12,6 +13,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.io.IOException; @@ -24,6 +26,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.resteasy3", "org.jboss.resteasy.core.registry"}) +@Category({ Java9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class APIEndpointTest { private final String handler = TestMapping.class.getName(); private static final String path = "/users"; diff --git a/instrumentation-security/solr-4.0.0/src/test/java/com/nr/agent/instrumentation/solr4/SolrTest.java b/instrumentation-security/solr-4.0.0/src/test/java/com/nr/agent/instrumentation/solr4/SolrTest.java index 7dc088a8e..751171ba6 100644 --- a/instrumentation-security/solr-4.0.0/src/test/java/com/nr/agent/instrumentation/solr4/SolrTest.java +++ b/instrumentation-security/solr-4.0.0/src/test/java/com/nr/agent/instrumentation/solr4/SolrTest.java @@ -4,6 +4,7 @@ import com.newrelic.agent.security.introspec.SecurityInstrumentationTestRunner; import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.operation.SolrDbOperation; +import com.newrelic.security.test.marker.*; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.HttpSolrServer; @@ -14,6 +15,7 @@ import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.testcontainers.containers.GenericContainer; @@ -27,6 +29,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.apache.solr") @FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class SolrTest { private static GenericContainer solrServer; diff --git a/instrumentation-security/spring-webmvc-6.0.0/build.gradle b/instrumentation-security/spring-webmvc-6.0.0/build.gradle index 4c4ba2b7f..477a6b34d 100644 --- a/instrumentation-security/spring-webmvc-6.0.0/build.gradle +++ b/instrumentation-security/spring-webmvc-6.0.0/build.gradle @@ -31,9 +31,9 @@ java { } test { - // These instrumentation tests only run on Java 17+ regardless of the -PtestN gradle property that is set. + // These instrumentation tests only run on Java 17 regardless of the -PtestN gradle property that is set. onlyIf { - !project.hasProperty('test8') && !project.hasProperty('test11') + project.hasProperty('test17') } } diff --git a/instrumentation-security/sun-net-httpserver/src/test/java/com/nr/agent/security/instrumentation/httpServer/test/HttpServerTest.java b/instrumentation-security/sun-net-httpserver/src/test/java/com/nr/agent/security/instrumentation/httpServer/test/HttpServerTest.java index 6f56e44cd..48eb3a61e 100644 --- a/instrumentation-security/sun-net-httpserver/src/test/java/com/nr/agent/security/instrumentation/httpServer/test/HttpServerTest.java +++ b/instrumentation-security/sun-net-httpserver/src/test/java/com/nr/agent/security/instrumentation/httpServer/test/HttpServerTest.java @@ -13,6 +13,8 @@ import com.newrelic.api.agent.security.schema.operation.RXSSOperation; import com.newrelic.security.test.marker.Java11IncompatibleTest; import com.newrelic.security.test.marker.Java17IncompatibleTest; +import com.newrelic.security.test.marker.Java21IncompatibleTest; +import com.newrelic.security.test.marker.Java23IncompatibleTest; import com.newrelic.security.test.marker.Java9IncompatibleTest; import org.junit.Assert; import org.junit.ClassRule; @@ -35,7 +37,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "com.sun.net.httpserver"}) -@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class }) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class HttpServerTest { @ClassRule public static Httpserver server = new Httpserver(); diff --git a/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/URLConnectionTest.java b/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/URLConnectionTest.java index 0e6bf6791..f454ca66f 100644 --- a/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/URLConnectionTest.java +++ b/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/URLConnectionTest.java @@ -10,7 +10,9 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.SSRFOperation; +import com.newrelic.security.test.marker.*; import org.junit.*; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; @@ -25,6 +27,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.urlconnection"}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class URLConnectionTest { public String endpoint; diff --git a/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/ftp/FTPConnectionTest.java b/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/ftp/FTPConnectionTest.java index 6fab4473d..7f137dd18 100644 --- a/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/ftp/FTPConnectionTest.java +++ b/instrumentation-security/urlconnection/src/test/java/com/nr/agent/security/instrumentation/urlconnection/ftp/FTPConnectionTest.java @@ -8,7 +8,9 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.SSRFOperation; +import com.newrelic.security.test.marker.*; import org.junit.*; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import sun.net.www.protocol.ftp.FtpURLConnection; @@ -22,6 +24,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.newrelic.agent.security.instrumentation.urlconnection"}) @FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class FTPConnectionTest { private static final String FTP_USER = "user"; private static final String FTP_PASSWORD = "password"; diff --git a/instrumentation-security/vertx-core-3.3.0/build.gradle b/instrumentation-security/vertx-core-3.3.0/build.gradle index bea94f57b..52acb8095 100644 --- a/instrumentation-security/vertx-core-3.3.0/build.gradle +++ b/instrumentation-security/vertx-core-3.3.0/build.gradle @@ -17,6 +17,14 @@ verifyInstrumentation { excludeRegex '.*(milestone|CR|Beta)[0-9]*' } +test { + // this version of Vert.x uses some DirectBuffer things that are now hidden in its module + if (project.hasProperty("test17") || project.hasProperty("test21") || project.hasProperty("test23")) { + jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' + jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' + } +} + site { title 'Vertx' type 'Framework' diff --git a/instrumentation-security/vertx-core-3.4.0/build.gradle b/instrumentation-security/vertx-core-3.4.0/build.gradle index a65c8ff23..2f8c6627f 100644 --- a/instrumentation-security/vertx-core-3.4.0/build.gradle +++ b/instrumentation-security/vertx-core-3.4.0/build.gradle @@ -20,6 +20,14 @@ verifyInstrumentation { excludeRegex '.*Beta[0-9]' } +test { + // this version of Vert.x uses some DirectBuffer things that are now hidden in its module + if (project.hasProperty("test17") || project.hasProperty("test21") || project.hasProperty("test23")) { + jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' + jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' + } +} + site { title 'Vertx' type 'Framework' diff --git a/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/VertxClientTest.java b/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/VertxClientTest.java index cbdefc67c..1eda347cf 100644 --- a/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/VertxClientTest.java +++ b/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/VertxClientTest.java @@ -16,6 +16,7 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.SSRFOperation; +import com.newrelic.security.test.marker.*; import io.vertx.core.Handler; import io.vertx.core.MultiMap; import io.vertx.core.Vertx; @@ -31,6 +32,7 @@ import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.util.List; @@ -40,6 +42,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "io.vertx.core" }) @FixMethodOrder +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class VertxClientTest { private static int port; private static HttpClient httpClient; diff --git a/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/WebClientTest.java b/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/WebClientTest.java index 6f8a8e95f..a93c5f483 100644 --- a/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/WebClientTest.java +++ b/instrumentation-security/vertx-core-3.4.0/src/test/java/com/nr/agent/security/instrumentation/vertx/core340/WebClientTest.java @@ -7,6 +7,7 @@ import com.newrelic.api.agent.security.schema.AbstractOperation; import com.newrelic.api.agent.security.schema.VulnerabilityCaseType; import com.newrelic.api.agent.security.schema.operation.SSRFOperation; +import com.newrelic.security.test.marker.*; import io.vertx.core.AsyncResult; import io.vertx.core.Handler; import io.vertx.core.Vertx; @@ -21,6 +22,7 @@ import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.util.List; @@ -29,6 +31,7 @@ @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "io.vertx.core" }) @FixMethodOrder +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class, Java23IncompatibleTest.class }) public class WebClientTest { private static int port; private static WebClient webClient; diff --git a/instrumentation-security/vertx-core-3.7.1/build.gradle b/instrumentation-security/vertx-core-3.7.1/build.gradle index 3b1b8db62..6e263b3ea 100644 --- a/instrumentation-security/vertx-core-3.7.1/build.gradle +++ b/instrumentation-security/vertx-core-3.7.1/build.gradle @@ -21,6 +21,14 @@ verifyInstrumentation { excludeRegex '.*-milestone[0-9]' } +test { + // this version of Vert.x uses some DirectBuffer things that are now hidden in its module + if (project.hasProperty("test17") || project.hasProperty("test21") || project.hasProperty("test23")) { + jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' + jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' + } +} + site { title 'Vertx' type 'Framework' diff --git a/instrumentation-security/vertx-core-4.0.0/build.gradle b/instrumentation-security/vertx-core-4.0.0/build.gradle index 8f8012a66..3d1161274 100644 --- a/instrumentation-security/vertx-core-4.0.0/build.gradle +++ b/instrumentation-security/vertx-core-4.0.0/build.gradle @@ -22,6 +22,14 @@ verifyInstrumentation { excludeRegex '.*Beta[0-9]' } +test { + // this version of Vert.x uses some DirectBuffer things that are now hidden in its module + if (project.hasProperty("test17") || project.hasProperty("test21") || project.hasProperty("test23")) { + jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' + jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' + } +} + site { title 'Vertx' type 'Framework' diff --git a/instrumentation-security/vertx-web-3.2.0/build.gradle b/instrumentation-security/vertx-web-3.2.0/build.gradle index c56071b5f..3b94ddaf3 100644 --- a/instrumentation-security/vertx-web-3.2.0/build.gradle +++ b/instrumentation-security/vertx-web-3.2.0/build.gradle @@ -16,6 +16,14 @@ verifyInstrumentation { exclude('io.vertx:vertx-web:3.1.0') } +test { + // this version of Vert.x uses some DirectBuffer things that are now hidden in its module + if (project.hasProperty("test17") || project.hasProperty("test21") || project.hasProperty("test23")) { + jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' + jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' + } +} + site { title 'Vertx' type 'Framework' diff --git a/instrumentation-security/vertx-web-3.5.1/build.gradle b/instrumentation-security/vertx-web-3.5.1/build.gradle index 676c51270..8c1915038 100644 --- a/instrumentation-security/vertx-web-3.5.1/build.gradle +++ b/instrumentation-security/vertx-web-3.5.1/build.gradle @@ -14,6 +14,14 @@ verifyInstrumentation { excludeRegex '.*milestone[0-9]*' } +test { + // this version of Vert.x uses some DirectBuffer things that are now hidden in its module + if (project.hasProperty("test17") || project.hasProperty("test21") || project.hasProperty("test23")) { + jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' + jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' + } +} + site { title 'Vertx' type 'Framework' diff --git a/instrumentation-security/vertx-web-3.8.3/build.gradle b/instrumentation-security/vertx-web-3.8.3/build.gradle index 2132b63d7..51612a560 100644 --- a/instrumentation-security/vertx-web-3.8.3/build.gradle +++ b/instrumentation-security/vertx-web-3.8.3/build.gradle @@ -14,6 +14,14 @@ verifyInstrumentation { excludeRegex '.*milestone[0-9]*' } +test { + // this version of Vert.x uses some DirectBuffer things that are now hidden in its module + if (project.hasProperty("test17") || project.hasProperty("test21") || project.hasProperty("test23")) { + jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' + jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' + } +} + site { title 'Vertx' type 'Framework' diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/IASTDataTransferRequestProcessor.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/IASTDataTransferRequestProcessor.java index 31ebfa7a7..6dd38ae36 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/IASTDataTransferRequestProcessor.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/httpclient/IASTDataTransferRequestProcessor.java @@ -118,7 +118,9 @@ private void task() { pendingRequestIds.addAll(RestRequestThreadPool.getInstance().getPendingIds()); pendingRequestIds.addAll(GrpcClientRequestReplayHelper.getInstance().getPendingIds()); request.setPendingRequestIds(pendingRequestIds); - WSClient.getInstance().send(request.toString()); + if(WSClient.getInstance().isOpen()) { + WSClient.getInstance().send(request.toString()); + } } } catch (Throwable e) { logger.log(LogLevel.SEVERE, String.format(UNABLE_TO_SEND_IAST_DATA_REQUEST_DUE_TO_ERROR_S_S, e.toString(), e.getCause().toString()), this.getClass().getName()); diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/utils/AgentUtils.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/utils/AgentUtils.java index fb55e2945..42bb7153d 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/utils/AgentUtils.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/utils/AgentUtils.java @@ -399,7 +399,9 @@ public boolean applyPolicyOverrideIfApplicable() { logger.log(LogLevel.INFO, String.format(NR_POLICY_OVER_RIDE_IN_PLACE_UPDATED_POLICY_S, JsonConverter.toJSON(AgentUtils.getInstance().getAgentPolicy())), AgentUtils.class.getName()); try { - WSClient.getInstance().send(JsonConverter.toJSON(AgentUtils.getInstance().getAgentPolicy())); + if(WSClient.getInstance().isOpen()) { + WSClient.getInstance().send(JsonConverter.toJSON(AgentUtils.getInstance().getAgentPolicy())); + } AgentUtils.getInstance().getStatusLogValues().put(POLICY_VERSION, AgentUtils.getInstance().getAgentPolicy().getVersion()); EventSendPool.getInstance().sendEvent(AgentInfo.getInstance().getApplicationInfo()); return true; diff --git a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/EventSender.java b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/EventSender.java index 889bd35e0..15e3c4ba3 100644 --- a/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/EventSender.java +++ b/newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/EventSender.java @@ -38,7 +38,7 @@ public Boolean call() throws Exception { if (event instanceof JavaAgentEventBean) { ((JavaAgentEventBean) event).setEventGenerationTime(System.currentTimeMillis()); } - if(WSUtils.isConnected()) { + if(WSClient.getInstance().isOpen()) { WSClient.getInstance().send(JsonConverter.toJSON(event)); } return true; diff --git a/test-annotations/src/main/java/com/newrelic/security/test/marker/Java21IncompatibleTest.java b/test-annotations/src/main/java/com/newrelic/security/test/marker/Java21IncompatibleTest.java new file mode 100644 index 000000000..7e7c9cced --- /dev/null +++ b/test-annotations/src/main/java/com/newrelic/security/test/marker/Java21IncompatibleTest.java @@ -0,0 +1,7 @@ +package com.newrelic.security.test.marker; + +/** + * Marker interface to denote a unit/functional/instrumentation test that is incompatible with Java 21. + */ +public interface Java21IncompatibleTest { +} diff --git a/test-annotations/src/main/java/com/newrelic/security/test/marker/Java23IncompatibleTest.java b/test-annotations/src/main/java/com/newrelic/security/test/marker/Java23IncompatibleTest.java new file mode 100644 index 000000000..4ebfee170 --- /dev/null +++ b/test-annotations/src/main/java/com/newrelic/security/test/marker/Java23IncompatibleTest.java @@ -0,0 +1,7 @@ +package com.newrelic.security.test.marker; + +/** + * Marker interface to denote a unit/functional/instrumentation test that is incompatible with Java 23. + */ +public interface Java23IncompatibleTest { +}