Skip to content

Commit f2b3f70

Browse files
Merge pull request #1098 from Checkmarx/feature/elchanan/add-sca-dependency-types
Add dev and test dependency flags to SCA results (AST-80203)
2 parents f41476c + 8a48373 commit f2b3f70

4 files changed

Lines changed: 83 additions & 14 deletions

File tree

internal/commands/result.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,11 +1536,13 @@ func parseScaExportPackage(packages []wrappers.ScaPackage) *[]wrappers.ScaPackag
15361536
for _, pkg := range packages {
15371537
pkg := pkg
15381538
scaPackages = append(scaPackages, wrappers.ScaPackageCollection{
1539-
ID: pkg.ID,
1540-
Locations: pkg.Locations,
1541-
DependencyPathArray: parsePackagePathToDependencyPath(&pkg),
1542-
Outdated: pkg.Outdated,
1543-
IsDirectDependency: pkg.IsDirectDependency,
1539+
ID: pkg.ID,
1540+
Locations: pkg.Locations,
1541+
DependencyPathArray: parsePackagePathToDependencyPath(&pkg),
1542+
Outdated: pkg.Outdated,
1543+
IsDirectDependency: pkg.IsDirectDependency,
1544+
IsDevelopmentDependency: pkg.IsDevelopmentDependency,
1545+
IsTestDependency: pkg.IsTestDependency,
15441546
})
15451547
}
15461548
return &scaPackages

internal/commands/result_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,3 +1565,67 @@ func TestRiskManagementHelp(t *testing.T) {
15651565
func TestRiskManagement(t *testing.T) {
15661566
execCmdNilAssertion(t, "results", "risk-management")
15671567
}
1568+
1569+
func Test_addPackageInformation_DependencyTypes(t *testing.T) {
1570+
// Create dependency paths with different types
1571+
var dependencyPaths = [][]wrappers.DependencyPath{
1572+
{{
1573+
ID: "dev-pkg",
1574+
IsDevelopment: true,
1575+
}},
1576+
{{
1577+
ID: "test-pkg",
1578+
IsDevelopment: false,
1579+
}},
1580+
}
1581+
1582+
// Create results model with two results - one dev and one test
1583+
resultsModel := &wrappers.ScanResultsCollection{
1584+
Results: []*wrappers.ScanResult{
1585+
{
1586+
Type: "sca",
1587+
ScanResultData: wrappers.ScanResultData{
1588+
PackageIdentifier: "dev-pkg",
1589+
},
1590+
},
1591+
{
1592+
Type: "sca",
1593+
ScanResultData: wrappers.ScanResultData{
1594+
PackageIdentifier: "test-pkg",
1595+
},
1596+
},
1597+
},
1598+
}
1599+
1600+
// Create package model with different dev/test settings
1601+
scaPackageModel := &[]wrappers.ScaPackageCollection{
1602+
{
1603+
ID: "dev-pkg",
1604+
DependencyPathArray: dependencyPaths[:1],
1605+
IsDevelopmentDependency: true,
1606+
IsTestDependency: false,
1607+
},
1608+
{
1609+
ID: "test-pkg",
1610+
DependencyPathArray: dependencyPaths[1:],
1611+
IsDevelopmentDependency: false,
1612+
IsTestDependency: true,
1613+
},
1614+
}
1615+
1616+
scaTypeModel := &[]wrappers.ScaTypeCollection{{}}
1617+
1618+
// Execute the function
1619+
resultsModel = addPackageInformation(resultsModel, scaPackageModel, scaTypeModel)
1620+
1621+
// Get the results
1622+
devPackage := resultsModel.Results[0].ScanResultData.ScaPackageCollection
1623+
testPackage := resultsModel.Results[1].ScanResultData.ScaPackageCollection
1624+
1625+
// Verify the fields were transferred correctly
1626+
assert.Equal(t, true, devPackage.IsDevelopmentDependency, "First package should be marked as development dependency")
1627+
assert.Equal(t, false, devPackage.IsTestDependency, "First package should not be marked as test dependency")
1628+
1629+
assert.Equal(t, false, testPackage.IsDevelopmentDependency, "Second package should not be marked as development dependency")
1630+
assert.Equal(t, true, testPackage.IsTestDependency, "Second package should be marked as test dependency")
1631+
}

internal/wrappers/export.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ScaPackage struct {
2020
Outdated bool `json:"Outdated,omitempty"`
2121
IsDirectDependency bool `json:"IsDirectDependency"`
2222
IsDevelopmentDependency bool `json:"IsDevelopmentDependency"`
23+
IsTestDependency bool `json:"IsTestDependency"`
2324
SupportsQuickFix bool
2425
FixLink string
2526
TypeOfDependency string

internal/wrappers/results-sca-package.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package wrappers
22

33
type ScaPackageCollection struct {
4-
ID string `json:"id,omitempty"`
5-
FixLink string `json:"fixLink,omitempty"`
6-
BestPackageLink string `json:"bestPackageLink,omitempty"`
7-
Locations []*string `json:"locations,omitempty"`
8-
DependencyPathArray [][]DependencyPath `json:"dependencyPaths,omitempty"`
9-
Outdated bool `json:"outdated,omitempty"`
10-
SupportsQuickFix bool `json:"supportsQuickFix"`
11-
IsDirectDependency bool `json:"isDirectDependency"`
12-
TypeOfDependency string `json:"typeOfDependency"`
4+
ID string `json:"id,omitempty"`
5+
FixLink string `json:"fixLink,omitempty"`
6+
BestPackageLink string `json:"bestPackageLink,omitempty"`
7+
Locations []*string `json:"locations,omitempty"`
8+
DependencyPathArray [][]DependencyPath `json:"dependencyPaths,omitempty"`
9+
Outdated bool `json:"outdated,omitempty"`
10+
SupportsQuickFix bool `json:"supportsQuickFix"`
11+
IsDirectDependency bool `json:"isDirectDependency"`
12+
TypeOfDependency string `json:"typeOfDependency"`
13+
IsDevelopmentDependency bool `json:"isDevelopmentDependency"`
14+
IsTestDependency bool `json:"isTestDependency"`
1315
}
1416

1517
type DependencyPath struct {

0 commit comments

Comments
 (0)