Metadata { public static Vulnerability getVulnerabilityMetadata(String rootDir) throws JsonSyntaxException, IOException { String filePath = rootDir + File.separator + META_PROPERTIES_FILE; if (!FileUtil.isAccessibleFile(filePath)) { throw new IllegalArgumentException( "The root folder " + rootDir + " or the meta file in root directory is missing " + filePath); } Gson gson = new Gson(); Vulnerability metadata = null; metadata = gson.fromJson(FileUtil.readFile(filePath), Vulnerability.class); if (StringUtils.isBlank(metadata.getVulnId())) { throw new IllegalArgumentException( "The vulnerability_id is missing missing in the " + filePath + " file"); } return metadata; }  static Commit getCommitMetadata(String commitDir); static Vulnerability getVulnerabilityMetadata(String rootDir);  }
@Test public void testGetVulnMetadata() throws JsonSyntaxException, IOException { ClassLoader classLoader = getClass().getClassLoader(); String path = classLoader.getResource("testRootDir1").getPath(); Vulnerability vuln = Metadata.getVulnerabilityMetadata(path); assertEquals(3, vuln.getArtifacts().size()); assertEquals(3, vuln.getNotes().size()); assertEquals("COLLECTIONS-580", vuln.getVulnId()); }
@Test(expected = IllegalArgumentException.class) public void testInvalidVulnRootDir() throws JsonSyntaxException, IOException { Metadata.getVulnerabilityMetadata("rootDir1test"); }
@Test(expected = IllegalArgumentException.class) public void testNoVulnIdArg() throws Exception, IOException { ClassLoader classLoader = getClass().getClassLoader(); String path = classLoader.getResource("testRootDir2").getPath(); Metadata.getVulnerabilityMetadata(path); }
@Test public void testMissingNonMandatoryParams() throws JsonSyntaxException, IOException { ClassLoader classLoader = getClass().getClassLoader(); String path = classLoader.getResource("testRootDir3").getPath(); Vulnerability vuln = Metadata.getVulnerabilityMetadata(path); assertNull(vuln.getNotes()); assertEquals("COLLECTIONS-580", vuln.getVulnId()); }
@Test public void testMetadataArtifacts() throws JsonSyntaxException, IOException { ClassLoader classLoader = getClass().getClassLoader(); String path = classLoader.getResource("testRootDir4").getPath(); Vulnerability vuln = Metadata.getVulnerabilityMetadata(path); assertEquals(3, vuln.getArtifacts().size()); }
@Test public void testMetadataArtifactsPUrl() throws JsonSyntaxException, IOException { ClassLoader classLoader = getClass().getClassLoader(); String path = classLoader.getResource("testRootDir5").getPath(); Vulnerability vuln = Metadata.getVulnerabilityMetadata(path); assertEquals(1, vuln.getArtifacts().size()); assertEquals(false, vuln.getArtifacts().get(0).getAffected()); assertEquals( "pkg:maven: vuln.getArtifacts().get(0).getId()); assertEquals("Manual review(frontend)", vuln.getArtifacts().get(0).getReason()); }
@Test(expected = IllegalArgumentException.class) public void testInvalidCommitMetadataDir() throws JsonSyntaxException, IOException { Metadata.getVulnerabilityMetadata("commitDir2"); }