diff --git a/src/main/java/eu/fasten/vulnerabilityproducer/utils/Vulnerability.java b/src/main/java/eu/fasten/vulnerabilityproducer/utils/Vulnerability.java index e77d6b7..0272612 100644 --- a/src/main/java/eu/fasten/vulnerabilityproducer/utils/Vulnerability.java +++ b/src/main/java/eu/fasten/vulnerabilityproducer/utils/Vulnerability.java @@ -251,6 +251,7 @@ public void setExploits(HashSet exploits) { public String toString() { return "Vulnerability{" + "id='" + id + '\'' + + ", base_cpe=" + baseCpe + ", purls=" + purls + ", first_patched=" + firstPatchedPurls + ", scoreCVSS2=" + scoreCVSS2 + @@ -296,6 +297,12 @@ public void merge(Vulnerability v2) { this.setDescription(v2.getDescription()); } } + // Base CPE + if (this.baseCpe == null) { + if (v2.baseCpe != null) { + this.setBaseCpe(v2.baseCpe); + } + } // Severity if (this.severity == null) { if (v2.severity != null) { @@ -355,6 +362,7 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Vulnerability that = (Vulnerability) o; return id.equals(that.id) && + Objects.equals(baseCpe, that.baseCpe) && Objects.equals(purls, that.purls) && Objects.equals(scoreCVSS2, that.scoreCVSS2) && Objects.equals(scoreCVSS3, that.scoreCVSS3) && diff --git a/src/test/java/eu/fasten/vulnerabilityproducer/VulnerabilityTest.java b/src/test/java/eu/fasten/vulnerabilityproducer/VulnerabilityTest.java index 8d38c93..d9c65a9 100644 --- a/src/test/java/eu/fasten/vulnerabilityproducer/VulnerabilityTest.java +++ b/src/test/java/eu/fasten/vulnerabilityproducer/VulnerabilityTest.java @@ -119,6 +119,7 @@ public void toJsonTest() { public void testMerge() { // Construct the first one Vulnerability v1 = new Vulnerability("test-id"); + v1.setBaseCpe("base_cpe_test"); v1.addPurl("pgk:pypi/django@1.0"); v1.setPublishedDate("20/06/2020"); v1.addReference("www.reference.com"); @@ -134,7 +135,9 @@ public void testMerge() { v2.setVectorCVSS3("7.4"); v1.merge(v2); + assertEquals("base_cpe_test", v1.getBaseCpe()); assertTrue(v1.getPurls().contains("pgk:pypi/django@1.4")); + assertTrue(v1.getPurls().contains("pgk:pypi/django@1.0")); assertTrue(v1.getReferences().contains("www.anotherreference.com")); assertTrue(v1.getPatchLinks().contains("www.patch.com")); assertEquals(v1.getSeverity(), Severity.CRITICAL);