From 4be031bebe693527082ff32f9f190b4147ad43e5 Mon Sep 17 00:00:00 2001 From: idawda Date: Mon, 17 Mar 2025 18:55:46 +0530 Subject: [PATCH 01/25] run dependency-submission workflow when pull request is created --- .github/workflows/dependency-submission.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml index a3aa139dc..5048c4fb9 100644 --- a/.github/workflows/dependency-submission.yml +++ b/.github/workflows/dependency-submission.yml @@ -3,6 +3,7 @@ name: Dependency Submission on: push: branches: ['main'] + pull_request: permissions: contents: write From 407209bcb0708f1ffa52087fd2d2338d7cafd7f4 Mon Sep 17 00:00:00 2001 From: idawda Date: Mon, 17 Mar 2025 18:58:31 +0530 Subject: [PATCH 02/25] Java 23 support --- .github/actions/setup-environment/action.yml | 4 ++- gradle/script/java.gradle | 32 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml index c9971074c..14204c34a 100644 --- a/.github/actions/setup-environment/action.yml +++ b/.github/actions/setup-environment/action.yml @@ -36,6 +36,7 @@ runs: with: distribution: 'temurin' java-version: | + 23 21 20 17 @@ -50,7 +51,8 @@ runs: 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 diff --git a/gradle/script/java.gradle b/gradle/script/java.gradle index f7c6663cf..f98691eae 100644 --- a/gradle/script/java.gradle +++ b/gradle/script/java.gradle @@ -89,6 +89,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.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.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', From c0caa29d682ac3c5fda63dd3953ccdd2cd652f0a Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 16:53:07 +0530 Subject: [PATCH 03/25] Update GHA workflow to run unit tests on pull request action --- .github/actions/unit-test/action.yml | 22 +++++++++--- ...-Security-Agent.yml => GHA-Unit-Tests.yml} | 36 ++++++++++++++++--- .github/workflows/build-integrated-jar.yml | 11 +++++- .github/workflows/dependency-submission.yml | 11 ++++-- .github/workflows/repolinter.yml | 2 +- 5 files changed, 69 insertions(+), 13 deletions(-) rename .github/workflows/{X-Reusable-Build-Security-Agent.yml => GHA-Unit-Tests.yml} (69%) diff --git a/.github/actions/unit-test/action.yml b/.github/actions/unit-test/action.yml index 06ab3371d..8e93889b5 100644 --- a/.github/actions/unit-test/action.yml +++ b/.github/actions/unit-test/action.yml @@ -5,17 +5,31 @@ 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 --info 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" + echo "Running attempt 1 with ${{ inputs.java-version }}" ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 2 @@ -24,7 +38,7 @@ runs: continue-on-error: true if: steps.run_tests_1.outcome == 'failure' run: | - echo "Running attempt 2" + echo "Running attempt 2 with ${{ inputs.java-version }}" ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 3 @@ -33,7 +47,7 @@ runs: continue-on-error: true if: steps.run_tests_2.outcome == 'failure' run: | - echo "Running attempt 3" + echo "Running attempt 3 with ${{ inputs.java-version }}" ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 4 @@ -41,5 +55,5 @@ runs: 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 69% rename from .github/workflows/X-Reusable-Build-Security-Agent.yml rename to .github/workflows/GHA-Unit-Tests.yml index 516344f99..33f6e4427 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,19 @@ 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, 23 ] ' + required: true + default: '[ 8, 11, 17, 21, 23 ]' + type: string + + 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 @@ -61,8 +87,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - java-version: [ 8 ] -# java-version: [ 8, 11, 17 ] + java-version: ${{ fromJson(inputs.unit-test-java-version) || fromJson('[ 8, 11, 17, 21, 23 ]') }} steps: - name: Checkout CSEC Repo @@ -86,4 +111,5 @@ jobs: if: ${{ inputs.run-unit-test == 'true' }} uses: ./.github/actions/unit-test with: + csec-run-scala-unittest: ${{ inputs.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 6d5fc9751..d55ba2e56 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 5048c4fb9..8ca9da530 100644 --- a/.github/workflows/dependency-submission.yml +++ b/.github/workflows/dependency-submission.yml @@ -1,3 +1,10 @@ +# 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: @@ -13,9 +20,9 @@ jobs: runs-on: ubuntu-22.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 d3db3615c..cbaf07f56 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 From 15cc727af1ff91e8d10646298514db91129696c3 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 16:55:58 +0530 Subject: [PATCH 04/25] Fix unit tests failing on various java version --- .../agent/security/instrumentation/jersey2/JerseyTests.java | 2 +- .../agent/security/instrumentation/jersey2/JerseyTests.java | 2 +- .../agent/security/instrumentation/jersey2/JerseyTests.java | 2 +- instrumentation-security/jetty-12/build.gradle | 4 ++-- instrumentation-security/play-2.13_2.7/build.gradle | 6 ++++++ instrumentation-security/play-2.6/build.gradle | 6 ++++++ instrumentation-security/spring-webmvc-6.0.0/build.gradle | 4 ++-- 7 files changed, 19 insertions(+), 7 deletions(-) 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 19fb1f5d3..150afd0e7 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 @@ -117,7 +117,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 fe5b4e607..7ea713c92 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 @@ -117,7 +117,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 0ccf39689..bcd2f1cb8 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 @@ -116,7 +116,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/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/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/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') } } From 5a56824f2a05c77fcb4c28079af85c51768ddba0 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 17:21:12 +0530 Subject: [PATCH 05/25] Update GHA workflow to run unit tests --- .github/workflows/GHA-Unit-Tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/GHA-Unit-Tests.yml b/.github/workflows/GHA-Unit-Tests.yml index 33f6e4427..af593d6ae 100644 --- a/.github/workflows/GHA-Unit-Tests.yml +++ b/.github/workflows/GHA-Unit-Tests.yml @@ -80,6 +80,9 @@ on: pull_request: branches: [ main ] +env: + JAVA_VERSIONS: ${{ github.event.inputs.unit-test-java-version || '[ 8, 11, 17, 21, 23 ]' }} + RUN_SCALA_UNIT_TEST: ${{ github.event.inputs.csec-run-scala-unittest || true }} 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. @@ -87,7 +90,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - java-version: ${{ fromJson(inputs.unit-test-java-version) || fromJson('[ 8, 11, 17, 21, 23 ]') }} + java-version: ${{ fromJson(env.JAVA_VERSIONS) }} steps: - name: Checkout CSEC Repo @@ -111,5 +114,5 @@ jobs: if: ${{ inputs.run-unit-test == 'true' }} uses: ./.github/actions/unit-test with: - csec-run-scala-unittest: ${{ inputs.csec-run-scala-unittest || 'true' }} + csec-run-scala-unittest: ${{ env.RUN_SCALA_UNIT_TEST }} java-version: ${{ matrix.java-version }} \ No newline at end of file From 77a3b3e98f6b024ae0b202e2155f796599561274 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 17:37:11 +0530 Subject: [PATCH 06/25] Update GHA workflow to run unit tests --- .github/workflows/GHA-Unit-Tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/GHA-Unit-Tests.yml b/.github/workflows/GHA-Unit-Tests.yml index af593d6ae..953c57fbe 100644 --- a/.github/workflows/GHA-Unit-Tests.yml +++ b/.github/workflows/GHA-Unit-Tests.yml @@ -83,6 +83,7 @@ on: env: JAVA_VERSIONS: ${{ github.event.inputs.unit-test-java-version || '[ 8, 11, 17, 21, 23 ]' }} RUN_SCALA_UNIT_TEST: ${{ github.event.inputs.csec-run-scala-unittest || true }} + 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. @@ -90,7 +91,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - java-version: ${{ fromJson(env.JAVA_VERSIONS) }} + java-version: ${{ fromJson(JAVA_VERSIONS) }} steps: - name: Checkout CSEC Repo From a1c9e9b17dd9a9a85ba04e45f4e46588b2a56e63 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 17:43:47 +0530 Subject: [PATCH 07/25] Update GHA workflow to run unit tests --- .github/workflows/GHA-Unit-Tests.yml | 11 ++------ .github/workflows/TestSuite-PR.yml | 42 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/TestSuite-PR.yml diff --git a/.github/workflows/GHA-Unit-Tests.yml b/.github/workflows/GHA-Unit-Tests.yml index 953c57fbe..13beafd65 100644 --- a/.github/workflows/GHA-Unit-Tests.yml +++ b/.github/workflows/GHA-Unit-Tests.yml @@ -77,13 +77,6 @@ on: default: '[ 8, 11, 17, 21, 23 ]' type: string - pull_request: - branches: [ main ] - -env: - JAVA_VERSIONS: ${{ github.event.inputs.unit-test-java-version || '[ 8, 11, 17, 21, 23 ]' }} - RUN_SCALA_UNIT_TEST: ${{ github.event.inputs.csec-run-scala-unittest || true }} - 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. @@ -91,7 +84,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - java-version: ${{ fromJson(JAVA_VERSIONS) }} + java-version: ${{ fromJson(inputs.unit-test-java-version) }} steps: - name: Checkout CSEC Repo @@ -115,5 +108,5 @@ jobs: if: ${{ inputs.run-unit-test == 'true' }} uses: ./.github/actions/unit-test with: - csec-run-scala-unittest: ${{ env.RUN_SCALA_UNIT_TEST }} + 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..493abf182 --- /dev/null +++ b/.github/workflows/TestSuite-PR.yml @@ -0,0 +1,42 @@ +# 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-20.04 + strategy: + matrix: + java-version: [ 8, 11, 17, 21, 23 ] + + steps: + - name: Checkout CSEC Repo + uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + + - name: Setup environment + uses: ./.github/actions/setup-environment + with: + apm-repo: ${{ inputs.apm-repo }} + apm-branch: ${{ inputs.apm-source-ref }} + 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 + if: ${{ inputs.run-unit-test == 'true' }} + uses: ./.github/actions/unit-test + with: + csec-run-scala-unittest: true + java-version: ${{ matrix.java-version }} \ No newline at end of file From ba97bc85ec3867e539ff2c8a011404b35428e74b Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 20:51:34 +0530 Subject: [PATCH 08/25] Fix unit tests failing on various java version --- .../apache-tomcat-7/build.gradle | 7 +++ .../cassandra-datastax-3/build.gradle | 7 +++ .../cassandra-datastax-4/build.gradle | 7 +++ .../instrumentation/javaio/FileTest.java | 3 ++ .../javaio/InputStreamJdk8Test.java | 4 +- .../java/lang/ProcessImplTest.java | 3 ++ .../javax/jndi/ContextRmiTest.java | 4 ++ .../javax/jndi/ContextTest.java | 8 ++++ .../javax/internal/XPathInternalTest.java | 4 +- .../ws/rs/api/test/JavaxWsRsApiTest.java | 7 +++ .../javax/ws/rs/api/test/SubresourceTest.java | 7 +++ .../instrumentation/jersey2/JerseyTests.java | 4 +- .../instrumentation/jersey2/JerseyTests.java | 4 +- .../instrumentation/jersey2/JerseyTests.java | 6 ++- .../javax/ws/rs/api/test/SubresourceTest.java | 48 ++++++++----------- .../instrumentation/random/RandomTest.java | 4 +- .../nashorn/NashornScriptEngineTest.java | 4 +- .../resteasy2_2/test/APIEndpointTest.java | 3 ++ .../resteasy3/test/APIEndpointTest.java | 3 ++ .../httpServer/test/HttpServerTest.java | 4 +- .../urlconnection/URLConnectionTest.java | 3 ++ .../urlconnection/ftp/FTPConnectionTest.java | 3 ++ .../vertx/core340/VertxClientTest.java | 3 ++ .../vertx/core340/WebClientTest.java | 3 ++ 24 files changed, 117 insertions(+), 36 deletions(-) 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-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 096799577..65ebab31f 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().toString(); 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/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 150afd0e7..c17bf62ed 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; @@ -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; 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 7ea713c92..36a76c3a6 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; 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 bcd2f1cb8..fa4819793 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; @@ -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.getResponseBody().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 874b7f0eb..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 @@ -1,27 +1,30 @@ package com.nr.agent.security.instrumentation.javax.ws.rs.api.test; +import com.newrelic.agent.security.introspec.InstrumentationTestConfig; +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.newrelic.agent.security.introspec.InstrumentationTestConfig; -import com.newrelic.agent.security.introspec.SecurityInstrumentationTestRunner; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.OrdersSubResource; import com.nr.agent.security.instrumentation.javax.ws.rs.api.app.TestMapping; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory; +import org.glassfish.jersey.test.spi.TestContainerFactory; 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 javax.ws.rs.core.Application; -import java.util.Iterator; +import java.util.Set; @RunWith(SecurityInstrumentationTestRunner.class) -@InstrumentationTestConfig(includePrefixes = { "com.nr.instrumentation.security.jersey", "org.glassfish.jersey.server.internal" }) -@Ignore +@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() { @@ -32,32 +35,23 @@ public static void bringUp() { public void testAPIEndpoints() { target("/customers/orders/getStuff/1").request().get(); - Iterator mappings = URLMappingsHelper.getApplicationURLMappings().iterator(); - - Assert.assertTrue(mappings.hasNext()); - assertMapping("/customers/orders/*", "*", CustomerLocatorResource.class.getName(), mappings.next()); - - Assert.assertTrue(mappings.hasNext()); - assertMapping("/users/count", "GET", TestMapping.class.getName(), mappings.next()); - - Assert.assertTrue(mappings.hasNext()); - assertMapping("/users", "PUT", TestMapping.class.getName(), mappings.next()); + Set mappings = URLMappingsHelper.getApplicationURLMappings(); + Assert.assertEquals(5, mappings.size()); - Assert.assertTrue(mappings.hasNext()); - assertMapping("/users", "OPTIONS", TestMapping.class.getName(), mappings.next()); - - Assert.assertTrue(mappings.hasNext()); - assertMapping("/users/count", "OPTIONS", TestMapping.class.getName(), mappings.next()); - } - - private void assertMapping(String path, String method, String handler, ApplicationURLMapping actualMapping){ - Assert.assertEquals(path, actualMapping.getPath()); - Assert.assertEquals(method, actualMapping.getMethod()); - Assert.assertEquals(handler, actualMapping.getHandler()); + Assert.assertTrue(mappings.contains(new ApplicationURLMapping("*", "/customers/orders/*", CustomerLocatorResource.class.getName()))); + Assert.assertTrue(mappings.contains(new ApplicationURLMapping("GET","/users/count", TestMapping.class.getName()))); + Assert.assertTrue(mappings.contains(new ApplicationURLMapping("PUT","/users", TestMapping.class.getName()))); + Assert.assertTrue(mappings.contains(new ApplicationURLMapping("OPTIONS","/users", TestMapping.class.getName()))); + Assert.assertTrue(mappings.contains(new ApplicationURLMapping("OPTIONS", "/users/count", TestMapping.class.getName()))); } @Override protected Application configure() { return new ResourceConfig(CustomerLocatorResource.class, IdSubResource.class, OrdersSubResource.class, TestMapping.class); } + + @Override + protected TestContainerFactory getTestContainerFactory() { + return new GrizzlyTestContainerFactory(); + } } 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/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/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 abb52a53a..ae52e6c7a 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; @@ -24,6 +26,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.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; From 1f1d408632be8d3d92dee2333ee4d2ff854f0dd9 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 20:52:06 +0530 Subject: [PATCH 09/25] Add support java version 21 and 23 --- gradle/script/java.gradle | 21 +++++++++++++++++-- .../test/marker/Java21IncompatibleTest.java | 7 +++++++ .../test/marker/Java23IncompatibleTest.java | 7 +++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test-annotations/src/main/java/com/newrelic/security/test/marker/Java21IncompatibleTest.java create mode 100644 test-annotations/src/main/java/com/newrelic/security/test/marker/Java23IncompatibleTest.java diff --git a/gradle/script/java.gradle b/gradle/script/java.gradle index f98691eae..902f9963c 100644 --- a/gradle/script/java.gradle +++ b/gradle/script/java.gradle @@ -9,6 +9,23 @@ dependencies { } jar { + // 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() + } + // Allow any java projects to bundle third party libraries into the jar from { configurations.includeInJar.collect { @@ -99,7 +116,7 @@ test { '--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.test.marker.Java23IncompatibleTest' + excludeCategories 'com.newrelic.security.test.marker.Java23IncompatibleTest' } } // mockito uses a version of bytebuddy that has experimental support for Java 21 @@ -115,7 +132,7 @@ test { '--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.test.marker.Java21IncompatibleTest' + excludeCategories 'com.newrelic.security.test.marker.Java21IncompatibleTest' } } // mockito uses a version of bytebuddy that has experimental support for Java 21 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 { +} From f13e126c43c36368d3df6838c3b507e265a95ee4 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 21:19:10 +0530 Subject: [PATCH 10/25] Remove inputs from PR based workflow --- .github/workflows/TestSuite-PR.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/TestSuite-PR.yml b/.github/workflows/TestSuite-PR.yml index 493abf182..8abe37024 100644 --- a/.github/workflows/TestSuite-PR.yml +++ b/.github/workflows/TestSuite-PR.yml @@ -25,8 +25,6 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-environment with: - apm-repo: ${{ inputs.apm-repo }} - apm-branch: ${{ inputs.apm-source-ref }} 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 @@ -35,7 +33,6 @@ jobs: uses: ./.github/actions/publish-csec-local - name: Run CSEC unit tests - if: ${{ inputs.run-unit-test == 'true' }} uses: ./.github/actions/unit-test with: csec-run-scala-unittest: true From 129ed0f1bac5fd3ac973ac7be8f808df3dbaa18c Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 21:19:31 +0530 Subject: [PATCH 11/25] Debug unit test run --- .github/workflows/GHA-Unit-Tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/GHA-Unit-Tests.yml b/.github/workflows/GHA-Unit-Tests.yml index 13beafd65..526253cb5 100644 --- a/.github/workflows/GHA-Unit-Tests.yml +++ b/.github/workflows/GHA-Unit-Tests.yml @@ -105,7 +105,7 @@ jobs: uses: ./.github/actions/publish-csec-local - name: Run CSEC unit tests - if: ${{ inputs.run-unit-test == 'true' }} +# if: ${{ inputs.run-unit-test == 'true' }} uses: ./.github/actions/unit-test with: csec-run-scala-unittest: ${{ inputs.csec-run-scala-unittest }} From 7176f2fa83b50062c8aa74dfbc804af2df07c1c6 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 21:39:37 +0530 Subject: [PATCH 12/25] Upgrade setup-java action version --- .../action.yml | 6 ++-- .github/actions/setup-environment/action.yml | 4 +-- gradle/script/java.gradle | 35 ++++++++++--------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.github/actions/setup-environment-inst-verifier/action.yml b/.github/actions/setup-environment-inst-verifier/action.yml index 3ec3aadd7..adf3eb2ea 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|jdk20=${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 14204c34a..46cff2710 100644 --- a/.github/actions/setup-environment/action.yml +++ b/.github/actions/setup-environment/action.yml @@ -32,13 +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 @@ -50,7 +49,6 @@ 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}| s|jdk23=23|jdk23=${JAVA_HOME_23_X64}|" gradle.properties.gha cat gradle.properties.gha >> gradle.properties diff --git a/gradle/script/java.gradle b/gradle/script/java.gradle index 902f9963c..2ef9f251a 100644 --- a/gradle/script/java.gradle +++ b/gradle/script/java.gradle @@ -9,23 +9,6 @@ dependencies { } jar { - // 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() - } - // Allow any java projects to bundle third party libraries into the jar from { configurations.includeInJar.collect { @@ -98,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) From e9d4fcfe3e129b3049a3580788a920452c8666f7 Mon Sep 17 00:00:00 2001 From: idawda Date: Tue, 25 Mar 2025 22:01:47 +0530 Subject: [PATCH 13/25] Java 23 support --- .github/actions/setup-environment/action.yml | 2 +- gradle.properties.gha | 4 ++-- instrumentation-security/vertx-core-3.3.0/build.gradle | 8 ++++++++ instrumentation-security/vertx-core-3.4.0/build.gradle | 8 ++++++++ instrumentation-security/vertx-core-3.7.1/build.gradle | 8 ++++++++ instrumentation-security/vertx-core-4.0.0/build.gradle | 8 ++++++++ instrumentation-security/vertx-web-3.2.0/build.gradle | 8 ++++++++ instrumentation-security/vertx-web-3.5.1/build.gradle | 8 ++++++++ instrumentation-security/vertx-web-3.8.3/build.gradle | 8 ++++++++ 9 files changed, 59 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml index 46cff2710..e6403a643 100644 --- a/.github/actions/setup-environment/action.yml +++ b/.github/actions/setup-environment/action.yml @@ -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/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/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.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' From 6aee0898c848b056f517d2243569bb4b07c3f91b Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 26 Mar 2025 09:26:09 +0530 Subject: [PATCH 14/25] Disabling unit tests run on java 23 due to Unsupported class file --- .github/workflows/GHA-Unit-Tests.yml | 7 ++++--- .github/workflows/TestSuite-PR.yml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/GHA-Unit-Tests.yml b/.github/workflows/GHA-Unit-Tests.yml index 526253cb5..78c8fe99d 100644 --- a/.github/workflows/GHA-Unit-Tests.yml +++ b/.github/workflows/GHA-Unit-Tests.yml @@ -72,9 +72,9 @@ on: type: boolean default: true unit-test-java-version: - description: 'Run Unit test on java version, default java versions are [ 8, 11, 17, 21, 23 ] ' + description: 'Run Unit test on java version, default java versions are [ 8, 11, 17, 21 ] ' required: true - default: '[ 8, 11, 17, 21, 23 ]' + default: '[ 8, 11, 17, 21 ]' type: string jobs: @@ -105,8 +105,9 @@ jobs: uses: ./.github/actions/publish-csec-local - name: Run CSEC unit tests -# if: ${{ inputs.run-unit-test == 'true' }} + 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 index 8abe37024..b1c00a21d 100644 --- a/.github/workflows/TestSuite-PR.yml +++ b/.github/workflows/TestSuite-PR.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - java-version: [ 8, 11, 17, 21, 23 ] + java-version: [ 8, 11, 17, 21 ] steps: - name: Checkout CSEC Repo From 31526aab0d24b401045c8a36aedae59884857311 Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 26 Mar 2025 09:46:39 +0530 Subject: [PATCH 15/25] Fix unit tests failing on java 17 and above --- .../java/com/nr/agent/security/instrumentation/FileTest.java | 3 +++ .../instrumentation/netty_reactor/APIEndpointTest.java | 3 +++ .../instrumentation/netty_reactor/APIEndpointTest.java | 3 +++ .../test/java/com/nr/agent/instrumentation/solr4/SolrTest.java | 3 +++ 4 files changed, 12 insertions(+) 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/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/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; From 538927ac7c3af67fde16b0ab010b9fb9fbad06cc Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 26 Mar 2025 15:26:27 +0530 Subject: [PATCH 16/25] update gradle.properties in workflow --- .github/actions/setup-environment-inst-verifier/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-environment-inst-verifier/action.yml b/.github/actions/setup-environment-inst-verifier/action.yml index adf3eb2ea..cef000f44 100644 --- a/.github/actions/setup-environment-inst-verifier/action.yml +++ b/.github/actions/setup-environment-inst-verifier/action.yml @@ -30,7 +30,7 @@ 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|jdk21=21|jdk20=${JAVA_HOME_21_X64}| + 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 From 92ff6820fbff27cd096e58865dad0c6e01f70e4d Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 26 Mar 2025 15:32:59 +0530 Subject: [PATCH 17/25] utilised testContainers instead of postgresql-embedded dependency as UTs are failing for postgres instrumentation in mac env --- .../build.gradle | 2 +- .../postgresql80312/DataStoreTest.java | 28 ++++++----- .../postgresql80312/DriverTest.java | 25 ++++++---- .../postgresql80312/PgStatementTest.java | 26 +++++----- .../jdbc-postgresql-9.4.1207/build.gradle | 2 +- .../postgresql941207/DataStoreTest.java | 27 +++++------ .../postgresql941207/DriverTest.java | 28 +++++------ .../postgresql941207/PgStatementTest.java | 28 ++++++----- .../jdbc-postgresql-9.4.1208/build.gradle | 3 +- .../postgresql941208/DataStoreTest.java | 33 +++++-------- .../postgresql941208/DriverTest.java | 39 ++++++--------- .../r2dbc-generic/build.gradle | 2 +- .../r2dbc/PostgresStatementTest.java | 31 +++++------- .../instrumentation/r2dbc/PostgresTest.java | 39 +++++---------- .../r2dbc-postgresql/build.gradle | 2 +- .../r2dbc/postgres/ConnectionTest.java | 47 +++++++------------ 16 files changed, 163 insertions(+), 199 deletions(-) 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..cd0937186 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,6 +16,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; +import org.testcontainers.containers.PostgreSQLContainer; import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; import java.io.IOException; @@ -24,6 +25,7 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Properties; @@ -34,22 +36,25 @@ @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..da4087636 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,38 @@ 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/r2dbc-generic/build.gradle b/instrumentation-security/r2dbc-generic/build.gradle index ab6fe765d..74d93a4b7 100644 --- a/instrumentation-security/r2dbc-generic/build.gradle +++ b/instrumentation-security/r2dbc-generic/build.gradle @@ -5,7 +5,7 @@ dependencies { implementation("io.r2dbc:r2dbc-h2:0.8.4.RELEASE") testImplementation("com.h2database:h2:1.4.200") testImplementation("ch.vorburger.mariaDB4j:mariaDB4j:2.2.1") - 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 From e392df231530285eac649b63de02c1fff5d98c3f Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 26 Mar 2025 16:42:56 +0530 Subject: [PATCH 18/25] update imports --- .../security/instrumentation/postgresql80312/DriverTest.java | 3 --- .../instrumentation/postgresql80312/PgStatementTest.java | 1 - 2 files changed, 4 deletions(-) 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 cd0937186..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 @@ -17,7 +17,6 @@ import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.testcontainers.containers.PostgreSQLContainer; -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; import java.io.IOException; import java.net.ServerSocket; @@ -29,9 +28,7 @@ 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) 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 da4087636..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 @@ -35,7 +35,6 @@ import java.util.List; import java.util.Map; -@Category({ Java12IncompatibleTest.class }) @RunWith(SecurityInstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = "org.postgresql") @FixMethodOrder(MethodSorters.NAME_ASCENDING) From 4fd8bc8d4ba192381e6f0c71b5abc832527debf1 Mon Sep 17 00:00:00 2001 From: idawda Date: Thu, 27 Mar 2025 10:48:48 +0530 Subject: [PATCH 19/25] Do not send websocket message if connection is not present --- .../httpclient/IASTDataTransferRequestProcessor.java | 4 +++- .../agent/security/instrumentator/utils/AgentUtils.java | 4 +++- .../agent/security/intcodeagent/websocket/EventSender.java | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) 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 a08ba5e68..7d3ccaa02 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; From 7584c6e4f5122d9fc7723030da9adc450fa94369 Mon Sep 17 00:00:00 2001 From: idawda Date: Fri, 28 Mar 2025 13:58:21 +0530 Subject: [PATCH 20/25] remove log level info from GHA unit test run --- .github/actions/unit-test/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/unit-test/action.yml b/.github/actions/unit-test/action.yml index 8e93889b5..5dc15fe72 100644 --- a/.github/actions/unit-test/action.yml +++ b/.github/actions/unit-test/action.yml @@ -21,7 +21,7 @@ runs: continue-on-error: true if: (inputs.csec-run-scala-unittest == 'true' && inputs.java-version == '8') run: | - ./gradlew $GRADLE_OPTIONS --info test -PincludeScala --continue + ./gradlew $GRADLE_OPTIONS test -PincludeScala --continue - name: Run instrumentation unit tests on Java ${{ inputs.java-version }} attempt 1 id: run_tests_1 @@ -30,7 +30,7 @@ runs: if: ( steps.run_scala_unit_tests.outcome == 'skipped' || steps.run_scala_unit_tests.outcome == 'failure' ) run: | echo "Running attempt 1 with ${{ inputs.java-version }}" - ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue + ./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 @@ -39,7 +39,7 @@ runs: if: steps.run_tests_1.outcome == 'failure' run: | echo "Running attempt 2 with ${{ inputs.java-version }}" - ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue + ./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 @@ -48,7 +48,7 @@ runs: if: steps.run_tests_2.outcome == 'failure' run: | echo "Running attempt 3 with ${{ inputs.java-version }}" - ./gradlew ${GRADLE_OPTIONS} --info test -Ptest${{ inputs.java-version }} --continue + ./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 From 163f4d46e9de5c03742f9e483ca3659ffe9bf869 Mon Sep 17 00:00:00 2001 From: idawda Date: Thu, 17 Apr 2025 10:49:51 +0530 Subject: [PATCH 21/25] Updating workflow runner image to ubuntu-24.04 --- .github/workflows/TestSuite-PR.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/TestSuite-PR.yml b/.github/workflows/TestSuite-PR.yml index b1c00a21d..130683934 100644 --- a/.github/workflows/TestSuite-PR.yml +++ b/.github/workflows/TestSuite-PR.yml @@ -11,7 +11,7 @@ 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-20.04 + runs-on: ubuntu-24.04 strategy: matrix: java-version: [ 8, 11, 17, 21 ] From e445140f10561cf90103a706e8bed994440ccc63 Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 30 Apr 2025 15:06:00 +0530 Subject: [PATCH 22/25] disable DOCKER_DEFAULT_PLATFORM flag for mysql unit tests --- .../instrumentation/jdbc/mysql602/MySql602DataStoreTest.java | 2 +- .../instrumentation/jdbc/mysql602/MySql602DriverTest.java | 2 +- .../security/instrumentation/jdbc/mysql602/MySql602Test.java | 2 +- .../instrumentation/jdbc/mysql604/MySql604DataStoreTest.java | 2 +- .../instrumentation/jdbc/mysql604/MySql604DriverTest.java | 2 +- .../security/instrumentation/jdbc/mysql604/MySql604Test.java | 2 +- .../jdbc/mysqlconnection514/MySqlConnection514Test.java | 2 +- .../jdbc/mysqlconnection602/MySqlConnection602Test.java | 2 +- .../jdbc/mysql/multihost/MysqlMultiHost513Test.java | 2 +- .../jdbc/mysql/multihost/MysqlMultiHost602Test.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java index 0966a837b..73ae18bbf 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java @@ -42,7 +42,7 @@ public class MySql602DataStoreTest { @BeforeClass public static void setUpDb() { - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCommand("--default-authentication-plugin=mysql_native_password") .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); diff --git a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java index 2010c52de..7a412b09a 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java @@ -47,7 +47,7 @@ public class MySql602DriverTest { @BeforeClass public static void setUpDb() { PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java index bb65edb46..b5c4de75d 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java +++ b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java @@ -51,7 +51,7 @@ public static void setUpDb() throws SQLException, ClassNotFoundException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java index fd6acc76d..1ab4bc6d5 100644 --- a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java @@ -42,7 +42,7 @@ public class MySql604DataStoreTest { @BeforeClass public static void setUpDb() { - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCommand("--default-authentication-plugin=mysql_native_password") .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); diff --git a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java index 46d9871a1..ed0674113 100644 --- a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java @@ -45,7 +45,7 @@ public class MySql604DriverTest { @BeforeClass public static void setUpDb() { PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java index 12007fc62..f29e601fb 100644 --- a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java +++ b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java @@ -50,7 +50,7 @@ public static void setUpDb() throws SQLException, ClassNotFoundException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) // .withCommand("--default-authentication-plugin=mysql_native_password") .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); diff --git a/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java b/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java index 1fd57465e..f18de0fef 100644 --- a/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java +++ b/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java @@ -49,7 +49,7 @@ public static void setUpDb() throws ClassNotFoundException, SQLException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java b/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java index 5e2e6e82d..d0f6e2b07 100644 --- a/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java +++ b/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java @@ -49,7 +49,7 @@ public static void setUpDb() throws ClassNotFoundException, SQLException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java b/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java index 499e64654..d60207b43 100644 --- a/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java +++ b/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java @@ -46,7 +46,7 @@ public class MysqlMultiHost513Test { @BeforeClass public static void setUpDb() { - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.start(); diff --git a/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java b/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java index d89534db1..4e46aa5b7 100644 --- a/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java +++ b/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java @@ -46,7 +46,7 @@ public class MysqlMultiHost602Test { @BeforeClass public static void setUpDb() { - System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.start(); From 5d009c713024d0c584d0d2e95342956d13059b48 Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 30 Apr 2025 18:48:03 +0530 Subject: [PATCH 23/25] Revert "disable DOCKER_DEFAULT_PLATFORM flag for mysql unit tests" This reverts commit e445140f10561cf90103a706e8bed994440ccc63. --- .../instrumentation/jdbc/mysql602/MySql602DataStoreTest.java | 2 +- .../instrumentation/jdbc/mysql602/MySql602DriverTest.java | 2 +- .../security/instrumentation/jdbc/mysql602/MySql602Test.java | 2 +- .../instrumentation/jdbc/mysql604/MySql604DataStoreTest.java | 2 +- .../instrumentation/jdbc/mysql604/MySql604DriverTest.java | 2 +- .../security/instrumentation/jdbc/mysql604/MySql604Test.java | 2 +- .../jdbc/mysqlconnection514/MySqlConnection514Test.java | 2 +- .../jdbc/mysqlconnection602/MySqlConnection602Test.java | 2 +- .../jdbc/mysql/multihost/MysqlMultiHost513Test.java | 2 +- .../jdbc/mysql/multihost/MysqlMultiHost602Test.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java index 73ae18bbf..0966a837b 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DataStoreTest.java @@ -42,7 +42,7 @@ public class MySql602DataStoreTest { @BeforeClass public static void setUpDb() { - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCommand("--default-authentication-plugin=mysql_native_password") .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); diff --git a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java index 7a412b09a..2010c52de 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602DriverTest.java @@ -47,7 +47,7 @@ public class MySql602DriverTest { @BeforeClass public static void setUpDb() { PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java index b5c4de75d..bb65edb46 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java +++ b/instrumentation-security/jdbc-mysql-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql602/MySql602Test.java @@ -51,7 +51,7 @@ public static void setUpDb() throws SQLException, ClassNotFoundException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java index 1ab4bc6d5..fd6acc76d 100644 --- a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DataStoreTest.java @@ -42,7 +42,7 @@ public class MySql604DataStoreTest { @BeforeClass public static void setUpDb() { - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCommand("--default-authentication-plugin=mysql_native_password") .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); diff --git a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java index ed0674113..46d9871a1 100644 --- a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java +++ b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604DriverTest.java @@ -45,7 +45,7 @@ public class MySql604DriverTest { @BeforeClass public static void setUpDb() { PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java index f29e601fb..12007fc62 100644 --- a/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java +++ b/instrumentation-security/jdbc-mysql-6.0.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql604/MySql604Test.java @@ -50,7 +50,7 @@ public static void setUpDb() throws SQLException, ClassNotFoundException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) // .withCommand("--default-authentication-plugin=mysql_native_password") .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); diff --git a/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java b/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java index f18de0fef..1fd57465e 100644 --- a/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java +++ b/instrumentation-security/jdbc-mysql-connection-5.1.4/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection514/MySqlConnection514Test.java @@ -49,7 +49,7 @@ public static void setUpDb() throws ClassNotFoundException, SQLException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java b/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java index d0f6e2b07..5e2e6e82d 100644 --- a/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java +++ b/instrumentation-security/jdbc-mysql-connection-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysqlconnection602/MySqlConnection602Test.java @@ -49,7 +49,7 @@ public static void setUpDb() throws ClassNotFoundException, SQLException { QUERIES.add("select * from testQuery"); PORT = SecurityInstrumentationTestRunner.getIntrospector().getRandomPort(); - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.setPortBindings(Collections.singletonList(PORT + ":3808")); diff --git a/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java b/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java index d60207b43..499e64654 100644 --- a/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java +++ b/instrumentation-security/jdbc-mysql-multihost-connections-5.1.3/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost513Test.java @@ -46,7 +46,7 @@ public class MysqlMultiHost513Test { @BeforeClass public static void setUpDb() { - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.start(); diff --git a/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java b/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java index 4e46aa5b7..d89534db1 100644 --- a/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java +++ b/instrumentation-security/jdbc-mysql-multihost-connections-6.0.2/src/test/java/com/nr/agent/security/instrumentation/jdbc/mysql/multihost/MysqlMultiHost602Test.java @@ -46,7 +46,7 @@ public class MysqlMultiHost602Test { @BeforeClass public static void setUpDb() { - // System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); + System.setProperty("DOCKER_DEFAULT_PLATFORM", "linux/amd64"); mysql = new MySQLContainer<>(DockerImageName.parse("mysql:5.7.43")) .withCopyFileToContainer(MountableFile.forClasspathResource("maria-db-test.sql"), "/docker-entrypoint-initdb.d/"); mysql.start(); From 905fcfa25c8e2599e57771110b04b0891c2105e9 Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 30 Apr 2025 18:48:35 +0530 Subject: [PATCH 24/25] disable mysql-6.0.2 modules unit tests with java 21 --- instrumentation-security/jdbc-mysql-6.0.2/build.gradle | 7 +++++++ .../jdbc-mysql-connection-6.0.2/build.gradle | 7 +++++++ .../jdbc-mysql-multihost-connections-6.0.2/build.gradle | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/instrumentation-security/jdbc-mysql-6.0.2/build.gradle b/instrumentation-security/jdbc-mysql-6.0.2/build.gradle index b7300629e..d138ec2c9 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 greater than equal to 21 + !project.hasProperty("test21") + } +} + 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..f5cde187b 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 greater than equal to 21 + !project.hasProperty("test21") + } +} + 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..773dda561 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 greater than equal to 21 + !project.hasProperty("test21") + } +} + site { title 'MySQL' type 'Datastore' From dcbfb71cf063429a7abbbdd41b4967ef5d05e665 Mon Sep 17 00:00:00 2001 From: idawda Date: Wed, 30 Apr 2025 21:35:41 +0530 Subject: [PATCH 25/25] disable mysql-6.0.2 modules unit tests with java 8 above --- instrumentation-security/jdbc-mysql-6.0.2/build.gradle | 4 ++-- .../jdbc-mysql-connection-6.0.2/build.gradle | 4 ++-- .../jdbc-mysql-multihost-connections-6.0.2/build.gradle | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/instrumentation-security/jdbc-mysql-6.0.2/build.gradle b/instrumentation-security/jdbc-mysql-6.0.2/build.gradle index d138ec2c9..775cb6647 100644 --- a/instrumentation-security/jdbc-mysql-6.0.2/build.gradle +++ b/instrumentation-security/jdbc-mysql-6.0.2/build.gradle @@ -18,8 +18,8 @@ verifyInstrumentation { test { onlyIf { - // test is incompatible with java version greater than equal to 21 - !project.hasProperty("test21") + // test is incompatible with java version 8 above + project.hasProperty("test8") } } 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 f5cde187b..79eba107a 100644 --- a/instrumentation-security/jdbc-mysql-connection-6.0.2/build.gradle +++ b/instrumentation-security/jdbc-mysql-connection-6.0.2/build.gradle @@ -20,8 +20,8 @@ verifyInstrumentation { test { onlyIf { - // test is incompatible with java version greater than equal to 21 - !project.hasProperty("test21") + // test is incompatible with java version 8 above + project.hasProperty("test8") } } 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 773dda561..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 @@ -20,8 +20,8 @@ verifyInstrumentation { test { onlyIf { - // test is incompatible with java version greater than equal to 21 - !project.hasProperty("test21") + // test is incompatible with java version 8 above + project.hasProperty("test8") } }