mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 09:31:32 +01:00
Squashed commit of the following:
commit 1d1a06a5ae7ea4f6e3adbf5a4b8163eba50562a3 Author: Will Stranathan <will@thestranathans.com> Date: Wed Mar 26 22:59:15 2014 -0400 Updated unit tests and logging commit bb00174e62c9657809d6e5a9cde7c7308d905593 Author: Will Stranathan <will@thestranathans.com> Date: Wed Mar 26 22:20:28 2014 -0400 Updated GrokAssembly to not fail if the vendor can't be gotten commit 27f7c9366acca8abbff9c6e9fa9ce1a1329da887 Author: Will Stranathan <will@thestranathans.com> Date: Wed Mar 26 22:18:33 2014 -0400 Updated unit test to not care about version number Former-commit-id: 6329e3f54f2808c54dd998514f0881dc3a976281
This commit is contained in:
@@ -71,7 +71,7 @@ public class AssemblyAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
/**
|
/**
|
||||||
* Logger
|
* Logger
|
||||||
*/
|
*/
|
||||||
private static final Logger LOG = Logger.getLogger(AbstractAnalyzer.class.getName());
|
private static final Logger LOG = Logger.getLogger(AssemblyAnalyzer.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the beginnings of a List for ProcessBuilder
|
* Builds the beginnings of a List for ProcessBuilder
|
||||||
@@ -113,6 +113,19 @@ public class AssemblyAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
final ProcessBuilder pb = new ProcessBuilder(args);
|
final ProcessBuilder pb = new ProcessBuilder(args);
|
||||||
try {
|
try {
|
||||||
final Process proc = pb.start();
|
final Process proc = pb.start();
|
||||||
|
int rc = 0;
|
||||||
|
try {
|
||||||
|
rc = proc.waitFor();
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (rc == 3) {
|
||||||
|
LOG.info(dependency.getActualFilePath() + " is not a valid assembly");
|
||||||
|
return;
|
||||||
|
} else if (rc != 0) {
|
||||||
|
LOG.warning("Return code " + rc + " from GrokAssembly");
|
||||||
|
}
|
||||||
|
|
||||||
final Document doc = builder.parse(proc.getInputStream());
|
final Document doc = builder.parse(proc.getInputStream());
|
||||||
final XPath xpath = XPathFactory.newInstance().newXPath();
|
final XPath xpath = XPathFactory.newInstance().newXPath();
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -17,14 +17,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.analyzer;
|
package org.owasp.dependencycheck.analyzer;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.junit.Assume.assumeFalse;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import static org.junit.Assume.assumeFalse;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
||||||
@@ -75,7 +78,21 @@ public class AssemblyAnalyzerTest {
|
|||||||
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("GrokAssembly.exe").getPath());
|
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("GrokAssembly.exe").getPath());
|
||||||
Dependency d = new Dependency(f);
|
Dependency d = new Dependency(f);
|
||||||
analyzer.analyze(d, null);
|
analyzer.analyze(d, null);
|
||||||
assertTrue(d.getVersionEvidence().getEvidence().contains(new Evidence("grokassembly", "version", "1.0.5176.23901", Confidence.HIGHEST)));
|
boolean foundVendor = false;
|
||||||
|
for (Evidence e : d.getVendorEvidence().getEvidence("grokassembly", "vendor")) {
|
||||||
|
if ("OWASP".equals(e.getValue())) {
|
||||||
|
foundVendor = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(foundVendor);
|
||||||
|
|
||||||
|
boolean foundProduct = false;
|
||||||
|
for (Evidence e : d.getProductEvidence().getEvidence("grokassembly", "product")) {
|
||||||
|
if ("GrokAssembly".equals(e.getValue())) {
|
||||||
|
foundProduct = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(foundProduct);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,15 +105,29 @@ public class AssemblyAnalyzerTest {
|
|||||||
assertTrue(d.getProductEvidence().getEvidence().contains(new Evidence("grokassembly", "product", "log4net", Confidence.HIGH)));
|
assertTrue(d.getProductEvidence().getEvidence().contains(new Evidence("grokassembly", "product", "log4net", Confidence.HIGH)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = AnalysisException.class)
|
@Test
|
||||||
public void testNonexistent() throws Exception {
|
public void testNonexistent() {
|
||||||
|
Level oldLevel = Logger.getLogger(AssemblyAnalyzer.class.getName()).getLevel();
|
||||||
|
Level oldDependency = Logger.getLogger(Dependency.class.getName()).getLevel();
|
||||||
|
// Tweak the log level so the warning doesn't show in the console
|
||||||
|
Logger.getLogger(AssemblyAnalyzer.class.getName()).setLevel(Level.OFF);
|
||||||
|
Logger.getLogger(Dependency.class.getName()).setLevel(Level.OFF);
|
||||||
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("log4net.dll").getPath());
|
File f = new File(AssemblyAnalyzerTest.class.getClassLoader().getResource("log4net.dll").getPath());
|
||||||
File test = new File(f.getParent(), "nonexistent.dll");
|
File test = new File(f.getParent(), "nonexistent.dll");
|
||||||
Dependency d = new Dependency(test);
|
Dependency d = new Dependency(test);
|
||||||
analyzer.analyze(d, null);
|
|
||||||
|
try {
|
||||||
|
analyzer.analyze(d, null);
|
||||||
|
fail("Expected an AnalysisException");
|
||||||
|
} catch (AnalysisException ae) {
|
||||||
|
assertEquals("File does not exist", ae.getMessage());
|
||||||
|
} finally {
|
||||||
|
Logger.getLogger(AssemblyAnalyzer.class.getName()).setLevel(oldLevel);
|
||||||
|
Logger.getLogger(Dependency.class.getName()).setLevel(oldDependency);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = AnalysisException.class)
|
@Test
|
||||||
public void testWithSettingMono() throws Exception {
|
public void testWithSettingMono() throws Exception {
|
||||||
|
|
||||||
//This test doesn't work on Windows.
|
//This test doesn't work on Windows.
|
||||||
@@ -113,12 +144,20 @@ public class AssemblyAnalyzerTest {
|
|||||||
Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, "/yooser/bine/mono");
|
Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, "/yooser/bine/mono");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Level oldLevel = Logger.getLogger(AssemblyAnalyzer.class.getName()).getLevel();
|
||||||
try {
|
try {
|
||||||
|
// Tweak the logging to swallow the warning when testing
|
||||||
|
Logger.getLogger(AssemblyAnalyzer.class.getName()).setLevel(Level.OFF);
|
||||||
// Have to make a NEW analyzer because during setUp, it would have gotten the correct one
|
// Have to make a NEW analyzer because during setUp, it would have gotten the correct one
|
||||||
AssemblyAnalyzer aanalyzer = new AssemblyAnalyzer();
|
AssemblyAnalyzer aanalyzer = new AssemblyAnalyzer();
|
||||||
aanalyzer.supportsExtension("dll");
|
aanalyzer.supportsExtension("dll");
|
||||||
aanalyzer.initialize();
|
aanalyzer.initialize();
|
||||||
|
fail("Expected an AnalysisException");
|
||||||
|
} catch (AnalysisException ae) {
|
||||||
|
assertEquals("An error occured with the .NET AssemblyAnalyzer", ae.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
// Recover the logger
|
||||||
|
Logger.getLogger(AssemblyAnalyzer.class.getName()).setLevel(oldLevel);
|
||||||
// Now recover the way we came in. If we had to set a System property, delete it. Otherwise,
|
// Now recover the way we came in. If we had to set a System property, delete it. Otherwise,
|
||||||
// reset the old value
|
// reset the old value
|
||||||
if (oldValue == null) {
|
if (oldValue == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user