This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cvss_test.go
190 lines (171 loc) · 5.08 KB
/
cvss_test.go
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package cvss
import "testing"
func TestFromVector(t *testing.T) {
var _, err = Parse("AV:N/AC:H/I:N/A:N")
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
}
func TestFromVectorFails(t *testing.T) {
var _, err = Parse("This is not valid")
if err == nil {
t.Errorf("New from vector should have failed but did not")
}
}
func TestCve_2002_0392_HighEnv(t *testing.T) {
var c, err = Parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
// Temp
c = append(c, ExploitabilityFunctional)
c = append(c, RemediationLevelOfficialFix)
c = append(c, ReportConfidenceConfirmed)
// Env
c = append(c, CollateralDamagePotentialHigh)
c = append(c, TargetDistributionHigh)
c = append(c, ConfidentialityRequirementHigh)
c = append(c, IntegrityRequirementHigh)
c = append(c, AvailabilityRequirementHigh)
s := c.Score()
expected := Score{7.8, 6.4, 9.2}
if s != expected {
t.Errorf("Score differ, expected %v got %v", expected, s)
}
}
func TestCve_2002_0392_LowEnv(t *testing.T) {
var c, err = Parse("AV:N/AC:L/Au:N/C:N/I:N/A:C")
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
// Temp
c = append(c, ExploitabilityFunctional)
c = append(c, RemediationLevelOfficialFix)
c = append(c, ReportConfidenceConfirmed)
// Env
c = append(c, CollateralDamagePotentialNone)
c = append(c, TargetDistributionNone)
c = append(c, ConfidentialityRequirementMedium)
c = append(c, IntegrityRequirementMedium)
c = append(c, AvailabilityRequirementHigh)
s := c.Score()
expected := Score{7.8, 6.4, 0.0}
if s != expected {
t.Errorf("Score differ, expected %v got %v\n%s", expected, s, c.collateralDamagePotential())
}
}
func TestCve_2003_0818_HighEnv(t *testing.T) {
var c, err = Parse("AV:N/AC:L/Au:N/C:C/I:C/A:C")
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
// Temp
c = append(c, ExploitabilityFunctional)
c = append(c, RemediationLevelOfficialFix)
c = append(c, ReportConfidenceConfirmed)
// Env
c = append(c, CollateralDamagePotentialHigh)
c = append(c, TargetDistributionHigh)
c = append(c, ConfidentialityRequirementMedium)
c = append(c, IntegrityRequirementMedium)
c = append(c, AvailabilityRequirementLow)
s := c.Score()
expected := Score{10.0, 8.3, 9.0}
if s != expected {
t.Errorf("Score differ, expected %v got %v", expected, s)
}
}
func TestCve_2003_0818_LowEnv(t *testing.T) {
var c, err = Parse("AV:N/AC:L/Au:N/C:C/I:C/A:C")
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
// Temp
c = append(c, ExploitabilityFunctional)
c = append(c, RemediationLevelOfficialFix)
c = append(c, ReportConfidenceConfirmed)
// Env
c = append(c, CollateralDamagePotentialNone)
c = append(c, TargetDistributionNone)
c = append(c, ConfidentialityRequirementMedium)
c = append(c, IntegrityRequirementMedium)
c = append(c, AvailabilityRequirementLow)
s := c.Score()
expected := Score{10.0, 8.3, 0.0}
if s != expected {
t.Errorf("Score differ, expected %v got %v", expected, s)
}
}
func TestCve_2003_0062_HighEnv(t *testing.T) {
var c, err = Parse("AV:L/AC:H/Au:N/C:C/I:C/A:C")
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
// Temp
c = append(c, ExploitabilityProofOfConcept)
c = append(c, RemediationLevelOfficialFix)
c = append(c, ReportConfidenceConfirmed)
// Env
c = append(c, CollateralDamagePotentialHigh)
c = append(c, TargetDistributionHigh)
c = append(c, ConfidentialityRequirementHigh)
c = append(c, IntegrityRequirementHigh)
c = append(c, AvailabilityRequirementHigh)
s := c.Score()
expected := Score{6.2, 4.9, 7.5}
if s != expected {
t.Errorf("Score differ, expected %v got %v", expected, s)
}
}
func TestCve_2003_0062_LowEnv(t *testing.T) {
var c, err = Parse("AV:L/AC:H/Au:N/C:C/I:C/A:C")
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
// Temp
c = append(c, ExploitabilityProofOfConcept)
c = append(c, RemediationLevelOfficialFix)
c = append(c, ReportConfidenceConfirmed)
// Env
c = append(c, CollateralDamagePotentialNone)
c = append(c, TargetDistributionNone)
c = append(c, ConfidentialityRequirementMedium)
c = append(c, IntegrityRequirementMedium)
c = append(c, AvailabilityRequirementMedium)
s := c.Score()
expected := Score{6.2, 4.9, 0.0}
if s != expected {
t.Errorf("Score differ, expected %v got %v", expected, s)
}
}
func TestToVector(t *testing.T) {
originalVec := "AV:L/AC:H/Au:N/C:C/I:C/A:C"
// We always sort the output to be predictable.
expected := "A:C/AC:H/AV:L/Au:N/C:C/I:C"
var c, err = Parse(originalVec)
if err != nil {
t.Errorf("New from vector failed: %v", err)
}
v := c.ToStringVector()
if v != expected {
t.Errorf("ToVector result differs, expected %v got %v", expected, v)
}
}
func TestToString(t *testing.T) {
s := new(CVSS).String()
if len(s) == 0 {
t.Errorf("Should have produced a string of lenght >0")
}
}
func TestCanParseAllNames(t *testing.T) {
for _, name := range names {
if _, err := Parse(name); err != nil {
t.Errorf("Could not parse name %v", name)
}
}
}
func TestCanParseEmptyVector(t *testing.T) {
if _, err := Parse(""); err != nil {
t.Errorf("Could not parse empty vector")
}
}