Skip to content

Commit

Permalink
add unit test coverage on cve submit
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
  • Loading branch information
matthyx committed Apr 4, 2023
1 parent 3faa2d3 commit 72a05e7
Show file tree
Hide file tree
Showing 2 changed files with 390 additions and 10 deletions.
33 changes: 23 additions & 10 deletions adapters/v1/armo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/armosec/utils-k8s-go/armometadata"
"github.com/go-test/deep"
"github.com/google/uuid"
"github.com/kinbiko/jsonassert"
"github.com/kubescape/kubevuln/core/domain"
)

Expand Down Expand Up @@ -100,25 +101,29 @@ func TestArmoAdapter_SubmitCVE(t *testing.T) {
return []armotypes.VulnerabilityExceptionPolicy{}, nil
}
tests := []struct {
name string
cve domain.CVEManifest
cvep domain.CVEManifest
wantErr bool
name string
cve domain.CVEManifest
cvep domain.CVEManifest
checkFullBody bool
checkChunks bool
wantErr bool
}{
{
name: "submit small cve",
cve: fileToCVEManifest("testdata/nginx-cve-small.json"),
cvep: domain.CVEManifest{},
name: "submit small cve",
cve: fileToCVEManifest("testdata/nginx-cve-small.json"),
cvep: domain.CVEManifest{},
checkFullBody: true,
},
{
name: "submit big cve",
cve: fileToCVEManifest("testdata/nginx-cve.json"),
cvep: domain.CVEManifest{},
},
{
name: "submit big cve with relevancy",
cve: fileToCVEManifest("testdata/nginx-cve.json"),
cvep: fileToCVEManifest("testdata/nginx-filtered-cve.json"),
name: "submit big cve with relevancy",
cve: fileToCVEManifest("testdata/nginx-cve.json"),
cvep: fileToCVEManifest("testdata/nginx-filtered-cve.json"),
checkChunks: true,
},
}
for _, tt := range tests {
Expand All @@ -131,6 +136,14 @@ func TestArmoAdapter_SubmitCVE(t *testing.T) {
if err != nil {
t.Errorf("failed to unmarshal report: %v", err)
}
if tt.checkFullBody {
expectedBody, err := os.ReadFile("testdata/cve-body.json")
if err != nil {
t.Errorf("failed to read expected body: %v", err)
}
ja := jsonassert.New(t)
ja.Assertf(string(body), string(expectedBody))
}
mu.Lock()
for _, v := range report.Vulnerabilities {
id := v.Name + "+" + v.RelatedPackageName
Expand Down
Loading

0 comments on commit 72a05e7

Please sign in to comment.