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 import org.owasp.dependencycheck.dependency.Evidence;
27
28 import java.io.File;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32
33
34
35
36
37
38 public class PythonPackageAnalyzerTest extends BaseTest {
39
40
41
42
43 private PythonPackageAnalyzer analyzer;
44
45
46
47
48
49
50 @Before
51 public void setUp() throws Exception {
52 analyzer = new PythonPackageAnalyzer();
53 analyzer.setFilesMatched(true);
54 analyzer.initialize();
55 }
56
57
58
59
60
61
62 @After
63 public void tearDown() throws Exception {
64 analyzer.close();
65 analyzer = null;
66 }
67
68
69
70
71 @Test
72 public void testGetName() {
73 assertEquals("Analyzer name wrong.", "Python Package Analyzer",
74 analyzer.getName());
75 }
76
77
78
79
80 @Test
81 public void testSupportsFileExtension() {
82 assertTrue("Should support \"py\" extension.",
83 analyzer.accept(new File("test.py")));
84 }
85
86 @Test
87 public void testAnalyzeSourceMetadata() throws AnalysisException {
88 boolean found = false;
89 final Dependency result = new Dependency(BaseTest.getResourceAsFile(
90 this, "python/eggtest/__init__.py"));
91 analyzer.analyze(result, null);
92 assertTrue("Expected vendor evidence to contain \"example\".", result
93 .getVendorEvidence().toString().contains("example"));
94 for (final Evidence e : result.getVersionEvidence()) {
95 if ("0.0.1".equals(e.getValue())) {
96 found = true;
97 break;
98 }
99 }
100 assertTrue("Version 0.0.1 not found in EggTest dependency.", found);
101 }
102
103 }