diff --git a/build-info-extractor/src/test/java/org/jfrog/build/extractor/buildScanTable/BuildInfoScanTableHelperTest.java b/build-info-extractor/src/test/java/org/jfrog/build/extractor/buildScanTable/BuildInfoScanTableHelperTest.java index d65bdd3a6..5060849fa 100644 --- a/build-info-extractor/src/test/java/org/jfrog/build/extractor/buildScanTable/BuildInfoScanTableHelperTest.java +++ b/build-info-extractor/src/test/java/org/jfrog/build/extractor/buildScanTable/BuildInfoScanTableHelperTest.java @@ -12,11 +12,11 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class BuildInfoScanTableHelperTest { private static final String SCAN_RESULT_PATH = "/buildScanTable/scanResult.json"; private static final String EMPTY_RESULT_PATH = "/buildScanTable/emptyResult.json"; - private static final String INVALID_RESULT_PATH = "/buildScanTable/invalidResult.json"; private final BuildScanTableHelper tableHelper = new BuildScanTableHelper(); @Test @@ -69,10 +69,14 @@ public void testPrintTableWithNoViolations() throws IOException, URISyntaxExcept } @Test - public void testPrintTableWithInvalidType() throws IOException, URISyntaxException { + public void testPrintTableWithUnexpectedType() throws IOException, URISyntaxException { TestsAggregationLog log = new TestsAggregationLog(); - ArtifactoryXrayResponse result = getXrayInvalidResultResource(); - Assert.assertThrows(IllegalArgumentException.class, () -> tableHelper.printTable(result, log)); + ArtifactoryXrayResponse result = getXrayResultResource(); + + // Set type to an unknown one to make sure no exception is thrown. + result.getAlerts().get(0).getIssues().get(0).setType("UNKNOWN_TYPE"); + + tableHelper.printTable(result, log); } private ArtifactoryXrayResponse getXrayResultResource() throws URISyntaxException, IOException { @@ -83,12 +87,8 @@ private ArtifactoryXrayResponse getXrayEmptyResultResource() throws URISyntaxExc return getResource(EMPTY_RESULT_PATH); } - private ArtifactoryXrayResponse getXrayInvalidResultResource() throws URISyntaxException, IOException { - return getResource(INVALID_RESULT_PATH); - } - private ArtifactoryXrayResponse getResource(String path) throws URISyntaxException, IOException { - File testResourcesPath = new File(this.getClass().getResource(path).toURI()).getCanonicalFile(); + File testResourcesPath = new File(Objects.requireNonNull(this.getClass().getResource(path)).toURI()).getCanonicalFile(); ObjectMapper mapper = new ObjectMapper(new JsonFactory()); return mapper.readValue(testResourcesPath, ArtifactoryXrayResponse.class); } diff --git a/build-info-extractor/src/test/resources/buildScanTable/invalidResult.json b/build-info-extractor/src/test/resources/buildScanTable/invalidResult.json deleted file mode 100644 index 65b57e773..000000000 --- a/build-info-extractor/src/test/resources/buildScanTable/invalidResult.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "summary" : { - "message" : "Build buildscan number 20 was scanned by Xray and 13 Alerts were generated", - "total_alerts" : 13, - "fail_build" : true, - "more_details_url" : "url" - }, - "alerts" : [ { - "created" : "2021-08-03T14:58:59.007Z", - "issues" : [ { - "severity" : "Critical", - "type" : "INVALID TYPE", - "provider" : "JFrog", - "created" : "2021-08-03T14:58:59.007Z", - "summary" : "Plexus-utils before 3.0.16 is vulnerable to command injection because it does not correctly process the contents of double quoted strings.", - "description" : "Plexus-utils before 3.0.16 is vulnerable to command injection because it does not correctly process the contents of double quoted strings.", - "cve" : "CVE-2017-1000487", - "impacted_artifacts" : [ { - "name" : "buildscan", - "path" : "artifactory_saas/builds/buildscan", - "sha256" : "e010e4a81d4066ced2f280c632deb0bfdf3fedb536f8994b7ec8a725f9765511", - "sha1" : "", - "depth" : 0, - "pkg_type" : "Build", - "parent_sha" : "e010e4a81d4066ced2f280c632deb0bfdf3fedb536f8994b7ec8a725f9765511", - "display_name" : "buildscan:20", - "infected_files" : [ { - "name" : "plexus-utils-1.5.1.jar", - "path" : "", - "sha256" : "72582f8ba285601fa753ceeda73ff3cbd94c6e78f52ec611621eaa0186165452", - "depth" : 0, - "parent_sha" : "e010e4a81d4066ced2f280c632deb0bfdf3fedb536f8994b7ec8a725f9765511", - "display_name" : "org.codehaus.plexus:plexus-utils:1.5.1" - } ] - } ] - }]}], - "licenses" : [ ] -} \ No newline at end of file