-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathxrayenrich_test.go
50 lines (43 loc) · 1.84 KB
/
xrayenrich_test.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
package tests
import (
"github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests/xray"
"github.com/jfrog/jfrog-client-go/auth"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
xrayServices "github.com/jfrog/jfrog-client-go/xray/services"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
)
func initXrayEnrichTest(t *testing.T) (xrayServerPort int, xrayDetails auth.ServiceDetails, client *jfroghttpclient.JfrogHttpClient) {
var err error
initXrayTest(t)
xrayServerPort = xray.StartXrayMockServer(t)
xrayDetails = GetXrayDetails()
client, err = jfroghttpclient.JfrogClientBuilder().
SetClientCertPath(xrayDetails.GetClientCertPath()).
SetClientCertKeyPath(xrayDetails.GetClientCertKeyPath()).
AppendPreRequestInterceptor(xrayDetails.RunPreRequestFunctions).
Build()
assert.NoError(t, err)
return
}
func TestIsImportSucceeded(t *testing.T) {
xrayServerPort, xrayDetails, client := initXrayEnrichTest(t)
testsEnrichService := xrayServices.NewEnrichService(client)
testsEnrichService.XrayDetails = xrayDetails
testsEnrichService.XrayDetails.SetUrl("http://localhost:" + strconv.Itoa(xrayServerPort) + "/xray/")
params := xrayServices.XrayGraphImportParams{SBOMInput: []byte("")}
result, err := testsEnrichService.ImportGraph(params, "test")
assert.NoError(t, err)
assert.Equal(t, result, xray.TestMultiScanId)
}
func TestGetImportResults(t *testing.T) {
xrayServerPort, xrayDetails, client := initXrayEnrichTest(t)
testsEnrichService := xrayServices.NewEnrichService(client)
testsEnrichService.XrayDetails = xrayDetails
testsEnrichService.XrayDetails.SetUrl("http://localhost:" + strconv.Itoa(xrayServerPort) + "/xray/")
result, err := testsEnrichService.GetImportGraphResults(xray.TestMultiScanId)
assert.NoError(t, err)
assert.Equal(t, result.ScanId, xray.TestMultiScanId)
assert.Len(t, result.Vulnerabilities, 1)
}