1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.dependency;
19
20 import java.util.Set;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import org.junit.Test;
26 import org.owasp.dependencycheck.BaseTest;
27
28
29
30
31
32 public class VulnerabilityTest extends BaseTest {
33
34
35
36
37 @Test
38 public void testDuplicateVersions() {
39 Vulnerability obj = new Vulnerability();
40
41 obj.addVulnerableSoftware("cpe:/a:mortbay:jetty:6.1.0");
42 obj.addVulnerableSoftware("cpe:/a:mortbay:jetty:6.1.1");
43 obj.addVulnerableSoftware("cpe:/a:mortbay:jetty:6.1.0");
44
45 assertEquals(2, obj.getVulnerableSoftware().size());
46 }
47
48 @Test
49 public void testDpulicateVersionsWithPreviousVersion() {
50 Vulnerability obj = new Vulnerability();
51 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-103%28a%29", null);
52 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-118", null);
53 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.3.132", null);
54 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.12-200", null);
55 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.2-127", null);
56 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.9", null);
57 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.10", null);
58 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.11", null);
59 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.12-118", null);
60 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.4-143", null);
61 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-109", null);
62 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.6-156", null);
63 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.4", null);
64 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.3", null);
65 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1", null);
66 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.10-186", null);
67 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.6", null);
68 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.5", null);
69 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.5-146", null);
70 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.8", null);
71 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.7", null);
72 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.2", null);
73 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.0.2", null);
74 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.1", null);
75 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.8-177", null);
76 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.0.1", null);
77 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.0.0", null);
78 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.7-168", null);
79 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-103", null);
80 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.11-197", null);
81 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.9-178", null);
82 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.12-200", "1");
83 assertEquals(31, obj.getVulnerableSoftware().size());
84 }
85
86 @Test
87 public void testSoftwareSorting() {
88 Vulnerability obj = new Vulnerability();
89 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-103%28a%29", null);
90 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-118", null);
91 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.3.132", null);
92 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.12-200", null);
93 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.2-127", null);
94 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.9", null);
95 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.10", null);
96 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.11", null);
97 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.12-118", null);
98 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.4-143", null);
99 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-109", null);
100 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.6-156", null);
101 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.4", null);
102 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.3", null);
103 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1", null);
104 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.10-186", null);
105 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.6", null);
106 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.5", null);
107 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.5-146", null);
108 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.8", null);
109 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.7", null);
110 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.2", null);
111 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.0.2", null);
112 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.1", null);
113 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.8-177", null);
114 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.0.1", null);
115 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.0.0", null);
116 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.7-168", null);
117 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.0-103", null);
118 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.11-197", null);
119 obj.addVulnerableSoftware("cpe:/a:hp:system_management_homepage:2.1.9-178", null);
120
121 Set<VulnerableSoftware> software = obj.getVulnerableSoftware();
122 VulnerableSoftware vs[] = software.toArray(new VulnerableSoftware[software.size()]);
123
124 assertTrue("cpe:/a:hp:system_management_homepage:2.0.0".equals(vs[0].getName()));
125 assertTrue("cpe:/a:hp:system_management_homepage:2.0.1".equals(vs[1].getName()));
126 assertTrue("cpe:/a:hp:system_management_homepage:2.0.2".equals(vs[2].getName()));
127 assertTrue("cpe:/a:hp:system_management_homepage:2.1".equals(vs[3].getName()));
128 assertTrue("cpe:/a:hp:system_management_homepage:2.1.0-103".equals(vs[4].getName()));
129 assertTrue("cpe:/a:hp:system_management_homepage:2.1.0-103%28a%29".equals(vs[5].getName()));
130 assertTrue("cpe:/a:hp:system_management_homepage:2.1.0-109".equals(vs[6].getName()));
131 assertTrue("cpe:/a:hp:system_management_homepage:2.1.0-118".equals(vs[7].getName()));
132 assertTrue("cpe:/a:hp:system_management_homepage:2.1.1".equals(vs[8].getName()));
133 assertTrue("cpe:/a:hp:system_management_homepage:2.1.2".equals(vs[9].getName()));
134 assertTrue("cpe:/a:hp:system_management_homepage:2.1.2-127".equals(vs[10].getName()));
135 assertTrue("cpe:/a:hp:system_management_homepage:2.1.3".equals(vs[11].getName()));
136 assertTrue("cpe:/a:hp:system_management_homepage:2.1.3.132".equals(vs[12].getName()));
137 assertTrue("cpe:/a:hp:system_management_homepage:2.1.4".equals(vs[13].getName()));
138 assertTrue("cpe:/a:hp:system_management_homepage:2.1.4-143".equals(vs[14].getName()));
139 assertTrue("cpe:/a:hp:system_management_homepage:2.1.5".equals(vs[15].getName()));
140 assertTrue("cpe:/a:hp:system_management_homepage:2.1.5-146".equals(vs[16].getName()));
141 assertTrue("cpe:/a:hp:system_management_homepage:2.1.6".equals(vs[17].getName()));
142 assertTrue("cpe:/a:hp:system_management_homepage:2.1.6-156".equals(vs[18].getName()));
143 assertTrue("cpe:/a:hp:system_management_homepage:2.1.7".equals(vs[19].getName()));
144 assertTrue("cpe:/a:hp:system_management_homepage:2.1.7-168".equals(vs[20].getName()));
145 assertTrue("cpe:/a:hp:system_management_homepage:2.1.8".equals(vs[21].getName()));
146 assertTrue("cpe:/a:hp:system_management_homepage:2.1.8-177".equals(vs[22].getName()));
147 assertTrue("cpe:/a:hp:system_management_homepage:2.1.9".equals(vs[23].getName()));
148 assertTrue("cpe:/a:hp:system_management_homepage:2.1.9-178".equals(vs[24].getName()));
149 assertTrue("cpe:/a:hp:system_management_homepage:2.1.10".equals(vs[25].getName()));
150 assertTrue("cpe:/a:hp:system_management_homepage:2.1.10-186".equals(vs[26].getName()));
151 assertTrue("cpe:/a:hp:system_management_homepage:2.1.11".equals(vs[27].getName()));
152 assertTrue("cpe:/a:hp:system_management_homepage:2.1.11-197".equals(vs[28].getName()));
153 assertTrue("cpe:/a:hp:system_management_homepage:2.1.12-118".equals(vs[29].getName()));
154 assertTrue("cpe:/a:hp:system_management_homepage:2.1.12-200".equals(vs[30].getName()));
155
156 }
157
158 }