|
24 | 24 | import static org.hamcrest.Matchers.is;
|
25 | 25 | import static org.hamcrest.Matchers.nullValue;
|
26 | 26 |
|
| 27 | +import java.util.ArrayList; |
27 | 28 | import java.util.Arrays;
|
28 | 29 | import java.util.Collection;
|
29 | 30 | import java.util.LinkedHashMap;
|
@@ -348,22 +349,64 @@ void shouldSetExitCode(String alertrisk, String exitcode) {
|
348 | 349 | assertThat(ExtensionAutomation.getExitOverride(), is(equalTo(Integer.parseInt(exitcode))));
|
349 | 350 | }
|
350 | 351 |
|
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); |
353 | 376 |
|
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 | + } |
356 | 386 |
|
357 |
| - @Override |
358 |
| - public String getKey() { |
359 |
| - return "test"; |
360 |
| - } |
| 387 | + private static JobResultData getTestData(String alertLevel) { |
| 388 | + return getTestData(alertLevel, "2"); |
| 389 | + } |
361 | 390 |
|
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 | + }; |
368 | 411 | }
|
369 | 412 | }
|
0 commit comments