-
Notifications
You must be signed in to change notification settings - Fork 22
/
enrich_test.go
68 lines (61 loc) · 1.93 KB
/
enrich_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"path/filepath"
"testing"
"github.com/jfrog/jfrog-cli-security/commands/enrich/enrichgraph"
securityTests "github.com/jfrog/jfrog-cli-security/tests"
securityTestUtils "github.com/jfrog/jfrog-cli-security/tests/utils"
"github.com/jfrog/jfrog-cli-security/tests/utils/integration"
securityIntegrationTestUtils "github.com/jfrog/jfrog-cli-security/tests/utils/integration"
"github.com/stretchr/testify/assert"
)
func TestXrayEnrichSbomOutput(t *testing.T) {
integration.InitEnrichTest(t, enrichgraph.EnrichMinimumVersionXray)
securityIntegrationTestUtils.CreateJfrogHomeConfig(t, true)
defer securityTestUtils.CleanTestsHomeEnv()
testCases := []struct {
name string
inputPath string
isXml bool
}{
{
name: "Json format",
inputPath: "enrich.json",
},
{
name: "Xml format",
inputPath: "enrich.xml",
isXml: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
inputPath := filepath.Join(filepath.FromSlash(securityTests.GetTestResourcesPath()), "other", "enrich", tc.inputPath)
output := securityTests.PlatformCli.RunCliCmdWithOutput(t, "sbom-enrich", inputPath)
if tc.isXml {
enrichedSbom := securityTestUtils.UnmarshalXML(t, output)
assert.Greater(t, len(enrichedSbom.Vulnerabilities.Vulnerability), 0)
testVulnerabilities(t, []struct {
BomRef string
Id string
}(enrichedSbom.Vulnerabilities.Vulnerability))
} else {
enrichedSbom := securityTestUtils.UnmarshalJson(t, output)
assert.Greater(t, len(enrichedSbom.Vulnerability), 0)
testVulnerabilities(t, []struct {
BomRef string
Id string
}(enrichedSbom.Vulnerability))
}
})
}
}
func testVulnerabilities(t *testing.T, vulnerabilities []struct {
BomRef string
Id string
}) {
for _, vulnerability := range vulnerabilities {
assert.NotEqual(t, vulnerability.BomRef, nil)
assert.NotEqual(t, vulnerability.Id, nil)
}
}