Skip to content

Commit 4804ad2

Browse files
committed
automation: Handle FP alerts in Exit Status
- CHANGELOG > Add fix note. - ExitStatusJob > Exclude FP alerts when looping to establish exit code. - ExitStatusJobUnitTest > Add test to assert the behavior. Signed-off-by: kingthorin <[email protected]>
1 parent 0fe1c7f commit 4804ad2

File tree

3 files changed

+64
-15
lines changed

3 files changed

+64
-15
lines changed

addOns/automation/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
- Allow to use variables for the TOTP data.
99
- Allow to enable diagnostics for Client Script and Browser Based Authentication methods.
1010

11+
### Fixed
12+
- Ensure that the Exit Status job accounts for False Positive alerts (Issue 8875).
13+
1114
## [0.47.0] - 2025-02-12
1215
### Added
1316
- Method to get the YAML representation of a plan.

addOns/automation/src/main/java/org/zaproxy/addon/automation/jobs/ExitStatusJob.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public void runJob(AutomationEnvironment env, AutomationProgress progress) {
8080

8181
try {
8282
for (JobResultData data : progress.getAllJobResultData()) {
83-
for (Alert alert : data.getAllAlertData()) {
83+
for (Alert alert :
84+
data.getAllAlertData().stream()
85+
.filter(a -> a.getConfidence() != Alert.CONFIDENCE_FALSE_POSITIVE)
86+
.toList()) {
8487
if (errorRisk != null && errorRisk <= alert.getRisk()) {
8588
progress.error(
8689
Constant.messages.getString(

addOns/automation/src/test/java/org/zaproxy/addon/automation/jobs/ExitStatusJobUnitTest.java

+57-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.hamcrest.Matchers.is;
2525
import static org.hamcrest.Matchers.nullValue;
2626

27+
import java.util.ArrayList;
2728
import java.util.Arrays;
2829
import java.util.Collection;
2930
import java.util.LinkedHashMap;
@@ -348,22 +349,64 @@ void shouldSetExitCode(String alertrisk, String exitcode) {
348349
assertThat(ExtensionAutomation.getExitOverride(), is(equalTo(Integer.parseInt(exitcode))));
349350
}
350351

351-
private JobResultData getTestData(String alertLevel) {
352-
Alert alert = new Alert(-1, JobUtils.parseAlertRisk(alertLevel), 2, "test");
352+
@ParameterizedTest
353+
@CsvSource({
354+
"HIGH,MEDIUM,4",
355+
"medium,medium,3",
356+
"low,medium,2",
357+
"High,False Positive,0",
358+
"Medium,False Positive,0",
359+
"Low,False Positive,0"
360+
})
361+
void shouldSetExitCodeExcludingFalsePositive(
362+
String alertrisk, String confidence, String exitcode) {
363+
// Given
364+
ExitStatusJob job = new ExitStatusJob();
365+
AutomationProgress progress = new AutomationProgress();
366+
progress.addJobResultData(getTestData(alertrisk, confidence));
367+
368+
// When
369+
job.getParameters().setOkExitValue(Integer.parseInt(exitcode) > 0 ? 2 : 0);
370+
job.getParameters().setWarnExitValue(3);
371+
job.getParameters().setErrorExitValue(4);
372+
job.getParameters().setErrorLevel("high");
373+
job.getParameters().setWarnLevel("medium");
374+
job.verifyParameters(progress);
375+
job.runJob(new AutomationEnvironment(progress), progress);
353376

354-
JobResultData data =
355-
new JobResultData("test") {
377+
// Then
378+
Collection<JobResultData> data = progress.getAllJobResultData();
379+
Collection<Alert> alerts = new ArrayList<>();
380+
data.forEach(e -> alerts.addAll(e.getAllAlertData()));
381+
assertThat(alerts.size(), is(equalTo(1)));
382+
Alert alert = (Alert) ((ArrayList<?>) alerts).get(0);
383+
assertThat(alert.getConfidence(), is(equalTo(JobUtils.parseAlertConfidence(confidence))));
384+
assertThat(ExtensionAutomation.getExitOverride(), is(equalTo(Integer.parseInt(exitcode))));
385+
}
356386

357-
@Override
358-
public String getKey() {
359-
return "test";
360-
}
387+
private static JobResultData getTestData(String alertLevel) {
388+
return getTestData(alertLevel, "2");
389+
}
361390

362-
@Override
363-
public Collection<Alert> getAllAlertData() {
364-
return Arrays.asList(alert);
365-
}
366-
};
367-
return data;
391+
private static JobResultData getTestData(String alertLevel, String confidence) {
392+
Alert alert =
393+
new Alert(
394+
-1,
395+
JobUtils.parseAlertRisk(alertLevel),
396+
JobUtils.parseAlertConfidence(confidence),
397+
"test");
398+
399+
return new JobResultData("test") {
400+
401+
@Override
402+
public String getKey() {
403+
return "test";
404+
}
405+
406+
@Override
407+
public Collection<Alert> getAllAlertData() {
408+
return Arrays.asList(alert);
409+
}
410+
};
368411
}
369412
}

0 commit comments

Comments
 (0)