From 9757416c862e584a659d8eb66e0e63e151517564 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Mon, 27 Jan 2025 15:24:16 +0200 Subject: [PATCH 01/16] test --- src/test/java/com/checkmarx/ast/AuthTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/checkmarx/ast/AuthTest.java b/src/test/java/com/checkmarx/ast/AuthTest.java index d5a12554..d48ee8d8 100644 --- a/src/test/java/com/checkmarx/ast/AuthTest.java +++ b/src/test/java/com/checkmarx/ast/AuthTest.java @@ -16,7 +16,7 @@ class AuthTest extends BaseTest { void testAuthValidate() throws CxException, IOException, InterruptedException { Assertions.assertNotNull(wrapper.authValidate()); } - +// @Test void testAuthFailure() { CxConfig cxConfig = getConfig(); From ad00f0d8c1979cde3ae0327d34fa803d678eb0a4 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Mon, 27 Jan 2025 15:40:08 +0200 Subject: [PATCH 02/16] put kics real time in comment --- .../com/checkmarx/ast/RemediationTest.java | 26 +++++++++---------- src/test/java/com/checkmarx/ast/ScanTest.java | 10 +++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/checkmarx/ast/RemediationTest.java b/src/test/java/com/checkmarx/ast/RemediationTest.java index d8a1a407..52e24f92 100644 --- a/src/test/java/com/checkmarx/ast/RemediationTest.java +++ b/src/test/java/com/checkmarx/ast/RemediationTest.java @@ -14,18 +14,18 @@ class RemediationTest extends BaseTest { private static String QUERY_ID = "9574288c118e8c87eea31b6f0b011295a39ec5e70d83fb70e839b8db4a99eba8"; private static String ENGINE = "docker"; - @Test - void testKicsRemediation() throws Exception { - KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,"",""); - Assertions.assertTrue(remediation.getAppliedRemediation() != ""); - Assertions.assertTrue(remediation.getAvailableRemediation() != ""); - } - - @Test - void testKicsRemediationSimilarityFilter() throws Exception { - KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,ENGINE,QUERY_ID); - Assertions.assertTrue(remediation.getAppliedRemediation() != ""); - Assertions.assertTrue(remediation.getAvailableRemediation() != ""); - } +// @Test +// void testKicsRemediation() throws Exception { +// KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,"",""); +// Assertions.assertTrue(remediation.getAppliedRemediation() != ""); +// Assertions.assertTrue(remediation.getAvailableRemediation() != ""); +// } +// +// @Test +// void testKicsRemediationSimilarityFilter() throws Exception { +// KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,ENGINE,QUERY_ID); +// Assertions.assertTrue(remediation.getAppliedRemediation() != ""); +// Assertions.assertTrue(remediation.getAvailableRemediation() != ""); +// } } diff --git a/src/test/java/com/checkmarx/ast/ScanTest.java b/src/test/java/com/checkmarx/ast/ScanTest.java index 42f20027..9504f69a 100644 --- a/src/test/java/com/checkmarx/ast/ScanTest.java +++ b/src/test/java/com/checkmarx/ast/ScanTest.java @@ -79,10 +79,10 @@ void testScanCancel() throws Exception { Assertions.assertDoesNotThrow(() -> wrapper.scanCancel(scan.getId())); } - @Test - void testKicsRealtimeScan() throws Exception { - KicsRealtimeResults scan = wrapper.kicsRealtimeScan("target/test-classes/Dockerfile","","v"); - Assertions.assertTrue(scan.getResults().size() >= 1); - } +// @Test +//// void testKicsRealtimeScan() throws Exception { +//// KicsRealtimeResults scan = wrapper.kicsRealtimeScan("target/test-classes/Dockerfile","","v"); +//// Assertions.assertTrue(scan.getResults().size() >= 1); +//// } } From 48b4c08961c807e4e89bf80ecbb2a8a2b8908d88 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Mon, 27 Jan 2025 15:57:54 +0200 Subject: [PATCH 03/16] add test --- .../com/checkmarx/ast/ScanResultTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/com/checkmarx/ast/ScanResultTest.java diff --git a/src/test/java/com/checkmarx/ast/ScanResultTest.java b/src/test/java/com/checkmarx/ast/ScanResultTest.java new file mode 100644 index 00000000..980f2810 --- /dev/null +++ b/src/test/java/com/checkmarx/ast/ScanResultTest.java @@ -0,0 +1,49 @@ +package com.checkmarx.ast; + +import com.checkmarx.ast.asca.ScanDetail; +import com.checkmarx.ast.asca.ScanResult; +import com.checkmarx.ast.asca.Error; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +class ScanResultTest extends BaseTest { + + @Test + void testScanAsca_WhenFileWithVulnerabilitiesIsSentWithAgent_ReturnSuccessfulResponseWithCorrectValues() throws Exception { + ScanResult scanResult = wrapper.ScanAsca("src/test/resources/python-vul-file.py", true, "vscode"); + + // Assertions for the scan result + Assertions.assertNotNull(scanResult.getRequestId(), "Request ID should not be null"); + Assertions.assertTrue(scanResult.isStatus(), "Status should be true"); + Assertions.assertNull(scanResult.getError(), "Error should be null"); + + // Ensure scan details are not null and contain at least one entry + Assertions.assertNotNull(scanResult.getScanDetails(), "Scan details should not be null"); + Assertions.assertFalse(scanResult.getScanDetails().isEmpty(), "Scan details should contain at least one entry"); + + // Iterate over all scan details and validate each one + for (ScanDetail scanDetail : scanResult.getScanDetails()) { + Assertions.assertNotNull(scanDetail.getRemediationAdvise(), "Remediation advise should not be null"); + Assertions.assertNotNull(scanDetail.getDescription(), "Description should not be null"); + } + } + + @Test + void testScanAsca_WhenFileWithoutVulnerabilitiesIsSent_ReturnSuccessfulResponseWithCorrectValues() throws Exception { + ScanResult scanResult = wrapper.ScanAsca("src/test/resources/csharp-no-vul.cs", true, null); + Assertions.assertNotNull(scanResult.getRequestId()); + Assertions.assertTrue(scanResult.isStatus()); + Assertions.assertNull(scanResult.getError()); + Assertions.assertNull(scanResult.getScanDetails()); // When no vulnerabilities are found, scan details is null + } + + @Test + void testScanAsca_WhenMissingFileExtension_ReturnFileExtensionIsRequiredFailure() throws Exception { + ScanResult scanResult = wrapper.ScanAsca("CODEOWNERS", true, null); + Assertions.assertNotNull(scanResult.getRequestId()); + Assertions.assertNotNull(scanResult.getError()); + Assertions.assertEquals("The file name must have an extension.", scanResult.getError().getDescription()); + } +} From 36b8cb289fb6df48383baa65aebd843927a05d00 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Mon, 27 Jan 2025 17:02:41 +0200 Subject: [PATCH 04/16] add test --- .../ast/BuildResultsArgumentsTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java diff --git a/src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java b/src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java new file mode 100644 index 00000000..1b906e8a --- /dev/null +++ b/src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java @@ -0,0 +1,24 @@ +package com.checkmarx.ast; + +import com.checkmarx.ast.results.ReportFormat; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.UUID; + +class BuildResultsArgumentsTest extends BaseTest { + + @Test + void testBuildResultsArguments_CreatesValidArguments() { + UUID scanId = UUID.randomUUID(); + ReportFormat format = ReportFormat.json; + + List arguments = wrapper.buildResultsArguments(scanId, format); + + Assertions.assertNotNull(arguments, "Arguments list should not be null"); + Assertions.assertFalse(arguments.isEmpty(), "Arguments list should not be empty"); + Assertions.assertTrue(arguments.contains(scanId.toString()), "Arguments should contain scan ID"); + Assertions.assertTrue(arguments.contains(format.toString()), "Arguments should contain the report format"); + } +} From 764edee6b937381e4e4e681039b79b0f73ba9e77 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 13:16:08 +0200 Subject: [PATCH 05/16] add badge and remove comment from kics --- .github/workflows/ci.yml | 5 ++++ pom.xml | 21 ++++++++++++--- .../com/checkmarx/ast/RemediationTest.java | 26 +++++++++---------- src/test/java/com/checkmarx/ast/ScanTest.java | 10 +++---- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fed1f695..75a751a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,6 +76,11 @@ jobs: COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc) echo "Total coverage percentage: $COVERAGE_PERCENTAGE%" + - name: Generate JaCoCo Badge + uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921 #v2.11.0 + with: + jacoco-csv-file: target/site/jacoco/jacoco.csv + - name: Upload JaCoCo coverage report uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4 with: diff --git a/pom.xml b/pom.xml index dafdd068..3802b3a0 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,7 @@ 0.8.8 + prepare-agent prepare-agent @@ -78,14 +79,26 @@ report - - **/src/main/java/** - - + + **/com/checkmarx/ast/results/** + **/com/checkmarx/ast/results/result/** + **/com/checkmarx/ast/kicsRealtimeResults/** + **/com/checkmarx/ast/kicsRealtimeResults/ast/kicsRealtimeResult/** + **/com/checkmarx/ast/asca/** + **/com/checkmarx/ast/learnMore/** + **/com/checkmarx/ast/predicate/** + **/com/checkmarx/ast/scan/** + **/com/checkmarx/ast/codebashing/** + **/com/checkmarx/ast/remediation/** + **/com/checkmarx/ast/project/** + **/com/checkmarx/ast/tenant/** + **/com/checkmarx/ast/wrapper/Execution** + + com.github.spotbugs spotbugs-maven-plugin diff --git a/src/test/java/com/checkmarx/ast/RemediationTest.java b/src/test/java/com/checkmarx/ast/RemediationTest.java index 52e24f92..d8a1a407 100644 --- a/src/test/java/com/checkmarx/ast/RemediationTest.java +++ b/src/test/java/com/checkmarx/ast/RemediationTest.java @@ -14,18 +14,18 @@ class RemediationTest extends BaseTest { private static String QUERY_ID = "9574288c118e8c87eea31b6f0b011295a39ec5e70d83fb70e839b8db4a99eba8"; private static String ENGINE = "docker"; -// @Test -// void testKicsRemediation() throws Exception { -// KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,"",""); -// Assertions.assertTrue(remediation.getAppliedRemediation() != ""); -// Assertions.assertTrue(remediation.getAvailableRemediation() != ""); -// } -// -// @Test -// void testKicsRemediationSimilarityFilter() throws Exception { -// KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,ENGINE,QUERY_ID); -// Assertions.assertTrue(remediation.getAppliedRemediation() != ""); -// Assertions.assertTrue(remediation.getAvailableRemediation() != ""); -// } + @Test + void testKicsRemediation() throws Exception { + KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,"",""); + Assertions.assertTrue(remediation.getAppliedRemediation() != ""); + Assertions.assertTrue(remediation.getAvailableRemediation() != ""); + } + + @Test + void testKicsRemediationSimilarityFilter() throws Exception { + KicsRemediation remediation = wrapper.kicsRemediate(RESULTS_FILE,KICS_FILE,ENGINE,QUERY_ID); + Assertions.assertTrue(remediation.getAppliedRemediation() != ""); + Assertions.assertTrue(remediation.getAvailableRemediation() != ""); + } } diff --git a/src/test/java/com/checkmarx/ast/ScanTest.java b/src/test/java/com/checkmarx/ast/ScanTest.java index 9504f69a..42f20027 100644 --- a/src/test/java/com/checkmarx/ast/ScanTest.java +++ b/src/test/java/com/checkmarx/ast/ScanTest.java @@ -79,10 +79,10 @@ void testScanCancel() throws Exception { Assertions.assertDoesNotThrow(() -> wrapper.scanCancel(scan.getId())); } -// @Test -//// void testKicsRealtimeScan() throws Exception { -//// KicsRealtimeResults scan = wrapper.kicsRealtimeScan("target/test-classes/Dockerfile","","v"); -//// Assertions.assertTrue(scan.getResults().size() >= 1); -//// } + @Test + void testKicsRealtimeScan() throws Exception { + KicsRealtimeResults scan = wrapper.kicsRealtimeScan("target/test-classes/Dockerfile","","v"); + Assertions.assertTrue(scan.getResults().size() >= 1); + } } From 8c8da621f2400555eb307ed9da8d970829d0e8b1 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 13:45:58 +0200 Subject: [PATCH 06/16] fix pom file --- pom.xml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 3802b3a0..3b5e8a65 100644 --- a/pom.xml +++ b/pom.xml @@ -80,20 +80,19 @@ - **/com/checkmarx/ast/results/** - **/com/checkmarx/ast/results/result/** - **/com/checkmarx/ast/kicsRealtimeResults/** - **/com/checkmarx/ast/kicsRealtimeResults/ast/kicsRealtimeResult/** - **/com/checkmarx/ast/asca/** - **/com/checkmarx/ast/learnMore/** - **/com/checkmarx/ast/predicate/** - **/com/checkmarx/ast/scan/** - **/com/checkmarx/ast/codebashing/** - **/com/checkmarx/ast/remediation/** - **/com/checkmarx/ast/project/** - **/com/checkmarx/ast/tenant/** - **/com/checkmarx/ast/wrapper/Execution** + **/com/checkmarx/ast/results/**/*.class + **/com/checkmarx/ast/kicsRealtimeResults/**/*.class + **/com/checkmarx/ast/asca/**/*.class + **/com/checkmarx/ast/learnMore/**/*.class + **/com/checkmarx/ast/predicate/**/*.class + **/com/checkmarx/ast/scan/**/*.class + **/com/checkmarx/ast/codebashing/**/*.class + **/com/checkmarx/ast/remediation/**/*.class + **/com/checkmarx/ast/project/**/*.class + **/com/checkmarx/ast/tenant/**/*.class + **/com/checkmarx/ast/wrapper/Execution**/*.class + From 59bf952b1a4bed111e290a51e02de12dab083c8a Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 14:04:33 +0200 Subject: [PATCH 07/16] fix pr --- .github/workflows/ci.yml | 23 ++++++++++++++++++----- pom.xml | 25 ++++++++++++++----------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75a751a3..099fbb02 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,13 +68,26 @@ jobs: CX_TENANT: ${{ secrets.CX_TENANT }} CX_APIKEY: ${{ secrets.CX_APIKEY }} - - name: Print total coverage percentage + - name: Print filtered coverage percentage run: | - COVERED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) - MISSED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) + COVERED_LINES=$(xmllint --xpath "sum(//report/package[not(matches(@name, 'com.checkmarx.ast.(results|kicsRealtimeResults|asca|learnMore|predicate|scan|codebashing|remediation|project|tenant)'))]/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) + MISSED_LINES=$(xmllint --xpath "sum(//report/package[not(matches(@name, 'com.checkmarx.ast.(results|kicsRealtimeResults|asca|learnMore|predicate|scan|codebashing|remediation|project|tenant)'))]/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) + + if [ -z "$COVERED_LINES" ] || [ -z "$MISSED_LINES" ]; then + echo "Error: Could not extract coverage data from jacoco.xml" + exit 1 + fi + TOTAL_LINES=$((COVERED_LINES + MISSED_LINES)) - COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc) - echo "Total coverage percentage: $COVERAGE_PERCENTAGE%" + + if [ "$TOTAL_LINES" -eq 0 ]; then + COVERAGE_PERCENTAGE=0 + else + COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc) + fi + + echo "Filtered coverage percentage: $COVERAGE_PERCENTAGE%" + - name: Generate JaCoCo Badge uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921 #v2.11.0 diff --git a/pom.xml b/pom.xml index 3b5e8a65..7ab2f9ab 100644 --- a/pom.xml +++ b/pom.xml @@ -80,19 +80,22 @@ - **/com/checkmarx/ast/results/**/*.class - **/com/checkmarx/ast/kicsRealtimeResults/**/*.class - **/com/checkmarx/ast/asca/**/*.class - **/com/checkmarx/ast/learnMore/**/*.class - **/com/checkmarx/ast/predicate/**/*.class - **/com/checkmarx/ast/scan/**/*.class - **/com/checkmarx/ast/codebashing/**/*.class - **/com/checkmarx/ast/remediation/**/*.class - **/com/checkmarx/ast/project/**/*.class - **/com/checkmarx/ast/tenant/**/*.class - **/com/checkmarx/ast/wrapper/Execution**/*.class + com/checkmarx/ast/results/** + com/checkmarx/ast/results/result/** + com/checkmarx/ast/kicsRealtimeResults/** + com/checkmarx/ast/kicsRealtimeResults/ast/kicsRealtimeResult/** + com/checkmarx/ast/asca/** + com/checkmarx/ast/learnMore/** + com/checkmarx/ast/predicate/** + com/checkmarx/ast/scan/** + com/checkmarx/ast/codebashing/** + com/checkmarx/ast/remediation/** + com/checkmarx/ast/project/** + com/checkmarx/ast/tenant/** + com/checkmarx/ast/wrapper/Execution** + From 4ac3d6a7fb718da6335c6ca647fd0373dcea017b Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 14:05:22 +0200 Subject: [PATCH 08/16] fix pr --- .../com/checkmarx/ast/ScanResultTest.java | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 src/test/java/com/checkmarx/ast/ScanResultTest.java diff --git a/src/test/java/com/checkmarx/ast/ScanResultTest.java b/src/test/java/com/checkmarx/ast/ScanResultTest.java deleted file mode 100644 index 980f2810..00000000 --- a/src/test/java/com/checkmarx/ast/ScanResultTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.checkmarx.ast; - -import com.checkmarx.ast.asca.ScanDetail; -import com.checkmarx.ast.asca.ScanResult; -import com.checkmarx.ast.asca.Error; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; - -class ScanResultTest extends BaseTest { - - @Test - void testScanAsca_WhenFileWithVulnerabilitiesIsSentWithAgent_ReturnSuccessfulResponseWithCorrectValues() throws Exception { - ScanResult scanResult = wrapper.ScanAsca("src/test/resources/python-vul-file.py", true, "vscode"); - - // Assertions for the scan result - Assertions.assertNotNull(scanResult.getRequestId(), "Request ID should not be null"); - Assertions.assertTrue(scanResult.isStatus(), "Status should be true"); - Assertions.assertNull(scanResult.getError(), "Error should be null"); - - // Ensure scan details are not null and contain at least one entry - Assertions.assertNotNull(scanResult.getScanDetails(), "Scan details should not be null"); - Assertions.assertFalse(scanResult.getScanDetails().isEmpty(), "Scan details should contain at least one entry"); - - // Iterate over all scan details and validate each one - for (ScanDetail scanDetail : scanResult.getScanDetails()) { - Assertions.assertNotNull(scanDetail.getRemediationAdvise(), "Remediation advise should not be null"); - Assertions.assertNotNull(scanDetail.getDescription(), "Description should not be null"); - } - } - - @Test - void testScanAsca_WhenFileWithoutVulnerabilitiesIsSent_ReturnSuccessfulResponseWithCorrectValues() throws Exception { - ScanResult scanResult = wrapper.ScanAsca("src/test/resources/csharp-no-vul.cs", true, null); - Assertions.assertNotNull(scanResult.getRequestId()); - Assertions.assertTrue(scanResult.isStatus()); - Assertions.assertNull(scanResult.getError()); - Assertions.assertNull(scanResult.getScanDetails()); // When no vulnerabilities are found, scan details is null - } - - @Test - void testScanAsca_WhenMissingFileExtension_ReturnFileExtensionIsRequiredFailure() throws Exception { - ScanResult scanResult = wrapper.ScanAsca("CODEOWNERS", true, null); - Assertions.assertNotNull(scanResult.getRequestId()); - Assertions.assertNotNull(scanResult.getError()); - Assertions.assertEquals("The file name must have an extension.", scanResult.getError().getDescription()); - } -} From 1fa8821e5e04f76948b12b66fd9a418ab9652812 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 14:26:07 +0200 Subject: [PATCH 09/16] fix ci file --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 099fbb02..e6ab273c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,8 +70,9 @@ jobs: - name: Print filtered coverage percentage run: | - COVERED_LINES=$(xmllint --xpath "sum(//report/package[not(matches(@name, 'com.checkmarx.ast.(results|kicsRealtimeResults|asca|learnMore|predicate|scan|codebashing|remediation|project|tenant)'))]/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) - MISSED_LINES=$(xmllint --xpath "sum(//report/package[not(matches(@name, 'com.checkmarx.ast.(results|kicsRealtimeResults|asca|learnMore|predicate|scan|codebashing|remediation|project|tenant)'))]/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) + COVERED_LINES=$(xmllint --xpath "sum(//report/package[not(contains(@name, 'results')) and not(contains(@name, 'kicsRealtimeResults')) and not(contains(@name, 'asca')) and not(contains(@name, 'learnMore')) and not(contains(@name, 'predicate')) and not(contains(@name, 'scan')) and not(contains(@name, 'codebashing')) and not(contains(@name, 'remediation')) and not(contains(@name, 'project')) and not(contains(@name, 'tenant'))]/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) + + MISSED_LINES=$(xmllint --xpath "sum(//report/package[not(contains(@name, 'results')) and not(contains(@name, 'kicsRealtimeResults')) and not(contains(@name, 'asca')) and not(contains(@name, 'learnMore')) and not(contains(@name, 'predicate')) and not(contains(@name, 'scan')) and not(contains(@name, 'codebashing')) and not(contains(@name, 'remediation')) and not(contains(@name, 'project')) and not(contains(@name, 'tenant'))]/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) if [ -z "$COVERED_LINES" ] || [ -z "$MISSED_LINES" ]; then echo "Error: Could not extract coverage data from jacoco.xml" @@ -88,6 +89,7 @@ jobs: echo "Filtered coverage percentage: $COVERAGE_PERCENTAGE%" + - name: Generate JaCoCo Badge uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921 #v2.11.0 From 5ca0566c92e0141064ec4a429dea79041883682d Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 16:04:58 +0200 Subject: [PATCH 10/16] fix pom and ci --- .github/workflows/ci.yml | 31 ++++++++++++++++++++++++++++--- pom.xml | 24 +++++++++++------------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6ab273c..885d2bf5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,9 +70,33 @@ jobs: - name: Print filtered coverage percentage run: | - COVERED_LINES=$(xmllint --xpath "sum(//report/package[not(contains(@name, 'results')) and not(contains(@name, 'kicsRealtimeResults')) and not(contains(@name, 'asca')) and not(contains(@name, 'learnMore')) and not(contains(@name, 'predicate')) and not(contains(@name, 'scan')) and not(contains(@name, 'codebashing')) and not(contains(@name, 'remediation')) and not(contains(@name, 'project')) and not(contains(@name, 'tenant'))]/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) - - MISSED_LINES=$(xmllint --xpath "sum(//report/package[not(contains(@name, 'results')) and not(contains(@name, 'kicsRealtimeResults')) and not(contains(@name, 'asca')) and not(contains(@name, 'learnMore')) and not(contains(@name, 'predicate')) and not(contains(@name, 'scan')) and not(contains(@name, 'codebashing')) and not(contains(@name, 'remediation')) and not(contains(@name, 'project')) and not(contains(@name, 'tenant'))]/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) + COVERED_LINES=$(xmllint --xpath "sum(//report/package[ + not(starts-with(@name, 'com.checkmarx.ast.results')) and + not(starts-with(@name, 'com.checkmarx.ast.kicsRealtimeResults')) and + not(starts-with(@name, 'com.checkmarx.ast.asca')) and + not(starts-with(@name, 'com.checkmarx.ast.learnMore')) and + not(starts-with(@name, 'com.checkmarx.ast.predicate')) and + not(starts-with(@name, 'com.checkmarx.ast.scan')) and + not(starts-with(@name, 'com.checkmarx.ast.codebashing')) and + not(starts-with(@name, 'com.checkmarx.ast.remediation')) and + not(starts-with(@name, 'com.checkmarx.ast.project')) and + not(starts-with(@name, 'com.checkmarx.ast.tenant')) and + not(starts-with(@name, 'com.checkmarx.ast.wrapper.Execution')) + ]/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) + + MISSED_LINES=$(xmllint --xpath "sum(//report/package[ + not(starts-with(@name, 'com.checkmarx.ast.results')) and + not(starts-with(@name, 'com.checkmarx.ast.kicsRealtimeResults')) and + not(starts-with(@name, 'com.checkmarx.ast.asca')) and + not(starts-with(@name, 'com.checkmarx.ast.learnMore')) and + not(starts-with(@name, 'com.checkmarx.ast.predicate')) and + not(starts-with(@name, 'com.checkmarx.ast.scan')) and + not(starts-with(@name, 'com.checkmarx.ast.codebashing')) and + not(starts-with(@name, 'com.checkmarx.ast.remediation')) and + not(starts-with(@name, 'com.checkmarx.ast.project')) and + not(starts-with(@name, 'com.checkmarx.ast.tenant')) and + not(starts-with(@name, 'com.checkmarx.ast.wrapper.Execution')) + ]/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) if [ -z "$COVERED_LINES" ] || [ -z "$MISSED_LINES" ]; then echo "Error: Could not extract coverage data from jacoco.xml" @@ -90,6 +114,7 @@ jobs: echo "Filtered coverage percentage: $COVERAGE_PERCENTAGE%" + - name: Generate JaCoCo Badge uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921 #v2.11.0 diff --git a/pom.xml b/pom.xml index 7ab2f9ab..9a8bcba8 100644 --- a/pom.xml +++ b/pom.xml @@ -80,19 +80,17 @@ - com/checkmarx/ast/results/** - com/checkmarx/ast/results/result/** - com/checkmarx/ast/kicsRealtimeResults/** - com/checkmarx/ast/kicsRealtimeResults/ast/kicsRealtimeResult/** - com/checkmarx/ast/asca/** - com/checkmarx/ast/learnMore/** - com/checkmarx/ast/predicate/** - com/checkmarx/ast/scan/** - com/checkmarx/ast/codebashing/** - com/checkmarx/ast/remediation/** - com/checkmarx/ast/project/** - com/checkmarx/ast/tenant/** - com/checkmarx/ast/wrapper/Execution** + **/com/checkmarx/ast/results/** + **/com/checkmarx/ast/kicsRealtimeResults/** + **/com/checkmarx/ast/asca/** + **/com/checkmarx/ast/learnMore/** + **/com/checkmarx/ast/predicate/** + **/com/checkmarx/ast/scan/** + **/com/checkmarx/ast/codebashing/** + **/com/checkmarx/ast/remediation/** + **/com/checkmarx/ast/project/** + **/com/checkmarx/ast/tenant/** + **/com/checkmarx/ast/wrapper/Execution** From 996b3641ce0c714565c3eb3be14449ec59dc255b Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 16:22:39 +0200 Subject: [PATCH 11/16] fix pom and ci --- .github/workflows/ci.yml | 48 +++++----------------------------------- pom.xml | 34 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 60 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 885d2bf5..74c2d7ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,50 +68,14 @@ jobs: CX_TENANT: ${{ secrets.CX_TENANT }} CX_APIKEY: ${{ secrets.CX_APIKEY }} - - name: Print filtered coverage percentage + - name: Print total coverage percentage run: | - COVERED_LINES=$(xmllint --xpath "sum(//report/package[ - not(starts-with(@name, 'com.checkmarx.ast.results')) and - not(starts-with(@name, 'com.checkmarx.ast.kicsRealtimeResults')) and - not(starts-with(@name, 'com.checkmarx.ast.asca')) and - not(starts-with(@name, 'com.checkmarx.ast.learnMore')) and - not(starts-with(@name, 'com.checkmarx.ast.predicate')) and - not(starts-with(@name, 'com.checkmarx.ast.scan')) and - not(starts-with(@name, 'com.checkmarx.ast.codebashing')) and - not(starts-with(@name, 'com.checkmarx.ast.remediation')) and - not(starts-with(@name, 'com.checkmarx.ast.project')) and - not(starts-with(@name, 'com.checkmarx.ast.tenant')) and - not(starts-with(@name, 'com.checkmarx.ast.wrapper.Execution')) - ]/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) - - MISSED_LINES=$(xmllint --xpath "sum(//report/package[ - not(starts-with(@name, 'com.checkmarx.ast.results')) and - not(starts-with(@name, 'com.checkmarx.ast.kicsRealtimeResults')) and - not(starts-with(@name, 'com.checkmarx.ast.asca')) and - not(starts-with(@name, 'com.checkmarx.ast.learnMore')) and - not(starts-with(@name, 'com.checkmarx.ast.predicate')) and - not(starts-with(@name, 'com.checkmarx.ast.scan')) and - not(starts-with(@name, 'com.checkmarx.ast.codebashing')) and - not(starts-with(@name, 'com.checkmarx.ast.remediation')) and - not(starts-with(@name, 'com.checkmarx.ast.project')) and - not(starts-with(@name, 'com.checkmarx.ast.tenant')) and - not(starts-with(@name, 'com.checkmarx.ast.wrapper.Execution')) - ]/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) - - if [ -z "$COVERED_LINES" ] || [ -z "$MISSED_LINES" ]; then - echo "Error: Could not extract coverage data from jacoco.xml" - exit 1 - fi - + COVERED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) + MISSED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) TOTAL_LINES=$((COVERED_LINES + MISSED_LINES)) - - if [ "$TOTAL_LINES" -eq 0 ]; then - COVERAGE_PERCENTAGE=0 - else - COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc) - fi - - echo "Filtered coverage percentage: $COVERAGE_PERCENTAGE%" + COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc) + echo "Total coverage percentage: $COVERAGE_PERCENTAGE%" + diff --git a/pom.xml b/pom.xml index 9a8bcba8..15aa83a9 100644 --- a/pom.xml +++ b/pom.xml @@ -65,9 +65,24 @@ org.jacoco jacoco-maven-plugin 0.8.8 + + + **/com/checkmarx/ast/results/** + **/com/checkmarx/ast/kicsRealtimeResults/** + **/com/checkmarx/ast/asca/** + **/com/checkmarx/ast/learnMore/** + **/com/checkmarx/ast/predicate/** + **/com/checkmarx/ast/scan/** + **/com/checkmarx/ast/codebashing/** + **/com/checkmarx/ast/remediation/** + **/com/checkmarx/ast/project/** + **/com/checkmarx/ast/tenant/** + **/com/checkmarx/ast/wrapper/Execution** + + + - prepare-agent prepare-agent @@ -78,23 +93,6 @@ report - - - **/com/checkmarx/ast/results/** - **/com/checkmarx/ast/kicsRealtimeResults/** - **/com/checkmarx/ast/asca/** - **/com/checkmarx/ast/learnMore/** - **/com/checkmarx/ast/predicate/** - **/com/checkmarx/ast/scan/** - **/com/checkmarx/ast/codebashing/** - **/com/checkmarx/ast/remediation/** - **/com/checkmarx/ast/project/** - **/com/checkmarx/ast/tenant/** - **/com/checkmarx/ast/wrapper/Execution** - - - - From f9699d0280e81a09737aac6b2ca3637448440708 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 17:01:15 +0200 Subject: [PATCH 12/16] fix code coverage and remove job printed --- .github/workflows/ci.yml | 12 ------------ pom.xml | 4 ++++ .../java/com/checkmarx/ast/wrapper/CxConfig.java | 5 ----- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74c2d7ef..4d6e7880 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,18 +68,6 @@ jobs: CX_TENANT: ${{ secrets.CX_TENANT }} CX_APIKEY: ${{ secrets.CX_APIKEY }} - - name: Print total coverage percentage - run: | - COVERED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml) - MISSED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml) - TOTAL_LINES=$((COVERED_LINES + MISSED_LINES)) - COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc) - echo "Total coverage percentage: $COVERAGE_PERCENTAGE%" - - - - - - name: Generate JaCoCo Badge uses: cicirello/jacoco-badge-generator@f33476a5a3fd5a4f77cb5eef2ebe728c1dd5b921 #v2.11.0 with: diff --git a/pom.xml b/pom.xml index 15aa83a9..5c4e7163 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,10 @@ **/com/checkmarx/ast/project/** **/com/checkmarx/ast/tenant/** **/com/checkmarx/ast/wrapper/Execution** + **/com/checkmarx/ast/wrapper/CxConstants** + **/com/checkmarx/ast/wrapper/CxException** + **/com/checkmarx/ast/wrapper/CxConfig** + diff --git a/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java b/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java index 5423de55..8d76e4f9 100644 --- a/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java +++ b/src/main/java/com/checkmarx/ast/wrapper/CxConfig.java @@ -63,11 +63,6 @@ List toArguments() { return commands; } - public static final class InvalidCLIConfigException extends Exception { - public InvalidCLIConfigException(String message) { - super(message); - } - } @SuppressWarnings("ALL") public static class CxConfigBuilder { From 6e91318baff68572748cf2c1cd6a4499c2363904 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 17:15:58 +0200 Subject: [PATCH 13/16] run again --- src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java b/src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java index 1b906e8a..473d2a68 100644 --- a/src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java +++ b/src/test/java/com/checkmarx/ast/BuildResultsArgumentsTest.java @@ -15,6 +15,7 @@ void testBuildResultsArguments_CreatesValidArguments() { ReportFormat format = ReportFormat.json; List arguments = wrapper.buildResultsArguments(scanId, format); + // Assertions.assertNotNull(arguments, "Arguments list should not be null"); Assertions.assertFalse(arguments.isEmpty(), "Arguments list should not be empty"); From 74eeda9aff219c00394bdc06b2594b847ac86237 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 18:13:11 +0200 Subject: [PATCH 14/16] fix pr --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 5c4e7163..c59ec803 100644 --- a/pom.xml +++ b/pom.xml @@ -77,10 +77,10 @@ **/com/checkmarx/ast/remediation/** **/com/checkmarx/ast/project/** **/com/checkmarx/ast/tenant/** - **/com/checkmarx/ast/wrapper/Execution** - **/com/checkmarx/ast/wrapper/CxConstants** - **/com/checkmarx/ast/wrapper/CxException** - **/com/checkmarx/ast/wrapper/CxConfig** + **/com/checkmarx/ast/wrapper/Execution.class + **/com/checkmarx/ast/wrapper/CxConstants.class + **/com/checkmarx/ast/wrapper/CxException.class + **/com/checkmarx/ast/wrapper/CxConfig.class From 8603659d30fe0129f63be82816c63acc99fe0b80 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 19:13:35 +0200 Subject: [PATCH 15/16] add to exclude --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index c59ec803..e4bd6d06 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,9 @@ **/com/checkmarx/ast/wrapper/CxConstants.class **/com/checkmarx/ast/wrapper/CxException.class **/com/checkmarx/ast/wrapper/CxConfig.class + **/com/checkmarx/ast/wrapper/CxBaseObject.class + **/com/checkmarx/ast/wrapper/CxConfig$*.class + From 8080a16be6205f40ade181fbed974ee5d748038f Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Tue, 28 Jan 2025 21:52:22 +0200 Subject: [PATCH 16/16] fix pr --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index e4bd6d06..787efc66 100644 --- a/pom.xml +++ b/pom.xml @@ -77,7 +77,6 @@ **/com/checkmarx/ast/remediation/** **/com/checkmarx/ast/project/** **/com/checkmarx/ast/tenant/** - **/com/checkmarx/ast/wrapper/Execution.class **/com/checkmarx/ast/wrapper/CxConstants.class **/com/checkmarx/ast/wrapper/CxException.class **/com/checkmarx/ast/wrapper/CxConfig.class