2023-05-03 18:02:11 +02:00
|
|
|
//go:build unit
|
|
|
|
// +build unit
|
|
|
|
|
2020-09-02 10:41:12 +02:00
|
|
|
package protecode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-09-02 10:07:04 +02:00
|
|
|
|
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
2020-09-02 10:41:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestWriteReport(t *testing.T) {
|
2022-03-23 11:02:00 +02:00
|
|
|
files := mock.FilesMock{}
|
|
|
|
|
2022-12-19 19:49:59 +02:00
|
|
|
expected := "{\"target\":\"REPORTFILENAME\",\"mandatory\":true,\"productID\":\"4711\",\"serverUrl\":\"DUMMYURL\",\"count\":\"0\",\"cvss2GreaterOrEqualSeven\":\"4\",\"cvss3GreaterOrEqualSeven\":\"3\",\"excludedVulnerabilities\":\"2\",\"triagedVulnerabilities\":\"0\",\"historicalVulnerabilities\":\"1\",\"Vulnerabilities\":[{\"cve\":\"Vulnerability\",\"cvss\":\"2.5\",\"cvss3_score\":\"5.5\"}]}"
|
2020-09-02 10:41:12 +02:00
|
|
|
|
|
|
|
var parsedResult map[string]int = make(map[string]int)
|
|
|
|
parsedResult["historical_vulnerabilities"] = 1
|
|
|
|
parsedResult["excluded_vulnerabilities"] = 2
|
|
|
|
parsedResult["cvss3GreaterOrEqualSeven"] = 3
|
|
|
|
parsedResult["cvss2GreaterOrEqualSeven"] = 4
|
|
|
|
parsedResult["vulnerabilities"] = 5
|
|
|
|
|
2022-12-19 19:49:59 +02:00
|
|
|
err := WriteReport(ReportData{ServerURL: "DUMMYURL", FailOnSevereVulnerabilities: false, ExcludeCVEs: "", Target: "REPORTFILENAME", ProductID: fmt.Sprintf("%v", 4711), Vulnerabilities: []Vuln{{"Vulnerability", "2.5", "5.5"}}}, ".", "report.json", parsedResult, &files)
|
2022-03-23 11:02:00 +02:00
|
|
|
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
content, err := files.FileRead("report.json")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, string(content))
|
|
|
|
}
|
2020-09-02 10:41:12 +02:00
|
|
|
}
|