mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
32 lines
1.3 KiB
Go
32 lines
1.3 KiB
Go
|
package protecode
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
var fileContent string
|
||
|
|
||
|
func writeToFileMock(f string, d []byte, p os.FileMode) error {
|
||
|
fileContent = string(d)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func TestWriteReport(t *testing.T) {
|
||
|
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\"}]}"
|
||
|
|
||
|
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
|
||
|
|
||
|
err := WriteReport(ReportData{ServerURL: "DUMMYURL", FailOnSevereVulnerabilities: false, ExcludeCVEs: "", Target: "REPORTFILENAME", ProductID: fmt.Sprintf("%v", 4711), Vulnerabilities: []Vuln{{"Vulnerability", 2.5, "5.5"}}}, ".", "", parsedResult, writeToFileMock)
|
||
|
assert.Equal(t, fileContent, expected, "content should be not empty")
|
||
|
assert.NoError(t, err)
|
||
|
}
|