mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
b59bac7892
* fix redundant type issues * cleanup * extract report function for protecode package * use speaking status constant for API results * remove unconsidered return value * correct switch statement * handle severe vulnerabilities * Apply suggestions from code review Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> * correct test name * return errors from WriteReport function * expose ReportData struct * set Error Category * refactor constant visibility * change type name * describe type * change type name * fail after report generation * do not fail on report write errors * add error as return value * fix typo * use require statements * assert major vulnerabilities Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
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)
|
|
}
|