formating and codacy recommended updates

This commit is contained in:
Jeremy Long
2017-02-17 12:59:17 -05:00
parent 71724461a9
commit 960a2e27ab
35 changed files with 149 additions and 153 deletions

View File

@@ -119,7 +119,7 @@ class AnalysisTask implements Callable<Void> {
* *
* @return whether or not the analyzer can analyze the dependency * @return whether or not the analyzer can analyze the dependency
*/ */
boolean shouldAnalyze() { protected boolean shouldAnalyze() {
if (analyzer instanceof FileTypeAnalyzer) { if (analyzer instanceof FileTypeAnalyzer) {
final FileTypeAnalyzer fileTypeAnalyzer = (FileTypeAnalyzer) analyzer; final FileTypeAnalyzer fileTypeAnalyzer = (FileTypeAnalyzer) analyzer;
return fileTypeAnalyzer.accept(dependency.getActualFile()); return fileTypeAnalyzer.accept(dependency.getActualFile());

View File

@@ -557,7 +557,7 @@ public class Engine implements FileFilter {
* @param analyzer the analyzer to execute * @param analyzer the analyzer to execute
* @throws ExceptionCollection thrown if exceptions occurred during analysis * @throws ExceptionCollection thrown if exceptions occurred during analysis
*/ */
void executeAnalysisTasks(Analyzer analyzer, List<Throwable> exceptions) throws ExceptionCollection { protected void executeAnalysisTasks(Analyzer analyzer, List<Throwable> exceptions) throws ExceptionCollection {
LOGGER.debug("Starting {}", analyzer.getName()); LOGGER.debug("Starting {}", analyzer.getName());
final List<AnalysisTask> analysisTasks = getAnalysisTasks(analyzer, exceptions); final List<AnalysisTask> analysisTasks = getAnalysisTasks(analyzer, exceptions);
final ExecutorService executorService = getExecutorService(analyzer); final ExecutorService executorService = getExecutorService(analyzer);

View File

@@ -70,26 +70,26 @@ public class CPEAnalyzer extends AbstractAnalyzer {
/** /**
* The maximum number of query results to return. * The maximum number of query results to return.
*/ */
static final int MAX_QUERY_RESULTS = 25; private static final int MAX_QUERY_RESULTS = 25;
/** /**
* The weighting boost to give terms when constructing the Lucene query. * The weighting boost to give terms when constructing the Lucene query.
*/ */
static final String WEIGHTING_BOOST = "^5"; private static final String WEIGHTING_BOOST = "^5";
/** /**
* A string representation of a regular expression defining characters * A string representation of a regular expression defining characters
* utilized within the CPE Names. * utilized within the CPE Names.
*/ */
static final String CLEANSE_CHARACTER_RX = "[^A-Za-z0-9 ._-]"; private static final String CLEANSE_CHARACTER_RX = "[^A-Za-z0-9 ._-]";
/** /**
* A string representation of a regular expression used to remove all but * A string representation of a regular expression used to remove all but
* alpha characters. * alpha characters.
*/ */
static final String CLEANSE_NONALPHA_RX = "[^A-Za-z]*"; private static final String CLEANSE_NONALPHA_RX = "[^A-Za-z]*";
/** /**
* The additional size to add to a new StringBuilder to account for extra * The additional size to add to a new StringBuilder to account for extra
* data that will be written into the string. * data that will be written into the string.
*/ */
static final int STRING_BUILDER_BUFFER = 20; private static final int STRING_BUILDER_BUFFER = 20;
/** /**
* The CPE in memory index. * The CPE in memory index.
*/ */

View File

@@ -384,7 +384,7 @@ public class DependencyBundlingAnalyzer extends AbstractAnalyzer {
* @return a boolean indicating whether or not the left dependency should be * @return a boolean indicating whether or not the left dependency should be
* considered the "core" version. * considered the "core" version.
*/ */
boolean isCore(Dependency left, Dependency right) { protected boolean isCore(Dependency left, Dependency right) {
final String leftName = left.getFileName().toLowerCase(); final String leftName = left.getFileName().toLowerCase();
final String rightName = right.getFileName().toLowerCase(); final String rightName = right.getFileName().toLowerCase();

View File

@@ -47,7 +47,7 @@ public class NvdCveAnalyzer extends AbstractAnalyzer {
/** /**
* The maximum number of query results to return. * The maximum number of query results to return.
*/ */
static final int MAX_QUERY_RESULTS = 100; private static final int MAX_QUERY_RESULTS = 100;
/** /**
* The CVE Index. * The CVE Index.
*/ */

View File

@@ -102,7 +102,7 @@ public class OpenSSLAnalyzer extends AbstractFileTypeAnalyzer {
* @param openSSLVersionConstant The open SSL version * @param openSSLVersionConstant The open SSL version
* @return the version of openssl * @return the version of openssl
*/ */
static String getOpenSSLVersion(long openSSLVersionConstant) { protected static String getOpenSSLVersion(long openSSLVersionConstant) {
final long major = openSSLVersionConstant >>> MAJOR_OFFSET; final long major = openSSLVersionConstant >>> MAJOR_OFFSET;
final long minor = (openSSLVersionConstant & MINOR_MASK) >>> MINOR_OFFSET; final long minor = (openSSLVersionConstant & MINOR_MASK) >>> MINOR_OFFSET;
final long fix = (openSSLVersionConstant & FIX_MASK) >>> FIX_OFFSET; final long fix = (openSSLVersionConstant & FIX_MASK) >>> FIX_OFFSET;

View File

@@ -31,7 +31,7 @@ public class IndexEntry implements Serializable {
/** /**
* the serial version uid. * the serial version uid.
*/ */
static final long serialVersionUID = 8011924485946326934L; private static final long serialVersionUID = 8011924485946326934L;
/** /**
* The vendor name. * The vendor name.
*/ */

View File

@@ -156,10 +156,7 @@ public final class TokenPairConcatenatingFilter extends TokenFilter {
if ((this.previousWord == null) ? (other.previousWord != null) : !this.previousWord.equals(other.previousWord)) { if ((this.previousWord == null) ? (other.previousWord != null) : !this.previousWord.equals(other.previousWord)) {
return false; return false;
} }
if (this.words != other.words && (this.words == null || !this.words.equals(other.words))) { return !(this.words != other.words && (this.words == null || !this.words.equals(other.words)));
return false;
}
return true;
} }
} }

View File

@@ -259,7 +259,7 @@ public class CveDB {
* *
* @return the properties from the database * @return the properties from the database
*/ */
synchronized Properties getProperties() { public synchronized Properties getProperties() {
final Properties prop = new Properties(); final Properties prop = new Properties();
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
@@ -285,7 +285,7 @@ public class CveDB {
* @param key the property key * @param key the property key
* @param value the property value * @param value the property value
*/ */
synchronized void saveProperty(String key, String value) { public synchronized void saveProperty(String key, String value) {
try { try {
try { try {
final PreparedStatement mergeProperty = getConnection().prepareStatement(statementBundle.getString("MERGE_PROPERTY")); final PreparedStatement mergeProperty = getConnection().prepareStatement(statementBundle.getString("MERGE_PROPERTY"));
@@ -703,7 +703,7 @@ public class CveDB {
* analyzed * analyzed
* @return true if the identified version is affected, otherwise false * @return true if the identified version is affected, otherwise false
*/ */
Entry<String, Boolean> getMatchingSoftware(Map<String, Boolean> vulnerableSoftware, String vendor, String product, protected Entry<String, Boolean> getMatchingSoftware(Map<String, Boolean> vulnerableSoftware, String vendor, String product,
DependencyVersion identifiedVersion) { DependencyVersion identifiedVersion) {
final boolean isVersionTwoADifferentProduct = "apache".equals(vendor) && "struts".equals(product); final boolean isVersionTwoADifferentProduct = "apache".equals(vendor) && "struts".equals(product);

View File

@@ -125,7 +125,7 @@ public class NvdCveUpdater extends BaseUpdater implements CachedWebDataSource {
} }
} }
void initializeExecutorServices() { protected void initializeExecutorServices() {
processingExecutorService = Executors.newFixedThreadPool(PROCESSING_THREAD_POOL_SIZE); processingExecutorService = Executors.newFixedThreadPool(PROCESSING_THREAD_POOL_SIZE);
downloadExecutorService = Executors.newFixedThreadPool(DOWNLOAD_THREAD_POOL_SIZE); downloadExecutorService = Executors.newFixedThreadPool(DOWNLOAD_THREAD_POOL_SIZE);
LOGGER.debug("#download threads: {}", DOWNLOAD_THREAD_POOL_SIZE); LOGGER.debug("#download threads: {}", DOWNLOAD_THREAD_POOL_SIZE);
@@ -280,7 +280,7 @@ public class NvdCveUpdater extends BaseUpdater implements CachedWebDataSource {
* @throws UpdateException Is thrown if there is an issue with the last * @throws UpdateException Is thrown if there is an issue with the last
* updated properties file * updated properties file
*/ */
final UpdateableNvdCve getUpdatesNeeded() throws MalformedURLException, DownloadFailedException, UpdateException { protected final UpdateableNvdCve getUpdatesNeeded() throws MalformedURLException, DownloadFailedException, UpdateException {
LOGGER.info("starting getUpdatesNeeded() ..."); LOGGER.info("starting getUpdatesNeeded() ...");
UpdateableNvdCve updates; UpdateableNvdCve updates;
try { try {

View File

@@ -191,10 +191,7 @@ public class Identifier implements Serializable, Comparable<Identifier> {
if ((this.value == null) ? (other.value != null) : !this.value.equals(other.value)) { if ((this.value == null) ? (other.value != null) : !this.value.equals(other.value)) {
return false; return false;
} }
if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) { return !((this.type == null) ? (other.type != null) : !this.type.equals(other.type));
return false;
}
return true;
} }
@Override @Override

View File

@@ -119,10 +119,7 @@ public class Reference implements Serializable, Comparable<Reference> {
if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) { if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
return false; return false;
} }
if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) { return !((this.source == null) ? (other.source != null) : !this.source.equals(other.source));
return false;
}
return true;
} }
@Override @Override

View File

@@ -374,10 +374,7 @@ public class Vulnerability implements Serializable, Comparable<Vulnerability> {
return false; return false;
} }
final Vulnerability other = (Vulnerability) obj; final Vulnerability other = (Vulnerability) obj;
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { return !((this.name == null) ? (other.name != null) : !this.name.equals(other.name));
return false;
}
return true;
} }
@Override @Override

View File

@@ -107,6 +107,7 @@ public class VelocityLoggerRedirect implements LogChute {
break; break;
default: default:
LOGGER.info(message, t); LOGGER.info(message, t);
break;
} }
} }

View File

@@ -119,9 +119,6 @@ public class Pair<L, R> {
if (this.left != other.left && (this.left == null || !this.left.equals(other.left))) { if (this.left != other.left && (this.left == null || !this.left.equals(other.left))) {
return false; return false;
} }
if (this.right != other.right && (this.right == null || !this.right.equals(other.right))) { return !(this.right != other.right && (this.right == null || !this.right.equals(other.right)));
return false;
}
return true;
} }
} }

View File

@@ -117,10 +117,7 @@ public class License {
if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) { if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
return false; return false;
} }
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { return !((this.name == null) ? (other.name != null) : !this.name.equals(other.name));
return false;
}
return true;
} }
/** /**

View File

@@ -163,10 +163,7 @@ public class PropertyType {
if (this.regex != other.regex) { if (this.regex != other.regex) {
return false; return false;
} }
if (this.caseSensitive != other.caseSensitive) { return this.caseSensitive == other.caseSensitive;
return false;
}
return true;
} }
/** /**

View File

@@ -35,6 +35,38 @@ public class SuppressionRule {
*/ */
private PropertyType filePath; private PropertyType filePath;
/**
* The SHA1 hash.
*/
private String sha1;
/**
* A list of CPEs to suppression
*/
private List<PropertyType> cpe = new ArrayList<>();
/**
* The list of cvssBelow scores.
*/
private List<Float> cvssBelow = new ArrayList<>();
/**
* The list of CWE entries to suppress.
*/
private List<String> cwe = new ArrayList<>();
/**
* The list of CVE entries to suppress.
*/
private List<String> cve = new ArrayList<>();
/**
* A Maven GAV to suppression.
*/
private PropertyType gav = null;
/**
* A flag indicating whether or not the suppression rule is a core/base rule
* that should not be included in the resulting report in the "suppressed"
* section.
*/
private boolean base;
/** /**
* Get the value of filePath. * Get the value of filePath.
* *
@@ -52,10 +84,6 @@ public class SuppressionRule {
public void setFilePath(PropertyType filePath) { public void setFilePath(PropertyType filePath) {
this.filePath = filePath; this.filePath = filePath;
} }
/**
* The sha1 hash.
*/
private String sha1;
/** /**
* Get the value of sha1. * Get the value of sha1.
@@ -67,40 +95,36 @@ public class SuppressionRule {
} }
/** /**
* Set the value of sha1. * Set the value of SHA1.
* *
* @param sha1 new value of sha1 * @param sha1 new value of SHA1
*/ */
public void setSha1(String sha1) { public void setSha1(String sha1) {
this.sha1 = sha1; this.sha1 = sha1;
} }
/**
* A list of CPEs to suppression
*/
private List<PropertyType> cpe = new ArrayList<PropertyType>();
/** /**
* Get the value of cpe. * Get the value of CPE.
* *
* @return the value of cpe * @return the value of CPE
*/ */
public List<PropertyType> getCpe() { public List<PropertyType> getCpe() {
return cpe; return cpe;
} }
/** /**
* Set the value of cpe. * Set the value of CPE.
* *
* @param cpe new value of cpe * @param cpe new value of CPE
*/ */
public void setCpe(List<PropertyType> cpe) { public void setCpe(List<PropertyType> cpe) {
this.cpe = cpe; this.cpe = cpe;
} }
/** /**
* Adds the cpe to the cpe list. * Adds the CPE to the CPE list.
* *
* @param cpe the cpe to add * @param cpe the CPE to add
*/ */
public void addCpe(PropertyType cpe) { public void addCpe(PropertyType cpe) {
this.cpe.add(cpe); this.cpe.add(cpe);
@@ -114,10 +138,6 @@ public class SuppressionRule {
public boolean hasCpe() { public boolean hasCpe() {
return !cpe.isEmpty(); return !cpe.isEmpty();
} }
/**
* The list of cvssBelow scores.
*/
private List<Float> cvssBelow = new ArrayList<Float>();
/** /**
* Get the value of cvssBelow. * Get the value of cvssBelow.
@@ -138,49 +158,45 @@ public class SuppressionRule {
} }
/** /**
* Adds the cvss to the cvssBelow list. * Adds the CVSS to the cvssBelow list.
* *
* @param cvss the cvss to add * @param cvss the CVSS to add
*/ */
public void addCvssBelow(Float cvss) { public void addCvssBelow(Float cvss) {
this.cvssBelow.add(cvss); this.cvssBelow.add(cvss);
} }
/** /**
* Returns whether or not this suppression rule has cvss suppressions. * Returns whether or not this suppression rule has CVSS suppressions.
* *
* @return whether or not this suppression rule has cvss suppressions * @return whether or not this suppression rule has CVSS suppressions
*/ */
public boolean hasCvssBelow() { public boolean hasCvssBelow() {
return !cvssBelow.isEmpty(); return !cvssBelow.isEmpty();
} }
/**
* The list of cwe entries to suppress.
*/
private List<String> cwe = new ArrayList<String>();
/** /**
* Get the value of cwe. * Get the value of CWE.
* *
* @return the value of cwe * @return the value of CWE
*/ */
public List<String> getCwe() { public List<String> getCwe() {
return cwe; return cwe;
} }
/** /**
* Set the value of cwe. * Set the value of CWE.
* *
* @param cwe new value of cwe * @param cwe new value of CWE
*/ */
public void setCwe(List<String> cwe) { public void setCwe(List<String> cwe) {
this.cwe = cwe; this.cwe = cwe;
} }
/** /**
* Adds the cwe to the cwe list. * Adds the CWE to the CWE list.
* *
* @param cwe the cwe to add * @param cwe the CWE to add
*/ */
public void addCwe(String cwe) { public void addCwe(String cwe) {
this.cwe.add(cwe); this.cwe.add(cwe);
@@ -194,33 +210,29 @@ public class SuppressionRule {
public boolean hasCwe() { public boolean hasCwe() {
return !cwe.isEmpty(); return !cwe.isEmpty();
} }
/**
* The list of cve entries to suppress.
*/
private List<String> cve = new ArrayList<String>();
/** /**
* Get the value of cve. * Get the value of CVE.
* *
* @return the value of cve * @return the value of CVE
*/ */
public List<String> getCve() { public List<String> getCve() {
return cve; return cve;
} }
/** /**
* Set the value of cve. * Set the value of CVE.
* *
* @param cve new value of cve * @param cve new value of CVE
*/ */
public void setCve(List<String> cve) { public void setCve(List<String> cve) {
this.cve = cve; this.cve = cve;
} }
/** /**
* Adds the cve to the cve list. * Adds the CVE to the CVE list.
* *
* @param cve the cve to add * @param cve the CVE to add
*/ */
public void addCve(String cve) { public void addCve(String cve) {
this.cve.add(cve); this.cve.add(cve);
@@ -234,15 +246,11 @@ public class SuppressionRule {
public boolean hasCve() { public boolean hasCve() {
return !cve.isEmpty(); return !cve.isEmpty();
} }
/**
* A Maven GAV to suppression.
*/
private PropertyType gav = null;
/** /**
* Get the value of Maven GAV. * Get the value of Maven GAV.
* *
* @return the value of gav * @return the value of GAV
*/ */
public PropertyType getGav() { public PropertyType getGav() {
return gav; return gav;
@@ -251,7 +259,7 @@ public class SuppressionRule {
/** /**
* Set the value of Maven GAV. * Set the value of Maven GAV.
* *
* @param gav new value of Maven gav * @param gav new value of Maven GAV
*/ */
public void setGav(PropertyType gav) { public void setGav(PropertyType gav) {
this.gav = gav; this.gav = gav;
@@ -266,12 +274,6 @@ public class SuppressionRule {
return gav != null; return gav != null;
} }
/**
* A flag indicating whether or not the suppression rule is a core/base rule that should not be included in the resulting
* report in the "suppressed" section.
*/
private boolean base;
/** /**
* Get the value of base. * Get the value of base.
* *
@@ -291,8 +293,9 @@ public class SuppressionRule {
} }
/** /**
* Processes a given dependency to determine if any CPE, CVE, CWE, or CVSS scores should be suppressed. If any should be, they * Processes a given dependency to determine if any CPE, CVE, CWE, or CVSS
* are removed from the dependency. * scores should be suppressed. If any should be, they are removed from the
* dependency.
* *
* @param dependency a project dependency to analyze * @param dependency a project dependency to analyze
*/ */
@@ -375,23 +378,26 @@ public class SuppressionRule {
} }
/** /**
* Identifies if the cpe specified by the cpe suppression rule does not specify a version. * Identifies if the cpe specified by the cpe suppression rule does not
* specify a version.
* *
* @param c a suppression rule identifier * @param c a suppression rule identifier
* @return true if the property type does not specify a version; otherwise false * @return true if the property type does not specify a version; otherwise
* false
*/ */
boolean cpeHasNoVersion(PropertyType c) { protected boolean cpeHasNoVersion(PropertyType c) {
return !c.isRegex() && countCharacter(c.getValue(), ':') <= 3; return !c.isRegex() && countCharacter(c.getValue(), ':') <= 3;
} }
/** /**
* Counts the number of occurrences of the character found within the string. * Counts the number of occurrences of the character found within the
* string.
* *
* @param str the string to check * @param str the string to check
* @param c the character to count * @param c the character to count
* @return the number of times the character is found in the string * @return the number of times the character is found in the string
*/ */
int countCharacter(String str, char c) { private int countCharacter(String str, char c) {
int count = 0; int count = 0;
int pos = str.indexOf(c) + 1; int pos = str.indexOf(c) + 1;
while (pos > 0) { while (pos > 0) {
@@ -402,7 +408,8 @@ public class SuppressionRule {
} }
/** /**
* Determines if the cpeEntry specified as a PropertyType matches the given Identifier. * Determines if the cpeEntry specified as a PropertyType matches the given
* Identifier.
* *
* @param identifierType the type of identifier ("cpe", "maven", etc.) * @param identifierType the type of identifier ("cpe", "maven", etc.)
* @param suppressionEntry a suppression rule entry * @param suppressionEntry a suppression rule entry

View File

@@ -17,13 +17,13 @@ import org.owasp.dependencycheck.utils.Settings;
public class AnalysisTaskTest extends BaseTest { public class AnalysisTaskTest extends BaseTest {
@Mocked @Mocked
FileTypeAnalyzer fileTypeAnalyzer; private FileTypeAnalyzer fileTypeAnalyzer;
@Mocked @Mocked
Dependency dependency; private Dependency dependency;
@Mocked @Mocked
Engine engine; private Engine engine;
@Test @Test

View File

@@ -25,7 +25,6 @@ import java.io.FileOutputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import org.junit.Before; import org.junit.Before;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.utils.Settings; import org.owasp.dependencycheck.utils.Settings;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -54,10 +53,10 @@ public abstract class BaseDBTestCase extends BaseTest {
f.delete(); f.delete();
} }
java.io.File dataPath = Settings.getDataDirectory(); File dataPath = Settings.getDataDirectory();
String fileName = Settings.getString(Settings.KEYS.DB_FILE_NAME); String fileName = Settings.getString(Settings.KEYS.DB_FILE_NAME);
LOGGER.trace("DB file name {}", fileName); LOGGER.trace("DB file name {}", fileName);
java.io.File dataFile = new File(dataPath, fileName); File dataFile = new File(dataPath, fileName);
LOGGER.trace("Ensuring {} exists", dataFile.toString()); LOGGER.trace("Ensuring {} exists", dataFile.toString());
if (!dataPath.exists() || !dataFile.exists()) { if (!dataPath.exists() || !dataFile.exists()) {
LOGGER.trace("Extracting database to {}", dataPath.toString()); LOGGER.trace("Extracting database to {}", dataPath.toString());

View File

@@ -46,9 +46,11 @@ public class EngineTest extends BaseDBTestCase {
@Mocked @Mocked
private AnalysisTask analysisTask; private AnalysisTask analysisTask;
/** /**
* Test of scanFile method, of class Engine. * Test of scanFile method, of class Engine.
*
* @throws org.owasp.dependencycheck.data.nvdcve.DatabaseException thrown is
* there is an exception
*/ */
@Test @Test
public void testScanFile() throws DatabaseException { public void testScanFile() throws DatabaseException {
@@ -64,30 +66,34 @@ public class EngineTest extends BaseDBTestCase {
Dependency secondDwr = instance.scanFile(file); Dependency secondDwr = instance.scanFile(file);
assertEquals(2, instance.getDependencies().size()); assertEquals(2, instance.getDependencies().size());
assertTrue(dwr == secondDwr); assertEquals(dwr, secondDwr);
} }
@Test(expected = ExceptionCollection.class) @Test(expected = ExceptionCollection.class)
public void exceptionDuringAnalysisTaskExecutionIsFatal() throws DatabaseException, ExceptionCollection { public void exceptionDuringAnalysisTaskExecutionIsFatal() throws DatabaseException, ExceptionCollection {
final ExecutorService executorService = Executors.newFixedThreadPool(3); final ExecutorService executorService = Executors.newFixedThreadPool(3);
final Engine instance = new Engine(); final Engine instance = new Engine();
final List<Throwable> exceptions = new ArrayList<Throwable>(); final List<Throwable> exceptions = new ArrayList<>();
new Expectations() {{ new Expectations() {
{
analysisTask.call(); analysisTask.call();
result = new IllegalStateException("Analysis task execution threw an exception"); result = new IllegalStateException("Analysis task execution threw an exception");
}}; }
};
final List<AnalysisTask> failingAnalysisTask = new ArrayList<AnalysisTask>(); final List<AnalysisTask> failingAnalysisTask = new ArrayList<>();
failingAnalysisTask.add(analysisTask); failingAnalysisTask.add(analysisTask);
new Expectations(instance) {{ new Expectations(instance) {
{
instance.getExecutorService(analyzer); instance.getExecutorService(analyzer);
result = executorService; result = executorService;
instance.getAnalysisTasks(analyzer, exceptions); instance.getAnalysisTasks(analyzer, exceptions);
result = failingAnalysisTask; result = failingAnalysisTask;
}}; }
};
instance.executeAnalysisTasks(analyzer, exceptions); instance.executeAnalysisTasks(analyzer, exceptions);

View File

@@ -49,7 +49,7 @@ public class AssemblyAnalyzerTest extends BaseTest {
private static final String LOG_KEY = "org.slf4j.simpleLogger.org.owasp.dependencycheck.analyzer.AssemblyAnalyzer"; private static final String LOG_KEY = "org.slf4j.simpleLogger.org.owasp.dependencycheck.analyzer.AssemblyAnalyzer";
AssemblyAnalyzer analyzer; private AssemblyAnalyzer analyzer;
/** /**
* Sets up the analyzer. * Sets up the analyzer.

View File

@@ -43,7 +43,7 @@ public class AutoconfAnalyzerTest extends BaseTest {
/** /**
* The analyzer to test. * The analyzer to test.
*/ */
AutoconfAnalyzer analyzer; private AutoconfAnalyzer analyzer;
private void assertCommonEvidence(Dependency result, String product, private void assertCommonEvidence(Dependency result, String product,
String version, String vendor) { String version, String vendor) {

View File

@@ -53,7 +53,7 @@ public class CMakeAnalyzerTest extends BaseDBTestCase {
/** /**
* The package analyzer to test. * The package analyzer to test.
*/ */
CMakeAnalyzer analyzer; private CMakeAnalyzer analyzer;
/** /**
* Setup the CmakeAnalyzer. * Setup the CmakeAnalyzer.

View File

@@ -47,7 +47,7 @@ public class ComposerLockAnalyzerTest extends BaseDBTestCase {
/** /**
* The analyzer to test. * The analyzer to test.
*/ */
ComposerLockAnalyzer analyzer; private ComposerLockAnalyzer analyzer;
/** /**
* Correctly setup the analyzer for testing. * Correctly setup the analyzer for testing.

View File

@@ -34,7 +34,7 @@ import static org.junit.Assert.assertTrue;
public class DependencyBundlingAnalyzerTest extends BaseTest { public class DependencyBundlingAnalyzerTest extends BaseTest {
@Mocked @Mocked
Engine engineMock; private Engine engineMock;
/** /**
* Test of getName method, of class DependencyBundlingAnalyzer. * Test of getName method, of class DependencyBundlingAnalyzer.

View File

@@ -40,7 +40,7 @@ public class NodePackageAnalyzerTest extends BaseTest {
/** /**
* The analyzer to test. * The analyzer to test.
*/ */
NodePackageAnalyzer analyzer; private NodePackageAnalyzer analyzer;
/** /**
* Correctly setup the analyzer for testing. * Correctly setup the analyzer for testing.

View File

@@ -57,7 +57,7 @@ public class RubyBundleAuditAnalyzerTest extends BaseDBTestCase {
/** /**
* The analyzer to test. * The analyzer to test.
*/ */
RubyBundleAuditAnalyzer analyzer; private RubyBundleAuditAnalyzer analyzer;
/** /**
* Correctly setup the analyzer for testing. * Correctly setup the analyzer for testing.

View File

@@ -40,7 +40,7 @@ public class RubyGemspecAnalyzerTest extends BaseTest {
/** /**
* The analyzer to test. * The analyzer to test.
*/ */
RubyGemspecAnalyzer analyzer; private RubyGemspecAnalyzer analyzer;
/** /**
* Correctly setup the analyzer for testing. * Correctly setup the analyzer for testing.

View File

@@ -20,6 +20,7 @@ package org.owasp.dependencycheck.data.nvdcve;
import org.owasp.dependencycheck.BaseDBTestCase; import org.owasp.dependencycheck.BaseDBTestCase;
import java.util.Properties; import java.util.Properties;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.owasp.dependencycheck.data.update.nvd.NvdCveInfo; import org.owasp.dependencycheck.data.update.nvd.NvdCveInfo;
@@ -40,8 +41,7 @@ public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
cveDB = new CveDB(); cveDB = new CveDB();
cveDB.open(); cveDB.open();
DatabaseProperties instance = cveDB.getDatabaseProperties(); DatabaseProperties instance = cveDB.getDatabaseProperties();
boolean expResult = false; assertNotNull(instance);
boolean result = instance.isEmpty();
//no exception means the call worked... whether or not it is empty depends on if the db is new //no exception means the call worked... whether or not it is empty depends on if the db is new
//assertEquals(expResult, result); //assertEquals(expResult, result);
} finally { } finally {

View File

@@ -18,8 +18,10 @@
package org.owasp.dependencycheck.data.update; package org.owasp.dependencycheck.data.update;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test; import org.junit.Test;
import org.owasp.dependencycheck.BaseTest; import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.data.update.exception.UpdateException;
import org.owasp.dependencycheck.data.update.nvd.UpdateableNvdCve; import org.owasp.dependencycheck.data.update.nvd.UpdateableNvdCve;
/** /**
@@ -38,9 +40,13 @@ import org.owasp.dependencycheck.data.update.nvd.UpdateableNvdCve;
* Test of update method. * Test of update method.
*/ */
@Test @Test
public void testUpdate() throws Exception { public void testUpdate() {
try {
NvdCveUpdater instance = getUpdater(); NvdCveUpdater instance = getUpdater();
instance.update(); instance.update();
} catch (UpdateException ex) {
fail(ex.getMessage());
}
} }
/** /**

View File

@@ -23,9 +23,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import org.owasp.dependencycheck.BaseTest; import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.dependency.VulnerableSoftware; import org.owasp.dependencycheck.dependency.VulnerableSoftware;
@@ -47,6 +45,6 @@ public class NvdCve_1_2_HandlerTest extends BaseTest {
NvdCve12Handler instance = new NvdCve12Handler(); NvdCve12Handler instance = new NvdCve12Handler();
saxParser.parse(file, instance); saxParser.parse(file, instance);
Map<String, List<VulnerableSoftware>> results = instance.getVulnerabilities(); Map<String, List<VulnerableSoftware>> results = instance.getVulnerabilities();
assertTrue("No vulnerable software identified with a previous version in 2012 CVE 1.2?", !results.isEmpty()); assertFalse("No vulnerable software identified with a previous version in 2012 CVE 1.2?", results.isEmpty());
} }
} }

View File

@@ -48,9 +48,10 @@ public class ModelTest extends BaseTest {
*/ */
@Test @Test
public void testSetName() { public void testSetName() {
String name = ""; String name = "name";
Model instance = new Model(); Model instance = new Model();
instance.setName(name); instance.setName(name);
assertEquals("name", instance.getName());
} }
/** /**
@@ -209,9 +210,10 @@ public class ModelTest extends BaseTest {
*/ */
@Test @Test
public void testSetParentArtifactId() { public void testSetParentArtifactId() {
String parentArtifactId = ""; String parentArtifactId = "something";
Model instance = new Model(); Model instance = new Model();
instance.setParentArtifactId(parentArtifactId); instance.setParentArtifactId(parentArtifactId);
assertNotNull(instance.getParentArtifactId());
} }
/** /**
@@ -231,9 +233,10 @@ public class ModelTest extends BaseTest {
*/ */
@Test @Test
public void testSetParentVersion() { public void testSetParentVersion() {
String parentVersion = ""; String parentVersion = "1.0";
Model instance = new Model(); Model instance = new Model();
instance.setParentVersion(parentVersion); instance.setParentVersion(parentVersion);
assertNotNull(instance.getParentVersion());
} }
/** /**
@@ -257,6 +260,7 @@ public class ModelTest extends BaseTest {
License license = new License("name", "url"); License license = new License("name", "url");
Model instance = new Model(); Model instance = new Model();
instance.addLicense(license); instance.addLicense(license);
assertNotNull(instance.getLicenses());
} }
/** /**

View File

@@ -983,10 +983,7 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
if (skipProvidedScope && org.apache.maven.artifact.Artifact.SCOPE_PROVIDED.equals(scope)) { if (skipProvidedScope && org.apache.maven.artifact.Artifact.SCOPE_PROVIDED.equals(scope)) {
return true; return true;
} }
if (skipRuntimeScope && !org.apache.maven.artifact.Artifact.SCOPE_RUNTIME.equals(scope)) { return skipRuntimeScope && !org.apache.maven.artifact.Artifact.SCOPE_RUNTIME.equals(scope);
return true;
}
return false;
} }
/** /**

View File

@@ -26,7 +26,6 @@ import static org.junit.Assert.fail;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.owasp.dependencycheck.utils.Checksum;
/** /**
* *