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.hamcrest.CoreMatchers.containsString;
30 import static org.hamcrest.CoreMatchers.is;
31 import static org.hamcrest.MatcherAssert.assertThat;
32 import static org.junit.Assert.assertEquals;
33 import org.owasp.dependencycheck.dependency.EvidenceType;
34
35
36
37
38
39
40 public class RubyGemspecAnalyzerTest extends BaseTest {
41
42
43
44
45 private RubyGemspecAnalyzer analyzer;
46
47
48
49
50
51
52 @Before
53 @Override
54 public void setUp() throws Exception {
55 super.setUp();
56 analyzer = new RubyGemspecAnalyzer();
57 analyzer.initialize(getSettings());
58 analyzer.setFilesMatched(true);
59 analyzer.prepare(null);
60 }
61
62
63
64
65
66
67 @After
68 @Override
69 public void tearDown() throws Exception {
70 analyzer.close();
71 super.tearDown();
72 }
73
74
75
76
77 @Test
78 public void testGetName() {
79 assertThat(analyzer.getName(), is("Ruby Gemspec Analyzer"));
80 }
81
82
83
84
85 @Test
86 public void testSupportsFiles() {
87 assertThat(analyzer.accept(new File("test.gemspec")), is(true));
88 assertThat(analyzer.accept(new File("gemspec.lock")), is(false));
89
90 }
91
92
93
94
95
96
97 @Test
98 public void testAnalyzePackageJson() throws AnalysisException {
99 final Dependency result = new Dependency(BaseTest.getResourceAsFile(this,
100 "ruby/vulnerable/gems/specifications/rest-client-1.7.2.gemspec"));
101 analyzer.analyze(result, null);
102 final String vendorString = result.getEvidence(EvidenceType.VENDOR).toString();
103 assertEquals(RubyGemspecAnalyzer.DEPENDENCY_ECOSYSTEM, result.getEcosystem());
104 assertThat(vendorString, containsString("REST Client Team"));
105 assertThat(vendorString, containsString("rest-client_project"));
106 assertThat(vendorString, containsString("rest.client@librelist.com"));
107 assertThat(vendorString, containsString("https://github.com/rest-client/rest-client"));
108 assertThat(result.getEvidence(EvidenceType.PRODUCT).toString(), containsString("rest-client"));
109 assertThat(result.getEvidence(EvidenceType.VERSION).toString(), containsString("1.7.2"));
110 assertEquals("rest-client", result.getName());
111 assertEquals("1.7.2", result.getVersion());
112 assertEquals("rest-client:1.7.2", result.getDisplayFileName());
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 }