Skip to content

Commit 1adc1f4

Browse files
Add ignoredFilePath parameter to ScanAsca realtime
1 parent 47a117a commit 1adc1f4

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public List<Project> projectList(String filter) throws IOException, InterruptedE
248248
return Execution.executeCommand(withConfigArguments(arguments), logger, Project::listFromLine);
249249
}
250250

251-
public ScanResult ScanAsca(String fileSource, boolean ascaLatestVersion, String agent) throws IOException, InterruptedException, CxException {
251+
public ScanResult ScanAsca(String fileSource, boolean ascaLatestVersion, String agent, String ignoredFilePath) throws IOException, InterruptedException, CxException {
252252
this.logger.info("Fetching ASCA scanResult");
253253

254254
List<String> arguments = new ArrayList<>();
@@ -259,6 +259,10 @@ public ScanResult ScanAsca(String fileSource, boolean ascaLatestVersion, String
259259
if (ascaLatestVersion) {
260260
arguments.add(CxConstants.ASCA_LATEST_VERSION);
261261
}
262+
if (StringUtils.isNotBlank(ignoredFilePath)) {
263+
arguments.add(CxConstants.IGNORED_FILE_PATH);
264+
arguments.add(ignoredFilePath);
265+
}
262266

263267
appendAgentToArguments(agent, arguments);
264268

src/test/java/com/checkmarx/ast/ScanTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void testScanShow() throws Exception {
2525

2626
@Test
2727
void testScanAsca_WhenFileWithVulnerabilitiesIsSentWithAgent_ReturnSuccessfulResponseWithCorrectValues() throws Exception {
28-
ScanResult scanResult = wrapper.ScanAsca("src/test/resources/python-vul-file.py", true, "vscode");
28+
ScanResult scanResult = wrapper.ScanAsca("src/test/resources/python-vul-file.py", true, "vscode", null);
2929

3030
// Assertions for the scan result
3131
Assertions.assertNotNull(scanResult.getRequestId(), "Request ID should not be null");
@@ -46,7 +46,7 @@ void testScanAsca_WhenFileWithVulnerabilitiesIsSentWithAgent_ReturnSuccessfulRes
4646

4747
@Test
4848
void testScanAsca_WhenFileWithoutVulnerabilitiesIsSent_ReturnSuccessfulResponseWithCorrectValues() throws Exception {
49-
ScanResult scanResult = wrapper.ScanAsca("src/test/resources/csharp-no-vul.cs", true, null);
49+
ScanResult scanResult = wrapper.ScanAsca("src/test/resources/csharp-no-vul.cs", true, null, null);
5050
Assertions.assertNotNull(scanResult.getRequestId());
5151
Assertions.assertTrue(scanResult.isStatus());
5252
Assertions.assertNull(scanResult.getError());
@@ -55,12 +55,25 @@ void testScanAsca_WhenFileWithoutVulnerabilitiesIsSent_ReturnSuccessfulResponseW
5555

5656
@Test
5757
void testScanAsca_WhenMissingFileExtension_ReturnFileExtensionIsRequiredFailure() throws Exception {
58-
ScanResult scanResult = wrapper.ScanAsca("CODEOWNERS", true, null);
58+
ScanResult scanResult = wrapper.ScanAsca("CODEOWNERS", true, null, null);
5959
Assertions.assertNotNull(scanResult.getRequestId());
6060
Assertions.assertNotNull(scanResult.getError());
6161
Assertions.assertEquals("The file name must have an extension.", scanResult.getError().getDescription());
6262
}
6363

64+
@Test
65+
void testScanAsca_WithIgnoreFilePath_ShouldWorkCorrectly() throws Exception {
66+
String ignoreFile = "src/test/resources/ignored-packages.json";
67+
68+
// Test with ignore file - should not break the scanning process
69+
ScanResult scanResult = wrapper.ScanAsca("src/test/resources/python-vul-file.py", true, "test-agent", ignoreFile);
70+
71+
// Verify the scan completes successfully
72+
Assertions.assertNotNull(scanResult.getRequestId(), "Request ID should not be null");
73+
Assertions.assertTrue(scanResult.isStatus(), "Status should be true");
74+
Assertions.assertNull(scanResult.getError(), "Error should be null when scan is successful");
75+
}
76+
6477
@Test
6578
void testScanList() throws Exception {
6679
List<Scan> cxOutput = wrapper.scanList("limit=10");

src/test/java/com/checkmarx/ast/TelemetryTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ void testTelemetryAIEventSuccessfulCaseWithMinimalParametersAiLog() throws CxExc
1616
// Test case: AI logging with specific parameters and some empty values
1717
Assertions.assertDoesNotThrow(() -> {
1818
String result = wrapper.telemetryAIEvent(
19-
"Cursor", // aiProvider
20-
"Cursos", // agent
19+
"Copilot", // aiProvider
20+
"JetBrains IntelliJ IDEA", // agent
2121
"click", // eventType
22-
"ast-results.viewPackageDetails", // subType
22+
"viewDetails", // subType
2323
"secrets", // engine
2424
"high", // problemSeverity
2525
"", // scanType (empty)
@@ -34,7 +34,7 @@ void testTelemetryAIEventSuccessfulCaseWithMinimalParametersDetectionLog() throw
3434
// Test case: Detection logging with most parameters empty and specific scan data
3535
Assertions.assertDoesNotThrow(() -> {
3636
String result = wrapper.telemetryAIEvent(
37-
"", // aiProvider (empty)
37+
"", // aiProvider (empty)
3838
"", // agent (empty)
3939
"", // eventType (empty)
4040
"", // subType (empty)
@@ -52,7 +52,7 @@ void testTelemetryAIEventSuccessfulCaseWithEdgeCaseParameters() throws CxExcepti
5252
// Test case: Edge case with minimal required parameters
5353
Assertions.assertDoesNotThrow(() -> {
5454
String result = wrapper.telemetryAIEvent(
55-
"test-provider", // aiProvider (minimal value)
55+
"test-provider", // aiProvider (minimal value)
5656
"java-wrapper", // agent (minimal value)
5757
"", // eventType (empty)
5858
"", // subType (empty)
@@ -64,4 +64,4 @@ void testTelemetryAIEventSuccessfulCaseWithEdgeCaseParameters() throws CxExcepti
6464
);
6565
}, "Telemetry AI event should execute successfully for edge case");
6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)