Skip to content

Commit

Permalink
TC-1642 Fix VulnerabilityID not found (guacsec#128)
Browse files Browse the repository at this point in the history
Signed-off-by: mrizzi <[email protected]>
  • Loading branch information
mrizzi authored Sep 20, 2024
1 parent a577a7b commit 840130f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions demo/graphql/queries-trustification.gql
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,9 @@ query CVE_2023_1664 {
documentRef
}
}

query VulnerabilityIDNotFound {
findTopLevelPackagesRelatedToVulnerability (vulnerabilityID:"CVE") {
__typename
}
}
3 changes: 3 additions & 0 deletions internal/testing/e2e-trustification/e2e
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ diff -u "${SCRIPT_DIR}/expectFindRelatedProductsCount.json" "${GUAC_DIR}/gotFind
cat "$queries" | gql-cli http://localhost:8080/query -o FindRelatedProducts | jq 'del(.. | .id?) | del(.. | .origin?) | .findTopLevelPackagesRelatedToVulnerability[] ' > "${GUAC_DIR}/gotFindRelatedProducts.json"
diff -u <(sort "${SCRIPT_DIR}/expectFindRelatedProducts.json") <(sort "${GUAC_DIR}/gotFindRelatedProducts.json")

cat "$queries" | gql-cli http://localhost:8080/query -o VulnerabilityIDNotFound | jq 'del(.. | .id?) | del(.. | .origin?) | .findTopLevelPackagesRelatedToVulnerability ' > "${GUAC_DIR}/gotVulnerabilityIDNotFound.json"
diff -u "${SCRIPT_DIR}/expectVulnerabilityIDNotFound.json" "${GUAC_DIR}/gotVulnerabilityIDNotFound.json"

cat ./demo/graphql/queries-trustification.gql | gql-cli http://localhost:8080/query -o FindDependentProduct | jq 'del(.. | .id?) | del(.. | .downloadLocation?) | del(.. | .origin?) | .findDependentProduct | sort_by(.digest)' > "${GUAC_DIR}/gotFindDependentProduct.json"
diff -u "${SCRIPT_DIR}/expectFindDependentProduct.json" "${GUAC_DIR}/gotFindDependentProduct.json"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
10 changes: 7 additions & 3 deletions pkg/assembler/backends/ent/backend/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@ func (b *EntBackend) FindTopLevelPackagesRelatedToVulnerability(ctx context.Cont
})
}).
Only(ctx)
if err != nil {
return nil, gqlerror.Errorf("error querying for SBOMs related to %v due to : %v", vulnerabilityID, err)
}
// build the output result backward compatible with the previous version
var result [][]model.Node
if err != nil {
if ent.IsNotFound(err) {
return result, nil
} else {
return nil, gqlerror.Errorf("error querying for SBOMs related to %v due to : %v", vulnerabilityID, err)
}
}
// Vex has priority over Vuln just for consistency with previous implementation, but it could be changed
if len(vulnerability.Edges.Vex) > 0 {
for _, vex := range vulnerability.Edges.Vex {
Expand Down

0 comments on commit 840130f

Please sign in to comment.