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.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.owasp.dependencycheck.BaseTest;
24 import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
25 import org.owasp.dependencycheck.dependency.Dependency;
26
27 import java.io.File;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertTrue;
31 import org.owasp.dependencycheck.dependency.Confidence;
32 import org.owasp.dependencycheck.dependency.Evidence;
33 import org.owasp.dependencycheck.dependency.EvidenceType;
34
35
36
37
38
39
40
41
42
43
44
45
46 public class AutoconfAnalyzerTest extends BaseTest {
47
48
49
50
51 private AutoconfAnalyzer analyzer;
52
53
54
55
56
57
58 @Before
59 @Override
60 public void setUp() throws Exception {
61 super.setUp();
62 analyzer = new AutoconfAnalyzer();
63 analyzer.initialize(getSettings());
64 analyzer.setFilesMatched(true);
65 analyzer.prepare(null);
66 }
67
68
69
70
71
72
73 @After
74 @Override
75 public void tearDown() throws Exception {
76 analyzer.close();
77 analyzer = null;
78 super.tearDown();
79 }
80
81
82
83
84
85
86 @Test
87 public void testAnalyzeConfigureAC1() throws AnalysisException {
88 final Dependency result = new Dependency(BaseTest.getResourceAsFile(
89 this, "autoconf/ghostscript/configure.ac"));
90 analyzer.analyze(result, null);
91
92 assertTrue(result.contains(EvidenceType.VENDOR, new Evidence("configure.ac", "Bug report address", "gnu-ghostscript-bug@gnu.org", Confidence.HIGH)));
93 assertTrue(result.contains(EvidenceType.PRODUCT, new Evidence("configure.ac", "Package", "gnu-ghostscript", Confidence.HIGHEST)));
94 assertTrue(result.contains(EvidenceType.VERSION, new Evidence("configure.ac", "Package Version", "8.62.0", Confidence.HIGHEST)));
95 }
96
97
98
99
100
101
102 @Test
103 public void testAnalyzeConfigureAC2() throws AnalysisException {
104 final Dependency result = new Dependency(BaseTest.getResourceAsFile(
105 this, "autoconf/readable-code/configure.ac"));
106 analyzer.analyze(result, null);
107
108 assertTrue(result.contains(EvidenceType.VENDOR, new Evidence("configure.ac", "Bug report address", "dwheeler@dwheeler.com", Confidence.HIGH)));
109 assertTrue(result.contains(EvidenceType.PRODUCT, new Evidence("configure.ac", "Package", "readable", Confidence.HIGHEST)));
110 assertTrue(result.contains(EvidenceType.VERSION, new Evidence("configure.ac", "Package Version", "1.0.7", Confidence.HIGHEST)));
111 assertTrue(result.contains(EvidenceType.VENDOR, new Evidence("configure.ac", "URL", "http://readable.sourceforge.net/", Confidence.HIGH)));
112 }
113
114
115
116
117
118
119 @Test
120 public void testAnalyzeConfigureScript() throws AnalysisException {
121 final Dependency result = new Dependency(BaseTest.getResourceAsFile(
122 this, "autoconf/binutils/configure"));
123 analyzer.analyze(result, null);
124
125 assertTrue(result.contains(EvidenceType.PRODUCT, new Evidence("configure", "NAME", "binutils", Confidence.HIGHEST)));
126 assertTrue(result.contains(EvidenceType.VERSION, new Evidence("configure", "VERSION", "2.25.51", Confidence.HIGHEST)));
127 }
128
129
130
131
132
133
134
135 @Test
136 public void testAnalyzeReadableConfigureScript() throws AnalysisException {
137 final Dependency result = new Dependency(BaseTest.getResourceAsFile(
138 this, "autoconf/readable-code/configure"));
139 analyzer.analyze(result, null);
140
141 assertTrue(result.contains(EvidenceType.VENDOR, new Evidence("configure", "BUGREPORT", "dwheeler@dwheeler.com", Confidence.HIGH)));
142 assertTrue(result.contains(EvidenceType.PRODUCT, new Evidence("configure", "NAME", "readable", Confidence.HIGHEST)));
143 assertTrue(result.contains(EvidenceType.VERSION, new Evidence("configure", "VERSION", "1.0.7", Confidence.HIGHEST)));
144 assertTrue(result.contains(EvidenceType.VENDOR, new Evidence("configure", "URL", "http://readable.sourceforge.net/", Confidence.HIGH)));
145 }
146
147
148
149
150 @Test
151 public void testGetName() {
152 assertEquals("Analyzer name wrong.", "Autoconf Analyzer",
153 analyzer.getName());
154 }
155
156
157
158
159 @Test
160 public void testSupportsFileExtension() {
161 assertTrue("Should support \"ac\" extension.",
162 analyzer.accept(new File("configure.ac")));
163 assertTrue("Should support \"in\" extension.",
164 analyzer.accept(new File("configure.in")));
165 assertTrue("Should support \"configure\" extension.",
166 analyzer.accept(new File("configure")));
167 }
168 }