mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 17:41:28 +01:00
added test case for classpath suppression file and missing file
Former-commit-id: a423b1289f39757645adf4dae0122bc4cee2d1b6
This commit is contained in:
@@ -17,31 +17,84 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.analyzer;
|
package org.owasp.dependencycheck.analyzer;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
import org.owasp.dependencycheck.BaseTest;
|
||||||
|
import org.owasp.dependencycheck.Engine;
|
||||||
|
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
||||||
|
import org.owasp.dependencycheck.dependency.Dependency;
|
||||||
|
import org.owasp.dependencycheck.suppression.SuppressionParseException;
|
||||||
|
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
||||||
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.owasp.dependencycheck.BaseTest;
|
|
||||||
import org.owasp.dependencycheck.Engine;
|
|
||||||
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
|
|
||||||
import org.owasp.dependencycheck.dependency.Dependency;
|
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Jeremy Long <jeremy.long@owasp.org>
|
* @author Jeremy Long <jeremy.long@owasp.org>
|
||||||
*/
|
*/
|
||||||
public class AbstractSuppressionAnalyzerTest extends BaseTest {
|
public class AbstractSuppressionAnalyzerTest extends BaseTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
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
|
||||||
|
public void testFailureToLocateSuppressionFileInClasspath() throws Exception {
|
||||||
|
Settings.setString(Settings.KEYS.SUPPRESSION_FILE, "doesnotexist.xml");
|
||||||
|
exception.expect(SuppressionParseException.class);
|
||||||
|
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 +105,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