/
junit.go
54 lines (49 loc) · 1.26 KB
/
junit.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
package security
import (
"encoding/xml"
"fmt"
)
type testsuites struct {
XMLName xml.Name `xml:"testsuites"`
Name string `xml:"name,attr"`
Testsuites []testsuite
}
type testsuite struct {
XMLName xml.Name `xml:"testsuite"`
Package string `xml:"package,attr"`
Errors int `xml:"errors,attr"`
Failures int `xml:"failures,attr"`
Tests int `xml:"tests,attr"`
Testcases []testcase
}
type testcase struct {
XMLName xml.Name `xml:"testcase"`
Name string `xml:"name,attr"`
Classname string `xml:"classname,attr"`
Failure []string `xml:"failure,omitempty"`
}
func ToJunit(vulns *Vulnerabilities) ([]byte, error) {
var packages []testsuite
var cases []testcase
ts := testsuite{}
for _, pkg := range vulns.Keys() {
v := vulns.Get(pkg)
tc := testcase{
Classname: "packages",
Name: fmt.Sprintf("%s (%s)", pkg, v.Version),
}
for _, a := range v.Advisories {
tc.Failure = append(tc.Failure, fmt.Sprintf("%s - %s (%s)", a.CVE, a.Title, a.Link))
}
cases = append(cases, tc)
ts.Failures++
ts.Tests++
}
ts.Testcases = cases
packages = append(packages, ts)
out := testsuites{
Name: "Symfony Security Check Report",
Testsuites: packages,
}
return xml.MarshalIndent(&out, " ", " ")
}