mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-25 18:41:44 +01:00
cleaned up test cases to properly close the DB
Former-commit-id: 7333e882aebfe54b94a4d70cdb55ca2fbd3f3c51
This commit is contained in:
@@ -39,28 +39,37 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOpen() throws Exception {
|
public void testOpen() throws Exception {
|
||||||
CveDB instance = new CveDB();
|
CveDB instance = null;
|
||||||
|
try {
|
||||||
|
instance = new CveDB();
|
||||||
instance.open();
|
instance.open();
|
||||||
instance.commit();
|
instance.commit();
|
||||||
|
} finally {
|
||||||
|
if (instance != null) {
|
||||||
instance.close();
|
instance.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getCPEs method, of class CveDB.
|
* Test of getCPEs method, of class CveDB.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetCPEs() throws Exception {
|
public void testGetCPEs() throws Exception {
|
||||||
CveDB instance = new CveDB();
|
CveDB instance = null;
|
||||||
try {
|
try {
|
||||||
|
instance = new CveDB();
|
||||||
String vendor = "apache";
|
String vendor = "apache";
|
||||||
String product = "struts";
|
String product = "struts";
|
||||||
instance.open();
|
instance.open();
|
||||||
Set<VulnerableSoftware> result = instance.getCPEs(vendor, product);
|
Set<VulnerableSoftware> result = instance.getCPEs(vendor, product);
|
||||||
assertTrue(result.size() > 5);
|
assertTrue(result.size() > 5);
|
||||||
} finally {
|
} finally {
|
||||||
|
if (instance != null) {
|
||||||
instance.close();
|
instance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getVulnerabilities method, of class CveDB.
|
* Test of getVulnerabilities method, of class CveDB.
|
||||||
@@ -68,9 +77,10 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetVulnerabilities() throws Exception {
|
public void testGetVulnerabilities() throws Exception {
|
||||||
String cpeStr = "cpe:/a:apache:struts:2.1.2";
|
String cpeStr = "cpe:/a:apache:struts:2.1.2";
|
||||||
CveDB instance = new CveDB();
|
CveDB instance = null;
|
||||||
List<Vulnerability> results;
|
List<Vulnerability> results;
|
||||||
try {
|
try {
|
||||||
|
instance = new CveDB();
|
||||||
instance.open();
|
instance.open();
|
||||||
results = instance.getVulnerabilities(cpeStr);
|
results = instance.getVulnerabilities(cpeStr);
|
||||||
assertTrue(results.size() > 5);
|
assertTrue(results.size() > 5);
|
||||||
@@ -99,20 +109,23 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
|
|||||||
assertTrue("Expected " + expected + ", but was not identified", found);
|
assertTrue("Expected " + expected + ", but was not identified", found);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
if (instance != null) {
|
||||||
instance.close();
|
instance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getMatchingSoftware method, of class CveDB.
|
* Test of getMatchingSoftware method, of class CveDB.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetMatchingSoftware() throws Exception {
|
public void testGetMatchingSoftware() throws Exception {
|
||||||
|
CveDB instance = null;
|
||||||
HashMap<String, Boolean> versions = new HashMap<String, Boolean>();
|
HashMap<String, Boolean> versions = new HashMap<String, Boolean>();
|
||||||
DependencyVersion identifiedVersion = new DependencyVersion("1.0.1o");
|
DependencyVersion identifiedVersion = new DependencyVersion("1.0.1o");
|
||||||
versions.put("cpe:/a:openssl:openssl:1.0.1e", Boolean.FALSE);
|
versions.put("cpe:/a:openssl:openssl:1.0.1e", Boolean.FALSE);
|
||||||
|
try {
|
||||||
CveDB instance = new CveDB();
|
instance = new CveDB();
|
||||||
Entry<String, Boolean> results = instance.getMatchingSoftware(versions, "openssl", "openssl", identifiedVersion);
|
Entry<String, Boolean> results = instance.getMatchingSoftware(versions, "openssl", "openssl", identifiedVersion);
|
||||||
Assert.assertNull(results);
|
Assert.assertNull(results);
|
||||||
versions.put("cpe:/a:openssl:openssl:1.0.1p", Boolean.FALSE);
|
versions.put("cpe:/a:openssl:openssl:1.0.1p", Boolean.FALSE);
|
||||||
@@ -157,7 +170,11 @@ public class CveDBIntegrationTest extends BaseDBTestCase {
|
|||||||
identifiedVersion = new DependencyVersion("1.6.3");
|
identifiedVersion = new DependencyVersion("1.6.3");
|
||||||
results = instance.getMatchingSoftware(versions, "springsource", "spring_framework", identifiedVersion);
|
results = instance.getMatchingSoftware(versions, "springsource", "spring_framework", identifiedVersion);
|
||||||
Assert.assertNotNull(results);
|
Assert.assertNotNull(results);
|
||||||
|
} finally {
|
||||||
|
if (instance != null) {
|
||||||
|
instance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user