-
Notifications
You must be signed in to change notification settings - Fork 529
/
metadata_mock.go
71 lines (65 loc) · 1.64 KB
/
metadata_mock.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
package models
import "github.com/anchore/grype/grype/vulnerability"
var _ vulnerability.MetadataProvider = (*MetadataMock)(nil)
// MetadataMock provides the behavior required for a vulnerability.MetadataProvider for the purpose of testing.
type MetadataMock struct {
store map[string]map[string]vulnerability.Metadata
}
type MockVendorMetadata struct {
BaseSeverity string
Status string
}
// NewMetadataMock returns a new instance of MetadataMock.
func NewMetadataMock() *MetadataMock {
return &MetadataMock{
store: map[string]map[string]vulnerability.Metadata{
"CVE-1999-0001": {
"source-1": {
Description: "1999-01 description",
Severity: "Low",
Cvss: []vulnerability.Cvss{
{
Metrics: vulnerability.CvssMetrics{
BaseScore: 4,
},
Vector: "another vector",
Version: "3.0",
},
},
},
},
"CVE-1999-0002": {
"source-2": {
Description: "1999-02 description",
Severity: "Critical",
Cvss: []vulnerability.Cvss{
{
Metrics: vulnerability.NewCvssMetrics(
1,
2,
3,
),
Vector: "vector",
Version: "2.0",
VendorMetadata: MockVendorMetadata{
BaseSeverity: "Low",
Status: "verified",
},
},
},
},
},
"CVE-1999-0003": {
"source-1": {
Description: "1999-03 description",
Severity: "High",
},
},
},
}
}
// GetMetadata returns vulnerability metadata for a given id and recordSource.
func (m *MetadataMock) GetMetadata(id, namespace string) (*vulnerability.Metadata, error) {
value := m.store[id][namespace]
return &value, nil
}