mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-04-01 06:33:46 +02:00
codacy recommended updates
This commit is contained in:
@@ -17,10 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck;
|
package org.owasp.dependencycheck;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -29,26 +25,6 @@ import static org.junit.Assert.*;
|
|||||||
* @author jeremy
|
* @author jeremy
|
||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
|
|
||||||
public AppTest() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpClass() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void tearDownClass() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of ensureCanonicalPath method, of class App.
|
* Test of ensureCanonicalPath method, of class App.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -606,7 +606,7 @@ public class Engine implements FileFilter {
|
|||||||
* @param analyzer the analyzer to obtain an executor
|
* @param analyzer the analyzer to obtain an executor
|
||||||
* @return the executor service
|
* @return the executor service
|
||||||
*/
|
*/
|
||||||
ExecutorService getExecutorService(Analyzer analyzer) {
|
protected ExecutorService getExecutorService(Analyzer analyzer) {
|
||||||
if (analyzer.supportsParallelProcessing()) {
|
if (analyzer.supportsParallelProcessing()) {
|
||||||
// just a fair trade-off that should be reasonable for all analyzer types
|
// just a fair trade-off that should be reasonable for all analyzer types
|
||||||
final int maximumNumberOfThreads = 4 * Runtime.getRuntime().availableProcessors();
|
final int maximumNumberOfThreads = 4 * Runtime.getRuntime().availableProcessors();
|
||||||
|
|||||||
@@ -810,10 +810,7 @@ public class CPEAnalyzer extends AbstractAnalyzer {
|
|||||||
if (this.confidence != other.confidence) {
|
if (this.confidence != other.confidence) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.identifier != other.identifier && (this.identifier == null || !this.identifier.equals(other.identifier))) {
|
return !(this.identifier != other.identifier && (this.identifier == null || !this.identifier.equals(other.identifier)));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
|
|||||||
@@ -168,11 +168,6 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
|
|
||||||
|
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
/**
|
|
||||||
* Constructs a new JarAnalyzer.
|
|
||||||
*/
|
|
||||||
public JarAnalyzer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="All standard implmentation details of Analyzer">
|
//<editor-fold defaultstate="collapsed" desc="All standard implmentation details of Analyzer">
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -44,10 +44,7 @@ public class NvdCveAnalyzer extends AbstractAnalyzer {
|
|||||||
* The Logger for use throughout the class
|
* The Logger for use throughout the class
|
||||||
*/
|
*/
|
||||||
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(NvdCveAnalyzer.class);
|
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(NvdCveAnalyzer.class);
|
||||||
/**
|
|
||||||
* The maximum number of query results to return.
|
|
||||||
*/
|
|
||||||
private static final int MAX_QUERY_RESULTS = 100;
|
|
||||||
/**
|
/**
|
||||||
* The CVE Index.
|
* The CVE Index.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -53,12 +53,6 @@ public class NugetPackage {
|
|||||||
*/
|
*/
|
||||||
private String licenseUrl;
|
private String licenseUrl;
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an empty NugetPackage.
|
|
||||||
*/
|
|
||||||
public NugetPackage() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the id.
|
* Sets the id.
|
||||||
* @param id the id
|
* @param id the id
|
||||||
|
|||||||
@@ -138,10 +138,7 @@ public class VulnerableSoftware extends IndexEntry implements Serializable, Comp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final VulnerableSoftware other = (VulnerableSoftware) obj;
|
final VulnerableSoftware other = (VulnerableSoftware) obj;
|
||||||
if ((this.name == null) ? (other.getName() != null) : !this.name.equals(other.getName())) {
|
return !((this.name == null) ? (other.getName() != null) : !this.name.equals(other.getName()));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,12 +24,15 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* DependencyCheck uses {@link org.slf4j.Logger} as a logging framework, and Apache Velocity uses a custom logging implementation
|
* DependencyCheck uses {@link org.slf4j.Logger} as a logging framework, and
|
||||||
* that outputs to a file named velocity.log by default. This class is an implementation of a custom Velocity logger that
|
* Apache Velocity uses a custom logging implementation that outputs to a file
|
||||||
* redirects all velocity logging to the Java Logger class.
|
* named velocity.log by default. This class is an implementation of a custom
|
||||||
|
* Velocity logger that redirects all velocity logging to the Java Logger class.
|
||||||
* </p><p>
|
* </p><p>
|
||||||
* This class was written to address permission issues when using Dependency-Check in a server environment (such as the Jenkins
|
* This class was written to address permission issues when using
|
||||||
* plugin). In some circumstances, Velocity would attempt to create velocity.log in an un-writable directory.</p>
|
* Dependency-Check in a server environment (such as the Jenkins plugin). In
|
||||||
|
* some circumstances, Velocity would attempt to create velocity.log in an
|
||||||
|
* un-writable directory.</p>
|
||||||
*
|
*
|
||||||
* @author Steve Springett
|
* @author Steve Springett
|
||||||
*/
|
*/
|
||||||
@@ -51,7 +54,8 @@ public class VelocityLoggerRedirect implements LogChute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a Velocity log level and message, this method will call the appropriate Logger level and log the specified values.
|
* Given a Velocity log level and message, this method will call the
|
||||||
|
* appropriate Logger level and log the specified values.
|
||||||
*
|
*
|
||||||
* @param level the logging level
|
* @param level the logging level
|
||||||
* @param message the message to be logged
|
* @param message the message to be logged
|
||||||
@@ -76,12 +80,13 @@ public class VelocityLoggerRedirect implements LogChute {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOGGER.info(message);
|
LOGGER.info(message);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a Velocity log level, message and Throwable, this method will call the appropriate Logger level and log the specified
|
* Given a Velocity log level, message and Throwable, this method will call
|
||||||
* values.
|
* the appropriate Logger level and log the specified values.
|
||||||
*
|
*
|
||||||
* @param level the logging level
|
* @param level the logging level
|
||||||
* @param message the message to be logged
|
* @param message the message to be logged
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.owasp.dependencycheck.BaseTest;
|
|||||||
import org.owasp.dependencycheck.Engine;
|
import org.owasp.dependencycheck.Engine;
|
||||||
import org.owasp.dependencycheck.BaseDBTestCase;
|
import org.owasp.dependencycheck.BaseDBTestCase;
|
||||||
import org.owasp.dependencycheck.dependency.Dependency;
|
import org.owasp.dependencycheck.dependency.Dependency;
|
||||||
|
import org.owasp.dependencycheck.exception.InitializationException;
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,15 +95,21 @@ public class ArchiveAnalyzerIntegrationTest extends BaseDBTestCase {
|
|||||||
* Test of initialize and close methods, of class ArchiveAnalyzer.
|
* Test of initialize and close methods, of class ArchiveAnalyzer.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInitialize() throws Exception {
|
public void testInitialize() {
|
||||||
ArchiveAnalyzer instance = new ArchiveAnalyzer();
|
ArchiveAnalyzer instance = new ArchiveAnalyzer();
|
||||||
|
try {
|
||||||
instance.setEnabled(true);
|
instance.setEnabled(true);
|
||||||
instance.setFilesMatched(true);
|
instance.setFilesMatched(true);
|
||||||
instance.initialize();
|
instance.initialize();
|
||||||
|
} catch (InitializationException ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
instance.close();
|
instance.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
//no exception means things worked.
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
import org.apache.lucene.queryparser.classic.ParseException;
|
import org.apache.lucene.queryparser.classic.ParseException;
|
||||||
import org.junit.Assert;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.owasp.dependencycheck.BaseTest;
|
import org.owasp.dependencycheck.BaseTest;
|
||||||
@@ -61,19 +61,19 @@ public class CPEAnalyzerIntegrationTest extends BaseDBTestCase {
|
|||||||
|
|
||||||
String queryText = instance.buildSearch(vendor, product, null, null);
|
String queryText = instance.buildSearch(vendor, product, null, null);
|
||||||
String expResult = " product:( struts 2 core ) AND vendor:( apache software foundation ) ";
|
String expResult = " product:( struts 2 core ) AND vendor:( apache software foundation ) ";
|
||||||
Assert.assertTrue(expResult.equals(queryText));
|
assertTrue(expResult.equals(queryText));
|
||||||
|
|
||||||
queryText = instance.buildSearch(vendor, product, null, productWeightings);
|
queryText = instance.buildSearch(vendor, product, null, productWeightings);
|
||||||
expResult = " product:( struts^5 struts2^5 2 core ) AND vendor:( apache software foundation ) ";
|
expResult = " product:( struts^5 struts2^5 2 core ) AND vendor:( apache software foundation ) ";
|
||||||
Assert.assertTrue(expResult.equals(queryText));
|
assertTrue(expResult.equals(queryText));
|
||||||
|
|
||||||
queryText = instance.buildSearch(vendor, product, vendorWeightings, null);
|
queryText = instance.buildSearch(vendor, product, vendorWeightings, null);
|
||||||
expResult = " product:( struts 2 core ) AND vendor:( apache^5 software foundation ) ";
|
expResult = " product:( struts 2 core ) AND vendor:( apache^5 software foundation ) ";
|
||||||
Assert.assertTrue(expResult.equals(queryText));
|
assertTrue(expResult.equals(queryText));
|
||||||
|
|
||||||
queryText = instance.buildSearch(vendor, product, vendorWeightings, productWeightings);
|
queryText = instance.buildSearch(vendor, product, vendorWeightings, productWeightings);
|
||||||
expResult = " product:( struts^5 struts2^5 2 core ) AND vendor:( apache^5 software foundation ) ";
|
expResult = " product:( struts^5 struts2^5 2 core ) AND vendor:( apache^5 software foundation ) ";
|
||||||
Assert.assertTrue(expResult.equals(queryText));
|
assertTrue(expResult.equals(queryText));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,10 +133,10 @@ public class CPEAnalyzerIntegrationTest extends BaseDBTestCase {
|
|||||||
|
|
||||||
if (expResult != null) {
|
if (expResult != null) {
|
||||||
Identifier expIdentifier = new Identifier("cpe", expResult, expResult);
|
Identifier expIdentifier = new Identifier("cpe", expResult, expResult);
|
||||||
Assert.assertTrue("Incorrect match: { dep:'" + dep.getFileName() + "' }", dep.getIdentifiers().contains(expIdentifier));
|
assertTrue("Incorrect match: { dep:'" + dep.getFileName() + "' }", dep.getIdentifiers().contains(expIdentifier));
|
||||||
} else {
|
} else {
|
||||||
for (Identifier i : dep.getIdentifiers()) {
|
for (Identifier i : dep.getIdentifiers()) {
|
||||||
Assert.assertFalse(String.format("%s - found a CPE identifier when should have been none (found '%s')", dep.getFileName(), i.getValue()), "cpe".equals(i.getType()));
|
assertFalse(String.format("%s - found a CPE identifier when should have been none (found '%s')", dep.getFileName(), i.getValue()), "cpe".equals(i.getType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,23 +190,17 @@ public class CPEAnalyzerIntegrationTest extends BaseDBTestCase {
|
|||||||
instance.determineCPE(spring3);
|
instance.determineCPE(spring3);
|
||||||
instance.close();
|
instance.close();
|
||||||
|
|
||||||
|
|
||||||
String expResult = "cpe:/a:apache:struts:2.1.2";
|
String expResult = "cpe:/a:apache:struts:2.1.2";
|
||||||
Identifier expIdentifier = new Identifier("cpe", expResult, expResult);
|
Identifier expIdentifier = new Identifier("cpe", expResult, expResult);
|
||||||
String expResultSpring = "cpe:/a:springsource:spring_framework:2.5.5";
|
|
||||||
String expResultSpring3 = "cpe:/a:vmware:springsource_spring_framework:3.0.0";
|
|
||||||
|
|
||||||
for (Identifier i : commonValidator.getIdentifiers()) {
|
for (Identifier i : commonValidator.getIdentifiers()) {
|
||||||
Assert.assertFalse("Apache Common Validator - found a CPE identifier?", "cpe".equals(i.getType()));
|
assertFalse("Apache Common Validator - found a CPE identifier?", "cpe".equals(i.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertTrue("Incorrect match size - struts", struts.getIdentifiers().size() >= 1);
|
assertTrue("Incorrect match size - struts", struts.getIdentifiers().size() >= 1);
|
||||||
Assert.assertTrue("Incorrect match - struts", struts.getIdentifiers().contains(expIdentifier));
|
assertTrue("Incorrect match - struts", struts.getIdentifiers().contains(expIdentifier));
|
||||||
Assert.assertTrue("Incorrect match size - spring3 - " + spring3.getIdentifiers().size(), spring3.getIdentifiers().size() >= 1);
|
assertTrue("Incorrect match size - spring3 - " + spring3.getIdentifiers().size(), spring3.getIdentifiers().size() >= 1);
|
||||||
|
|
||||||
//the following two only work if the HintAnalyzer is used.
|
|
||||||
//Assert.assertTrue("Incorrect match size - spring", spring.getIdentifiers().size() == 1);
|
|
||||||
//Assert.assertTrue("Incorrect match - spring", spring.getIdentifiers().get(0).getValue().equals(expResultSpring));
|
|
||||||
jarAnalyzer.close();
|
jarAnalyzer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +237,6 @@ public class CPEAnalyzerIntegrationTest extends BaseDBTestCase {
|
|||||||
public void testSearchCPE() throws Exception {
|
public void testSearchCPE() throws Exception {
|
||||||
String vendor = "apache software foundation";
|
String vendor = "apache software foundation";
|
||||||
String product = "struts 2 core";
|
String product = "struts 2 core";
|
||||||
String version = "2.1.2";
|
|
||||||
String expVendor = "apache";
|
String expVendor = "apache";
|
||||||
String expProduct = "struts";
|
String expProduct = "struts";
|
||||||
|
|
||||||
@@ -251,9 +244,7 @@ public class CPEAnalyzerIntegrationTest extends BaseDBTestCase {
|
|||||||
instance.open();
|
instance.open();
|
||||||
|
|
||||||
Set<String> productWeightings = Collections.singleton("struts2");
|
Set<String> productWeightings = Collections.singleton("struts2");
|
||||||
|
|
||||||
Set<String> vendorWeightings = Collections.singleton("apache");
|
Set<String> vendorWeightings = Collections.singleton("apache");
|
||||||
|
|
||||||
List<IndexEntry> result = instance.searchCPE(vendor, product, vendorWeightings, productWeightings);
|
List<IndexEntry> result = instance.searchCPE(vendor, product, vendorWeightings, productWeightings);
|
||||||
instance.close();
|
instance.close();
|
||||||
|
|
||||||
@@ -265,6 +256,5 @@ public class CPEAnalyzerIntegrationTest extends BaseDBTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue("apache:struts was not identified", found);
|
assertTrue("apache:struts was not identified", found);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ package org.owasp.dependencycheck.analyzer;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
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.dependency.Dependency;
|
import org.owasp.dependencycheck.dependency.Dependency;
|
||||||
|
import org.owasp.dependencycheck.exception.InitializationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -76,19 +78,26 @@ public class FileNameAnalyzerTest extends BaseTest {
|
|||||||
* Test of initialize method, of class FileNameAnalyzer.
|
* Test of initialize method, of class FileNameAnalyzer.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInitialize() throws Exception {
|
public void testInitialize() {
|
||||||
FileNameAnalyzer instance = new FileNameAnalyzer();
|
FileNameAnalyzer instance = new FileNameAnalyzer();
|
||||||
|
try {
|
||||||
instance.initialize();
|
instance.initialize();
|
||||||
assertTrue(true); //initialize does nothing.
|
} catch (InitializationException ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
assertTrue(instance.isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of close method, of class FileNameAnalyzer.
|
* Test of close method, of class FileNameAnalyzer.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testClose() throws Exception {
|
public void testClose() {
|
||||||
FileNameAnalyzer instance = new FileNameAnalyzer();
|
FileNameAnalyzer instance = new FileNameAnalyzer();
|
||||||
|
try {
|
||||||
instance.close();
|
instance.close();
|
||||||
assertTrue(true); //close does nothing.
|
} catch (Exception ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,6 @@ public class HintAnalyzerTest extends BaseDBTestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAnalyze() throws Exception {
|
public void testAnalyze() throws Exception {
|
||||||
HintAnalyzer instance = new HintAnalyzer();
|
|
||||||
|
|
||||||
//File guice = new File(this.getClass().getClassLoader().getResource("guice-3.0.jar").getPath());
|
//File guice = new File(this.getClass().getClassLoader().getResource("guice-3.0.jar").getPath());
|
||||||
File guice = BaseTest.getResourceAsFile(this, "guice-3.0.jar");
|
File guice = BaseTest.getResourceAsFile(this, "guice-3.0.jar");
|
||||||
//Dependency guice = new Dependency(fileg);
|
//Dependency guice = new Dependency(fileg);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import java.io.File;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for PythonDistributionAnalyzer.
|
* Unit tests for PythonDistributionAnalyzer.
|
||||||
@@ -93,13 +94,15 @@ public class PythonDistributionAnalyzerTest extends BaseTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of inspect method, of class PythonDistributionAnalyzer.
|
* Test of inspect method, of class PythonDistributionAnalyzer.
|
||||||
*
|
|
||||||
* @throws AnalysisException is thrown when an exception occurs.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAnalyzeWheel() throws AnalysisException {
|
public void testAnalyzeWheel() {
|
||||||
|
try {
|
||||||
djangoAssertions(new Dependency(BaseTest.getResourceAsFile(this,
|
djangoAssertions(new Dependency(BaseTest.getResourceAsFile(this,
|
||||||
"python/Django-1.7.2-py2.py3-none-any.whl")));
|
"python/Django-1.7.2-py2.py3-none-any.whl")));
|
||||||
|
} catch (AnalysisException ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,23 +134,39 @@ public class PythonDistributionAnalyzerTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnalyzeEggInfoFolder() throws AnalysisException {
|
public void testAnalyzeEggInfoFolder() {
|
||||||
|
try {
|
||||||
eggtestAssertions(this, "python/site-packages/EggTest.egg-info/PKG-INFO");
|
eggtestAssertions(this, "python/site-packages/EggTest.egg-info/PKG-INFO");
|
||||||
|
} catch (AnalysisException ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnalyzeEggArchive() throws AnalysisException {
|
public void testAnalyzeEggArchive() {
|
||||||
|
try {
|
||||||
eggtestAssertions(this, "python/dist/EggTest-0.0.1-py2.7.egg");
|
eggtestAssertions(this, "python/dist/EggTest-0.0.1-py2.7.egg");
|
||||||
|
} catch (AnalysisException ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnalyzeEggArchiveNamedZip() throws AnalysisException {
|
public void testAnalyzeEggArchiveNamedZip() {
|
||||||
|
try {
|
||||||
eggtestAssertions(this, "python/dist/EggTest-0.0.1-py2.7.zip");
|
eggtestAssertions(this, "python/dist/EggTest-0.0.1-py2.7.zip");
|
||||||
|
} catch (AnalysisException ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnalyzeEggFolder() throws AnalysisException {
|
public void testAnalyzeEggFolder() {
|
||||||
|
try {
|
||||||
eggtestAssertions(this, "python/site-packages/EggTest-0.0.1-py2.7.egg/EGG-INFO/PKG-INFO");
|
eggtestAssertions(this, "python/site-packages/EggTest-0.0.1-py2.7.egg/EGG-INFO/PKG-INFO");
|
||||||
|
} catch (AnalysisException ex) {
|
||||||
|
fail(ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eggtestAssertions(Object context, final String resource) throws AnalysisException {
|
public void eggtestAssertions(Object context, final String resource) throws AnalysisException {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.owasp.dependencycheck.exception.ExceptionCollection;
|
|||||||
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;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link RubyBundleAuditAnalyzer}.
|
* Unit tests for {@link RubyBundleAuditAnalyzer}.
|
||||||
@@ -187,7 +188,7 @@ public class RubyBundleAuditAnalyzerTest extends BaseDBTestCase {
|
|||||||
engine.analyzeDependencies();
|
engine.analyzeDependencies();
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
LOGGER.error("NPE", ex);
|
LOGGER.error("NPE", ex);
|
||||||
throw ex;
|
fail(ex.getMessage());
|
||||||
} catch (ExceptionCollection ex) {
|
} 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);
|
Assume.assumeNoException("Exception setting up RubyBundleAuditAnalyzer; bundle audit may not be installed, or property \"analyzer.bundle.audit.path\" may not be set.", ex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class XPathNuspecParserTest extends BaseTest {
|
|||||||
final ByteArrayOutputStream myOut = new ByteArrayOutputStream();
|
final ByteArrayOutputStream myOut = new ByteArrayOutputStream();
|
||||||
System.setErr(new PrintStream(myOut));
|
System.setErr(new PrintStream(myOut));
|
||||||
|
|
||||||
NugetPackage np = parser.parse(is);
|
parser.parse(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -144,6 +144,6 @@ public class DriverLoaderTest extends BaseTest {
|
|||||||
//File testClassPath = (new File(this.getClass().getClassLoader().getResource("org.mortbay.jetty.jar").getPath())).getParentFile();
|
//File testClassPath = (new File(this.getClass().getClassLoader().getResource("org.mortbay.jetty.jar").getPath())).getParentFile();
|
||||||
File testClassPath = BaseTest.getResourceAsFile(this, "org.mortbay.jetty.jar").getParentFile();
|
File testClassPath = BaseTest.getResourceAsFile(this, "org.mortbay.jetty.jar").getParentFile();
|
||||||
File driver = new File(testClassPath, "../../src/test/bad/mysql-connector-java-5.1.27-bin.jar");
|
File driver = new File(testClassPath, "../../src/test/bad/mysql-connector-java-5.1.27-bin.jar");
|
||||||
Driver d = DriverLoader.load(className, driver.getAbsolutePath());
|
DriverLoader.load(className, driver.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -53,9 +54,9 @@ public class ChecksumTest {
|
|||||||
arraysAreEqual = result[i] == expResult[i];
|
arraysAreEqual = result[i] == expResult[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Assert.fail("Checksum results do not match expected results.");
|
fail("Checksum results do not match expected results.");
|
||||||
}
|
}
|
||||||
Assert.assertTrue(arraysAreEqual);
|
assertTrue(arraysAreEqual);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +100,7 @@ public class ChecksumTest {
|
|||||||
//String expResult = "F0915C5F46B8CFA283E5AD67A09B3793";
|
//String expResult = "F0915C5F46B8CFA283E5AD67A09B3793";
|
||||||
String expResult = "f0915c5f46b8cfa283e5ad67a09b3793";
|
String expResult = "f0915c5f46b8cfa283e5ad67a09b3793";
|
||||||
String result = Checksum.getMD5Checksum(file);
|
String result = Checksum.getMD5Checksum(file);
|
||||||
Assert.assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,7 +114,7 @@ public class ChecksumTest {
|
|||||||
//String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A";
|
//String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A";
|
||||||
String expResult = "b8a9ff28b21bcb1d0b50e24a5243d8b51766851a";
|
String expResult = "b8a9ff28b21bcb1d0b50e24a5243d8b51766851a";
|
||||||
String result = Checksum.getSHA1Checksum(file);
|
String result = Checksum.getSHA1Checksum(file);
|
||||||
Assert.assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,6 +126,6 @@ public class ChecksumTest {
|
|||||||
//String expResult = "000102030405060708090A0B0C0D0E0F10";
|
//String expResult = "000102030405060708090A0B0C0D0E0F10";
|
||||||
String expResult = "000102030405060708090a0b0c0d0e0f10";
|
String expResult = "000102030405060708090a0b0c0d0e0f10";
|
||||||
String result = Checksum.getHex(raw);
|
String result = Checksum.getHex(raw);
|
||||||
Assert.assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user