Skip to content

Commit

Permalink
fix snyk score
Browse files Browse the repository at this point in the history
  • Loading branch information
mchmarny committed Apr 3, 2023
1 parent 032d8eb commit 56fdc73
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.7
v0.3.8
6 changes: 5 additions & 1 deletion internal/converter/snyk/snyk.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ func mapVulnerability(v *gabs.Container) *data.Vulnerability {
Package: parser.ToString(v.Search("name").Data()),
Version: parser.ToString(v.Search("version").Data()),
Severity: strings.ToLower(parser.ToString(v.Search("severity").Data())),
Score: parser.ToFloat32(c.Search("cvssScore").Data()),
Score: parser.ToFloat32(v.Search("cvssScore").Data()),
IsFixed: parser.ToBool(v.Search("isUpgradable").Data()),
}

if item.Score == 0 {
item.Score = parser.ToFloat32(c.Search("baseScore").Data())
}

return item
}
5 changes: 5 additions & 0 deletions internal/converter/snyk/snyk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ func TestSnykConverter(t *testing.T) {
assert.NotNil(t, list)
assert.Greater(t, len(list), 0)

noScoreCounter := 0
for _, v := range list {
assert.NotEmpty(t, v.ID)
assert.NotEmpty(t, v.Package, v.ID)
assert.NotEmpty(t, v.Severity, v.ID)
assert.NotEmpty(t, v.Version, v.ID)
assert.GreaterOrEqual(t, v.Score, float32(0), v.ID) // some matches won't have score
if v.Score == 0 {
noScoreCounter++
}
}
assert.NotEqual(t, noScoreCounter, len(list))
}

0 comments on commit 56fdc73

Please sign in to comment.