From 5de1450d316a552e7c8f5c97a1d6ec6ad6498ef8 Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Mon, 27 Jan 2025 12:22:41 +0200 Subject: [PATCH 1/2] add scan result test asca --- .../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 ac2c070a5e95e3a5bedf316d21d86cba4b6d487b Mon Sep 17 00:00:00 2001 From: Itay Paz Date: Mon, 27 Jan 2025 14:46:19 +0200 Subject: [PATCH 2/2] delte test --- .../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()); - } -}