Skip to content

Commit

Permalink
Merge pull request #682 from Checkmarx/bug/elchanan/up-fixlink
Browse files Browse the repository at this point in the history
Fix "About this vulnerability" link (AST-35994)
  • Loading branch information
elchananarb authored Mar 27, 2024
2 parents 7e1396b + e1bd993 commit d153d73
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/commands/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -1797,11 +1797,11 @@ func addPackageInformation(
head.SupportsQuickFix = head.SupportsQuickFix && util.IsPackageFileSupported(*location)
}
currentPackage.SupportsQuickFix = currentPackage.SupportsQuickFix || head.SupportsQuickFix
}
if result.VulnerabilityDetails.CveName != "" {
currentPackage.FixLink = "https://devhub.checkmarx.com/cve-details/" + result.VulnerabilityDetails.CveName
} else {
currentPackage.FixLink = ""
if result.ID != "" {
currentPackage.FixLink = "https://devhub.checkmarx.com/cve-details/" + result.ID
} else {
currentPackage.FixLink = ""
}
}
if currentPackage.IsDirectDependency {
currentPackage.TypeOfDependency = directDependencyType
Expand Down
35 changes: 35 additions & 0 deletions internal/commands/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,38 @@ func TestRunGetResultsByScanIdGLFormat(t *testing.T) {
// Run test for gl-sast report type
os.Remove(fmt.Sprintf("%s.%s", fileName, printer.FormatGL))
}

func Test_addPackageInformation(t *testing.T) {
var dependencyPath = wrappers.DependencyPath{ID: "test-1"}
var dependencyArray = [][]wrappers.DependencyPath{{dependencyPath}}
resultsModel := &wrappers.ScanResultsCollection{
Results: []*wrappers.ScanResult{
{
Type: "sca", // Assuming this matches commonParams.ScaType
ScanResultData: wrappers.ScanResultData{
PackageIdentifier: "pkg-123",
},
ID: "CVE-2021-23-424",
VulnerabilityDetails: wrappers.VulnerabilityDetails{
CvssScore: 5.0,
CveName: "cwe-789",
},
},
},
}
scaPackageModel := &[]wrappers.ScaPackageCollection{
{
ID: "pkg-123",
FixLink: "",
DependencyPathArray: dependencyArray,
},
}
scaTypeModel := &[]wrappers.ScaTypeCollection{
{}}

resultsModel = addPackageInformation(resultsModel, scaPackageModel, scaTypeModel)

expectedFixLink := "https://devhub.checkmarx.com/cve-details/CVE-2021-23-424"
actualFixLink := resultsModel.Results[0].ScanResultData.ScaPackageCollection.FixLink
assert.Equal(t, expectedFixLink, actualFixLink, "FixLink should match the result ID")
}

0 comments on commit d153d73

Please sign in to comment.