mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-13 05:35:36 +01:00
fixed merge
This commit is contained in:
@@ -25,9 +25,7 @@ import java.io.FileOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.owasp.dependencycheck.data.nvdcve.CveDB;
|
||||
import org.owasp.dependencycheck.utils.Settings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -49,11 +47,6 @@ public abstract class BaseDBTestCase extends BaseTest {
|
||||
ensureDBExists();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
CveDB.getInstance().closeDatabase();
|
||||
}
|
||||
|
||||
public static void ensureDBExists() throws Exception {
|
||||
File f = new File("./target/data/dc.h2.db");
|
||||
if (f.exists() && f.isFile() && f.length() < 71680) {
|
||||
|
||||
@@ -72,9 +72,11 @@ public class EngineIT extends BaseDBTestCase {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
CveDB cveDB = CveDB.getInstance();
|
||||
DatabaseProperties dbProp = cveDB.getDatabaseProperties();
|
||||
ReportGenerator rg = new ReportGenerator("DependencyCheck", instance.getDependencies(), instance.getAnalyzers(), dbProp);
|
||||
DatabaseProperties prop = null;
|
||||
try (CveDB cve = CveDB.getInstance()) {
|
||||
prop = cve.getDatabaseProperties();
|
||||
}
|
||||
ReportGenerator rg = new ReportGenerator("DependencyCheck", instance.getDependencies(), instance.getAnalyzers(), prop);
|
||||
rg.generateReports("./target/", "ALL");
|
||||
instance.cleanup();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -82,8 +83,10 @@ public class RubyBundleAuditAnalyzerTest extends BaseDBTestCase {
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
analyzer.close();
|
||||
analyzer = null;
|
||||
if (analyzer != null) {
|
||||
analyzer.close();
|
||||
analyzer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,6 +169,7 @@ public class RubyBundleAuditAnalyzerTest extends BaseDBTestCase {
|
||||
analyzer.initialize();
|
||||
} catch (Exception e) {
|
||||
//expected, so ignore.
|
||||
assertNotNull(e);
|
||||
} finally {
|
||||
assertThat(analyzer.isEnabled(), is(false));
|
||||
LOGGER.info("phantom-bundle-audit is not available. Ruby Bundle Audit Analyzer is disabled as expected.");
|
||||
@@ -190,6 +194,7 @@ public class RubyBundleAuditAnalyzerTest extends BaseDBTestCase {
|
||||
fail(ex.getMessage());
|
||||
} catch (ExceptionCollection ex) {
|
||||
Assume.assumeNoException("Exception setting up RubyBundleAuditAnalyzer; bundle audit may not be installed, or property \"analyzer.bundle.audit.path\" may not be set.", ex);
|
||||
return;
|
||||
}
|
||||
List<Dependency> dependencies = engine.getDependencies();
|
||||
LOGGER.info(dependencies.size() + " dependencies found.");
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -66,6 +67,9 @@ public class CveDBIT extends BaseDBTestCase {
|
||||
instance.commit();
|
||||
} catch (DatabaseException | SQLException ex) {
|
||||
fail(ex.getMessage());
|
||||
} finally {
|
||||
instance.close();
|
||||
assertFalse(instance.isOpen());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +83,7 @@ public class CveDBIT extends BaseDBTestCase {
|
||||
String product = "struts";
|
||||
Set<VulnerableSoftware> result = instance.getCPEs(vendor, product);
|
||||
assertTrue(result.size() > 5);
|
||||
instance.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,6 +94,7 @@ public class CveDBIT extends BaseDBTestCase {
|
||||
CveDB instance = CveDB.getInstance();
|
||||
Vulnerability result = instance.getVulnerability("CVE-2014-0094");
|
||||
assertEquals("The ParametersInterceptor in Apache Struts before 2.3.16.1 allows remote attackers to \"manipulate\" the ClassLoader via the class parameter, which is passed to the getClass method.", result.getDescription());
|
||||
instance.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,6 +131,7 @@ public class CveDBIT extends BaseDBTestCase {
|
||||
}
|
||||
}
|
||||
assertTrue("Expected " + expected + ", but was not identified", found);
|
||||
instance.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,5 +187,6 @@ public class CveDBIT extends BaseDBTestCase {
|
||||
identifiedVersion = new DependencyVersion("1.6.3");
|
||||
results = instance.getMatchingSoftware(versions, "springsource", "spring_framework", identifiedVersion);
|
||||
assertNotNull(results);
|
||||
instance.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.owasp.dependencycheck.data.nvdcve;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -36,6 +37,23 @@ import static org.junit.Assert.fail;
|
||||
*/
|
||||
public class CveDBMySqlIT extends BaseTest {
|
||||
|
||||
/**
|
||||
* Pretty useless tests of open, commit, and close methods, of class CveDB.
|
||||
*/
|
||||
@Test
|
||||
public void testOpen() {
|
||||
CveDB instance = null;
|
||||
try {
|
||||
instance = CveDB.getInstance();
|
||||
} catch (DatabaseException ex) {
|
||||
System.out.println("Unable to connect to the My SQL database; verify that the db server is running and that the schema has been generated");
|
||||
fail(ex.getMessage());
|
||||
} finally {
|
||||
instance.close();
|
||||
assertFalse(instance.isOpen());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getCPEs method, of class CveDB.
|
||||
*/
|
||||
@@ -50,6 +68,8 @@ public class CveDBMySqlIT extends BaseTest {
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Unable to access the My SQL database; verify that the db server is running and that the schema has been generated");
|
||||
throw ex;
|
||||
} finally {
|
||||
instance.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +86,8 @@ public class CveDBMySqlIT extends BaseTest {
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Unable to access the My SQL database; verify that the db server is running and that the schema has been generated");
|
||||
throw ex;
|
||||
} finally {
|
||||
instance.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class DatabasePropertiesIT extends BaseDBTestCase {
|
||||
assertNotNull(instance);
|
||||
//no exception means the call worked... whether or not it is empty depends on if the db is new
|
||||
//assertEquals(expResult, result);
|
||||
cveDB.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +63,7 @@ public class DatabasePropertiesIT extends BaseDBTestCase {
|
||||
instance = cveDB.reloadProperties();
|
||||
long results = Long.parseLong(instance.getProperty("NVD CVE " + key));
|
||||
assertEquals(expected, results);
|
||||
cveDB.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +78,7 @@ public class DatabasePropertiesIT extends BaseDBTestCase {
|
||||
String expResult = "default";
|
||||
String result = instance.getProperty(key, defaultValue);
|
||||
assertEquals(expResult, result);
|
||||
cveDB.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,6 +93,7 @@ public class DatabasePropertiesIT extends BaseDBTestCase {
|
||||
double version = Double.parseDouble(result);
|
||||
assertTrue(version >= 2.8);
|
||||
assertTrue(version <= 10);
|
||||
cveDB.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,5 +105,6 @@ public class DatabasePropertiesIT extends BaseDBTestCase {
|
||||
DatabaseProperties instance = cveDB.getDatabaseProperties();
|
||||
Properties result = instance.getProperties();
|
||||
assertTrue(result.size() > 0);
|
||||
cveDB.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.owasp.dependencycheck.data.update;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.Test;
|
||||
import org.owasp.dependencycheck.BaseTest;
|
||||
import org.owasp.dependencycheck.BaseDBTestCase;
|
||||
import org.owasp.dependencycheck.data.update.exception.UpdateException;
|
||||
import org.owasp.dependencycheck.data.update.nvd.UpdateableNvdCve;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -30,7 +30,7 @@ import static org.junit.Assert.fail;
|
||||
*
|
||||
* @author Jeremy Long
|
||||
*/
|
||||
public class NvdCveUpdaterIT extends BaseTest {
|
||||
public class NvdCveUpdaterIT extends BaseDBTestCase {
|
||||
|
||||
public NvdCveUpdater getUpdater() {
|
||||
NvdCveUpdater instance = new NvdCveUpdater();
|
||||
|
||||
@@ -150,6 +150,7 @@ public class ReportGeneratorIT extends BaseDBTestCase {
|
||||
|
||||
ReportGenerator generator = new ReportGenerator("Test Report", engine.getDependencies(), engine.getAnalyzers(), dbProp);
|
||||
generator.generateReport(templateName, writeTo);
|
||||
cveDB.close();
|
||||
|
||||
engine.cleanup();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user