Skip to content

Commit

Permalink
Handle nil values from Trusty API (#3638)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherias authored and dmjb committed Jun 18, 2024
1 parent d243a44 commit 25d94a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/engine/eval/trusty/trusty.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func readPackageDescription(resp *trustytypes.Reply) map[string]any {

// Ensure don't panic checking all fields are there
for _, fld := range []string{"activity", "provenance"} {
if _, ok := descr[fld]; !ok {
if _, ok := descr[fld]; !ok || descr[fld] == nil {
descr[fld] = float64(0)
}
}
Expand Down
18 changes: 18 additions & 0 deletions internal/engine/eval/trusty/trusty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@ func TestClassifyDependency(t *testing.T) {
},
mustFilter: true,
},
{
name: "nil-activity",
score: &trustytypes.Reply{
PackageName: "test",
PackageType: "npm",
Summary: trustytypes.ScoreSummary{
Score: mkfloat(8.0),
Description: map[string]any{
"provenance": nil,
},
},
},
config: defaultConfig(),
expected: &dependencyAlternatives{
Reasons: []RuleViolationReason{},
},
mustFilter: false,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 25d94a8

Please sign in to comment.