forked from DependencyTrack/dependency-track
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindingTest.java
More file actions
135 lines (123 loc) · 5.69 KB
/
Copy pathFindingTest.java
File metadata and controls
135 lines (123 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* This file is part of Dependency-Track.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.dependencytrack.model;
import org.dependencytrack.PersistenceCapableTest;
import org.dependencytrack.tasks.scanners.AnalyzerIdentity;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
class FindingTest extends PersistenceCapableTest {
private final UUID projectUuid = UUID.randomUUID();
private final Date attributedOn = new Date();
private final Finding finding = new Finding(projectUuid, "component-uuid", "component-name", "component-group",
"component-version", "Required","component-purl", "component-cpe", "vuln-uuid", "vuln-source", "vuln-vulnId", "vuln-title",
"vuln-subtitle", "vuln-description", "vuln-recommendation",
Severity.HIGH, // 14
BigDecimal.valueOf(7.2), // 15
"CVSS:2.0/AV:N/AC:L/Au:N/C:P/I:P/A:P", // 16
BigDecimal.valueOf(8.4), // 17
"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", // 18
BigDecimal.valueOf(9.2), // 19
"CVSS:4.0/...", // 20
BigDecimal.valueOf(1.25), // 21
BigDecimal.valueOf(1.75), // 22
BigDecimal.valueOf(1.3), // 23
"OWASP_VECTOR", // 24
BigDecimal.valueOf(0.5), // 25
BigDecimal.valueOf(0.9), // 26
"787,79", // 27
"vuln-references", // 28
attributedOn, // 29
AnalyzerIdentity.INTERNAL_ANALYZER, // 30
attributedOn, // 31
null, // 32
null, // 33
AnalysisState.NOT_AFFECTED, // 34
true, // 35
"analysis-detail" // 36
);
@Test
void testComponent() {
Map<String, Object> map = finding.getComponent();
Assertions.assertEquals("component-uuid", map.get("uuid"));
Assertions.assertEquals("component-name", map.get("name"));
Assertions.assertEquals("component-group", map.get("group"));
Assertions.assertEquals("component-version", map.get("version"));
Assertions.assertEquals("component-purl", map.get("purl"));
}
@Test
void testVulnerability() {
Map<String, Object> map = finding.getVulnerability();
Assertions.assertEquals("vuln-uuid", map.get("uuid"));
Assertions.assertEquals("vuln-source", map.get("source"));
Assertions.assertEquals("vuln-vulnId", map.get("vulnId"));
Assertions.assertEquals("vuln-title", map.get("title"));
Assertions.assertEquals("vuln-subtitle", map.get("subtitle"));
//Assertions.assertEquals("vuln-description", map.get("description"));
//Assertions.assertEquals("vuln-recommendation", map.get("recommendation"));
Assertions.assertEquals(BigDecimal.valueOf(7.2), map.get("cvssV2BaseScore"));
Assertions.assertEquals("CVSS:2.0/AV:N/AC:L/Au:N/C:P/I:P/A:P", map.get("cvssV2Vector"));
Assertions.assertEquals(BigDecimal.valueOf(8.4), map.get("cvssV3BaseScore"));
Assertions.assertEquals("CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", map.get("cvssV3Vector"));
Assertions.assertEquals(BigDecimal.valueOf(9.2), map.get("cvssV4Score"));
Assertions.assertEquals("CVSS:4.0/...", map.get("cvssV4Vector"));
Assertions.assertEquals(BigDecimal.valueOf(1.25), map.get("owaspLikelihoodScore"));
Assertions.assertEquals(BigDecimal.valueOf(1.75), map.get("owaspTechnicalImpactScore"));
Assertions.assertEquals(BigDecimal.valueOf(1.3), map.get("owaspBusinessImpactScore"));
Assertions.assertEquals("OWASP_VECTOR", map.get("owaspRRVector"));
Assertions.assertEquals(Severity.HIGH.name(), map.get("severity"));
Assertions.assertEquals(1, map.get("severityRank"));
Assertions.assertEquals("vuln-references", map.get("references"));
Assertions.assertEquals(attributedOn, map.get("published"));
}
@Test
void testAnalysis() {
Map<String, Object> map = finding.getAnalysis();
Assertions.assertEquals(AnalysisState.NOT_AFFECTED, map.get("state"));
Assertions.assertEquals(true, map.get("isSuppressed"));
Assertions.assertEquals("analysis-detail", map.get("detail"));
}
@Test
void testMatrix() {
Assertions.assertEquals(projectUuid + ":component-uuid" + ":vuln-uuid", finding.getMatrix());
}
@Test
void testGetCwes() {
assertThat(Finding.getCwes("787,79,,89,"))
.hasSize(3)
.satisfiesExactly(
cwe -> assertThat(cwe.getCweId()).isEqualTo(787),
cwe -> assertThat(cwe.getCweId()).isEqualTo(79),
cwe -> assertThat(cwe.getCweId()).isEqualTo(89)
);
}
@Test
void testGetCwesWhenInputIsEmpty() {
assertThat(Finding.getCwes("")).isNull();
assertThat(Finding.getCwes(",")).isNull();
}
@Test
void testGetCwesWhenInputIsNull() {
assertThat(Finding.getCwes(null)).isNull();
}
}