1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.analyzer;
19
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.owasp.dependencycheck.BaseTest;
23 import org.owasp.dependencycheck.Engine;
24 import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
25 import org.owasp.dependencycheck.dependency.Dependency;
26 import org.owasp.dependencycheck.suppression.SuppressionParseException;
27 import org.owasp.dependencycheck.suppression.SuppressionRule;
28 import org.owasp.dependencycheck.utils.Settings;
29 import org.slf4j.LoggerFactory;
30
31 import java.net.MalformedURLException;
32 import java.net.URISyntaxException;
33 import java.util.List;
34 import java.util.Set;
35
36 import static org.junit.Assert.assertNull;
37 import static org.junit.Assert.assertTrue;
38
39
40
41
42 public class AbstractSuppressionAnalyzerTest extends BaseTest {
43
44 private AbstractSuppressionAnalyzer instance;
45
46 @Before
47 public void createObjectUnderTest() throws Exception {
48 instance = new AbstractSuppressionAnalyzerImpl();
49 }
50
51
52
53
54 @Test
55 public void testGetSupportedExtensions() {
56 Set<String> result = instance.getSupportedExtensions();
57 assertNull(result);
58 }
59
60
61
62
63 @Test
64 public void testGetRulesFromSuppressionFileFromURL() throws Exception {
65 setSupressionFileFromURL();
66 instance.initialize();
67 int expCount = 5;
68 List<SuppressionRule> result = instance.getRules();
69 assertTrue(expCount <= result.size());
70 }
71
72
73
74
75 @Test
76 public void testGetRulesFromSuppressionFileInClasspath() throws Exception {
77 Settings.setString(Settings.KEYS.SUPPRESSION_FILE, "suppressions.xml");
78 instance.initialize();
79 int expCount = 5;
80 List<SuppressionRule> result = instance.getRules();
81 assertTrue(expCount <= result.size());
82 }
83
84 @Test(expected = SuppressionParseException.class)
85 public void testFailureToLocateSuppressionFileAnywhere() throws Exception {
86 Settings.setString(Settings.KEYS.SUPPRESSION_FILE, "doesnotexist.xml");
87 instance.initialize();
88 }
89
90 private void setSupressionFileFromURL() throws Exception {
91 try {
92 final String uri = this.getClass().getClassLoader().getResource("suppressions.xml").toURI().toURL().toString();
93 Settings.setString(Settings.KEYS.SUPPRESSION_FILE, uri);
94 } catch (URISyntaxException ex) {
95 LoggerFactory.getLogger(AbstractSuppressionAnalyzerTest.class).error("", ex);
96 } catch (MalformedURLException ex) {
97 LoggerFactory.getLogger(AbstractSuppressionAnalyzerTest.class).error("", ex);
98 }
99 }
100
101 public class AbstractSuppressionAnalyzerImpl extends AbstractSuppressionAnalyzer {
102
103 @Override
104 public void analyze(Dependency dependency, Engine engine) throws AnalysisException {
105 throw new UnsupportedOperationException("Not supported yet.");
106 }
107
108 @Override
109 public String getName() {
110 throw new UnsupportedOperationException("Not supported yet.");
111 }
112
113 @Override
114 public AnalysisPhase getAnalysisPhase() {
115 throw new UnsupportedOperationException("Not supported yet.");
116 }
117 }
118
119 }