Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Hoehl <[email protected]>
  • Loading branch information
Lukas Hoehl committed Oct 27, 2024
1 parent bc4ab4c commit f557457
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/testing/testdata/exampledata/certify-vuln.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"_type": "https://in-toto.io/Statement/v0.1",
"subject": [
{
"uri": "pkg:maven/org.apache.logging.log4j/[email protected]"
}
{
"uri": "pkg:maven/org.apache.logging.log4j/[email protected]"
}
],
"predicateType": "https://in-toto.io/attestation/vulns/v0.1",
"predicate": {
Expand Down
28 changes: 28 additions & 0 deletions pkg/ingestor/parser/vuln/vuln_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestParser(t *testing.T) {
doc *processor.Document
wantCVs []assembler.CertifyVulnIngest
wantIVs []assembler.VulnEqualIngest
wantVMs []assembler.VulnMetadataIngest
wantErr bool
}{{
name: "valid vulnerability certifier document",
Expand Down Expand Up @@ -243,6 +244,18 @@ func TestParser(t *testing.T) {
},
},
},
wantVMs: []assembler.VulnMetadataIngest{
{
Vulnerability: &generated.VulnerabilityInputSpec{
Type: "ghsa",
VulnerabilityID: "ghsa-7rjr-3q55-vv33",
},
VulnMetadata: &generated.VulnerabilityMetadataInputSpec{
ScoreType: generated.VulnerabilityScoreTypeCvssv31,
ScoreValue: 10.0,
},
},
},
wantErr: false,
}, {
name: "no vulnerability certifier document with package digest",
Expand Down Expand Up @@ -287,6 +300,18 @@ func TestParser(t *testing.T) {
})
return out
})

vmSortOpt := cmp.Transformer("Sort", func(in []assembler.VulnMetadataIngest) []assembler.VulnMetadataIngest {
out := append([]assembler.VulnMetadataIngest(nil), in...)
sort.Slice(out, func(i, j int) bool {
return strings.Compare(out[i].Vulnerability.VulnerabilityID, out[j].Vulnerability.VulnerabilityID) > 0
})
return out
})
vmTimeCompareOpt := cmp.Comparer(func(x time.Time, y time.Time) bool {
return true
})

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := NewVulnCertificationParser()
Expand All @@ -304,6 +329,9 @@ func TestParser(t *testing.T) {
if diff := cmp.Diff(tt.wantIVs, ip.VulnEqual, ivSortOpt); diff != "" {
t.Errorf("Unexpected results. (-want +got):\n%s", diff)
}
if diff := cmp.Diff(tt.wantVMs, ip.VulnMetadata, vmSortOpt, vmTimeCompareOpt); diff != "" {
t.Errorf("Unexpected results. (-want +got):\n%s", diff)
}
})
}
}

0 comments on commit f557457

Please sign in to comment.