diff --git a/stackrox-container-image-scanner/src/main/java/com/stackrox/jenkins/plugins/report/ReportGenerator.java b/stackrox-container-image-scanner/src/main/java/com/stackrox/jenkins/plugins/report/ReportGenerator.java index 3a84066e..8d23ccff 100644 --- a/stackrox-container-image-scanner/src/main/java/com/stackrox/jenkins/plugins/report/ReportGenerator.java +++ b/stackrox-container-image-scanner/src/main/java/com/stackrox/jenkins/plugins/report/ReportGenerator.java @@ -43,37 +43,33 @@ private static void generateReport(FilePath reportsDir, ImageCheckResults result FilePath imageResultDir = new FilePath(reportsDir, result.getImageName().replace(":", ".")); imageResultDir.mkdirs(); - if (!result.getCves().isEmpty()) { - try (OutputStream outputStream = new FilePath(imageResultDir, CVES_FILENAME).write(); - CSVPrinter printer = openCsv(outputStream, CVES_HEADER)) { - for (CVE cve : result.getCves()) { - printer.printRecord(nullIfEmpty( - cve.getPackageName(), - cve.getPackageVersion(), - cve.getId(), - cve.getSeverity(), - cve.isFixable(), - cve.getCvssScore(), - cve.getScoreType(), - cve.getLink() - )); - } + try (OutputStream outputStream = new FilePath(imageResultDir, CVES_FILENAME).write(); + CSVPrinter printer = openCsv(outputStream, CVES_HEADER)) { + for (CVE cve : result.getCves()) { + printer.printRecord(nullIfEmpty( + cve.getPackageName(), + cve.getPackageVersion(), + cve.getId(), + cve.getSeverity(), + cve.isFixable(), + cve.getCvssScore(), + cve.getScoreType(), + cve.getLink() + )); } } - if (!result.getViolatedPolicies().isEmpty()) { - try (OutputStream outputStream = new FilePath(imageResultDir, POLICY_VIOLATIONS_FILENAME).write(); - CSVPrinter printer = openCsv(outputStream, VIOLATED_POLICIES_HEADER)) { - for (PolicyViolation policy : result.getViolatedPolicies()) { - printer.printRecord(nullIfEmpty( - policy.getName(), - policy.getSeverity(), - policy.getDescription(), - policy.getViolations(), - prettyRemediation(policy.getRemediation()), - policy.isBuildEnforced() ? "X" : "-" - )); - } + try (OutputStream outputStream = new FilePath(imageResultDir, POLICY_VIOLATIONS_FILENAME).write(); + CSVPrinter printer = openCsv(outputStream, VIOLATED_POLICIES_HEADER)) { + for (PolicyViolation policy : result.getViolatedPolicies()) { + printer.printRecord(nullIfEmpty( + policy.getName(), + policy.getSeverity(), + policy.getDescription(), + policy.getViolations(), + prettyRemediation(policy.getRemediation()), + policy.isBuildEnforced() ? "X" : "-" + )); } } } diff --git a/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/report/ReportGeneratorTest.java b/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/report/ReportGeneratorTest.java index 95cb0ead..a9b0db3d 100644 --- a/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/report/ReportGeneratorTest.java +++ b/stackrox-container-image-scanner/src/test/java/com/stackrox/jenkins/plugins/report/ReportGeneratorTest.java @@ -57,7 +57,7 @@ void testGenerateReportFroEmptyResultGeneratesNothing() throws IOException, Inte } @Test - void testGenerateReportFroEmptyCVSAndViolationsGeneratesEmptyDir() throws IOException, InterruptedException { + void testGenerateReportForEmptyCVSAndViolationsGeneratesEmptyFiles() throws IOException, InterruptedException { FilePath reportsDir = new FilePath(folder.toFile()); ImmutableList results = ImmutableList.of( @@ -66,7 +66,7 @@ void testGenerateReportFroEmptyCVSAndViolationsGeneratesEmptyDir() throws IOExce List actual = reportsDir.list().stream().map(FilePath::getName).collect(Collectors.toList()); assertEquals(ImmutableList.of("mis-spelled.lts"), actual); - assertTrue(reportsDir.child("mis-spelled.lts").list().isEmpty()); + assertDirsAreEqual(Paths.get("src", "test", "resources", "report_with_no_issues"), folder); } @Test diff --git a/stackrox-container-image-scanner/src/test/resources/report_with_no_issues/mis-spelled.lts/cves.csv b/stackrox-container-image-scanner/src/test/resources/report_with_no_issues/mis-spelled.lts/cves.csv new file mode 100644 index 00000000..3840847c --- /dev/null +++ b/stackrox-container-image-scanner/src/test/resources/report_with_no_issues/mis-spelled.lts/cves.csv @@ -0,0 +1 @@ +COMPONENT,VERSION,CVE,FIXABLE,SEVERITY,CVSS SCORE,SCORE TYPE,LINK diff --git a/stackrox-container-image-scanner/src/test/resources/report_with_no_issues/mis-spelled.lts/policyViolations.csv b/stackrox-container-image-scanner/src/test/resources/report_with_no_issues/mis-spelled.lts/policyViolations.csv new file mode 100644 index 00000000..1fc1c4aa --- /dev/null +++ b/stackrox-container-image-scanner/src/test/resources/report_with_no_issues/mis-spelled.lts/policyViolations.csv @@ -0,0 +1 @@ +POLICY,SEVERITY,DESCRIPTION,VIOLATION,REMEDIATION,ENFORCED