mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-24 18:11:47 +01:00
Merge branch 'bkimminich-master'
Former-commit-id: d4f3bd1ebe5237060251b1f81111b26b5f653f65
This commit is contained in:
@@ -17,31 +17,78 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.analyzer;
|
package org.owasp.dependencycheck.analyzer;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.owasp.dependencycheck.BaseTest;
|
import org.owasp.dependencycheck.BaseTest;
|
||||||
import org.owasp.dependencycheck.Engine;
|
import org.owasp.dependencycheck.Engine;
|
||||||
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
||||||
import org.owasp.dependencycheck.dependency.Dependency;
|
import org.owasp.dependencycheck.dependency.Dependency;
|
||||||
|
import org.owasp.dependencycheck.suppression.SuppressionParseException;
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Jeremy Long <jeremy.long@owasp.org>
|
* @author Jeremy Long <jeremy.long@owasp.org>
|
||||||
*/
|
*/
|
||||||
public class AbstractSuppressionAnalyzerTest extends BaseTest {
|
public class AbstractSuppressionAnalyzerTest extends BaseTest {
|
||||||
|
|
||||||
|
private AbstractSuppressionAnalyzer instance;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void createObjectUnderTest() throws Exception {
|
||||||
|
instance = new AbstractSuppressionAnalyzerImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of getSupportedExtensions method, of class AbstractSuppressionAnalyzer.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetSupportedExtensions() {
|
||||||
|
Set<String> result = instance.getSupportedExtensions();
|
||||||
|
assertNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of getRules method, of class AbstractSuppressionAnalyzer for suppression file declared as URL.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetRulesFromSuppressionFileFromURL() throws Exception {
|
||||||
|
setSupressionFileFromURL();
|
||||||
|
instance.initialize();
|
||||||
|
int expCount = 5;
|
||||||
|
List<SuppressionRule> result = instance.getRules();
|
||||||
|
assertEquals(expCount, result.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of getRules method, of class AbstractSuppressionAnalyzer for suppression file declared as URL.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetRulesFromSuppressionFileInClasspath() throws Exception {
|
||||||
|
Settings.setString(Settings.KEYS.SUPPRESSION_FILE, "suppressions.xml");
|
||||||
|
instance.initialize();
|
||||||
|
int expCount = 5;
|
||||||
|
List<SuppressionRule> result = instance.getRules();
|
||||||
|
assertEquals(expCount, result.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = SuppressionParseException.class)
|
||||||
|
public void testFailureToLocateSuppressionFileAnywhere() throws Exception {
|
||||||
|
Settings.setString(Settings.KEYS.SUPPRESSION_FILE, "doesnotexist.xml");
|
||||||
|
instance.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSupressionFileFromURL() throws Exception {
|
||||||
try {
|
try {
|
||||||
final String uri = this.getClass().getClassLoader().getResource("suppressions.xml").toURI().toURL().toString();
|
final String uri = this.getClass().getClassLoader().getResource("suppressions.xml").toURI().toURL().toString();
|
||||||
Settings.setString(Settings.KEYS.SUPPRESSION_FILE, uri);
|
Settings.setString(Settings.KEYS.SUPPRESSION_FILE, uri);
|
||||||
@@ -52,37 +99,6 @@ public class AbstractSuppressionAnalyzerTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test of getSupportedExtensions method, of class AbstractSuppressionAnalyzer.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetSupportedExtensions() {
|
|
||||||
AbstractSuppressionAnalyzer instance = new AbstractSuppressionAnalyzerImpl();
|
|
||||||
Set<String> result = instance.getSupportedExtensions();
|
|
||||||
assertNull(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test of initialize method, of class AbstractSuppressionAnalyzer.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testInitialize() throws Exception {
|
|
||||||
AbstractSuppressionAnalyzer instance = new AbstractSuppressionAnalyzerImpl();
|
|
||||||
instance.initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test of getRules method, of class AbstractSuppressionAnalyzer.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetRules() throws Exception {
|
|
||||||
AbstractSuppressionAnalyzer instance = new AbstractSuppressionAnalyzerImpl();
|
|
||||||
instance.initialize();
|
|
||||||
int expCount = 5;
|
|
||||||
List<SuppressionRule> result = instance.getRules();
|
|
||||||
assertEquals(expCount, result.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AbstractSuppressionAnalyzerImpl extends AbstractSuppressionAnalyzer {
|
public class AbstractSuppressionAnalyzerImpl extends AbstractSuppressionAnalyzer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user