Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Third party dependencies contextual analysis for npm #941

Merged
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
ccb5c4f
Improve audit data handling
attiasas Sep 6, 2023
ccc3379
Merge remote-tracking branch 'upstream/dev' into refactor_handle_scan…
attiasas Sep 6, 2023
c0cb84f
resolve conflicts
attiasas Sep 6, 2023
ff11b5d
fix tests
attiasas Sep 6, 2023
ffce12b
fix static tests
attiasas Sep 6, 2023
bace6ff
finish convert xray results to sarif
attiasas Sep 6, 2023
7ee9b55
Merge remote-tracking branch 'upstream/dev' into refactor_handle_scan…
attiasas Sep 6, 2023
9024c73
hard coded exclude
EyalDelarea Sep 7, 2023
9e23c46
pull assaf's sarif PR
EyalDelarea Sep 7, 2023
633b93c
more sarif utils
attiasas Sep 7, 2023
852a378
fix static tests
attiasas Sep 7, 2023
e80a2e7
Merge remote-tracking branch 'upstream/dev' into refactor_handle_scan…
attiasas Sep 7, 2023
18e4c3f
format
attiasas Sep 7, 2023
60a9327
fix tests
attiasas Sep 7, 2023
73de66f
fix tests
attiasas Sep 7, 2023
a08da44
fix tests
attiasas Sep 7, 2023
c7c68d2
cleanup
attiasas Sep 8, 2023
d88a09c
fix tests
attiasas Sep 8, 2023
b62cbe7
review changes
attiasas Sep 8, 2023
1fafae7
fix tests
attiasas Sep 8, 2023
8fd9fa4
review changes, add more sarif utils
attiasas Sep 9, 2023
a3141fa
format
attiasas Sep 9, 2023
7d1ac5c
fix invocation to sast
attiasas Sep 9, 2023
d49a657
more Sarif utils
attiasas Sep 9, 2023
54a7fa3
more Sarif utils
attiasas Sep 9, 2023
d8a90af
more sarif utils
attiasas Sep 10, 2023
ce2c2a2
pull dev
EyalDelarea Sep 10, 2023
0907b3c
pull asaffa branch
EyalDelarea Sep 10, 2023
75fa7b2
fix generate applic map
attiasas Sep 10, 2023
84789ef
review changes
attiasas Sep 10, 2023
3374ca8
set results not append
attiasas Sep 10, 2023
433b65f
stash
EyalDelarea Sep 10, 2023
9848b7e
review changes
attiasas Sep 10, 2023
4e6fca9
Merge remote-tracking branch 'upstream/dev' into refactor_handle_scan…
attiasas Sep 10, 2023
56b8322
fix static
attiasas Sep 10, 2023
3ca4db4
create properties if not exists
attiasas Sep 10, 2023
33fd368
stash
EyalDelarea Sep 10, 2023
59f6174
merge
EyalDelarea Sep 10, 2023
78ec95b
clean up
attiasas Sep 10, 2023
cd1fb68
fix bugs
attiasas Sep 10, 2023
fad0c0a
format
attiasas Sep 10, 2023
4de5e01
fix tests
attiasas Sep 10, 2023
0f31707
fix diff
attiasas Sep 10, 2023
71e275e
fix diff
attiasas Sep 10, 2023
749d07b
fix diff
attiasas Sep 10, 2023
72a1f09
fix tests
attiasas Sep 10, 2023
92d75dd
format
attiasas Sep 10, 2023
29d608d
Merge branch 'refactor_handle_scan_results' of https://github.com/att…
EyalDelarea Sep 10, 2023
af05d37
working hardcoded
EyalDelarea Sep 10, 2023
3bd985f
pull dev
EyalDelarea Sep 10, 2023
2b65639
refactor
EyalDelarea Sep 10, 2023
e07c2d1
fix tests
EyalDelarea Sep 10, 2023
b6f1f75
fix tests
EyalDelarea Sep 10, 2023
cedde6c
Edit comments
EyalDelarea Sep 10, 2023
68423a5
break loop if not in npm
EyalDelarea Sep 10, 2023
0960ece
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-core into in…
EyalDelarea Sep 11, 2023
ba31175
change flag name
EyalDelarea Sep 11, 2023
ad5ad84
renames
EyalDelarea Sep 11, 2023
e8ade07
Fix comments
EyalDelarea Sep 11, 2023
ace0616
pull dev
EyalDelarea Sep 11, 2023
0fcb045
pull dev
EyalDelarea Sep 11, 2023
8f4ff19
pull dev
EyalDelarea Sep 12, 2023
d860501
add tests
EyalDelarea Sep 12, 2023
037da70
refactor test
EyalDelarea Sep 12, 2023
74df977
add comments
EyalDelarea Sep 12, 2023
d0acaf9
CR
EyalDelarea Sep 12, 2023
196aae5
CR
EyalDelarea Sep 12, 2023
84511b4
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-core into in…
EyalDelarea Sep 12, 2023
eb631dc
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-core into in…
EyalDelarea Sep 13, 2023
5c99075
Pass flatten graph instead of including indirects dependencies
EyalDelarea Sep 13, 2023
afc4d6f
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-core into in…
EyalDelarea Sep 13, 2023
1088594
Add comments
EyalDelarea Sep 13, 2023
04432bf
CR
EyalDelarea Sep 13, 2023
f51094d
CR
EyalDelarea Sep 13, 2023
03a3707
Fix import cycle
EyalDelarea Sep 13, 2023
228cc94
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-core into in…
EyalDelarea Sep 13, 2023
8488830
Fix imports
EyalDelarea Sep 13, 2023
81a34ed
CR
EyalDelarea Sep 13, 2023
5b50d24
CR
EyalDelarea Sep 13, 2023
b5a1920
CR
EyalDelarea Sep 13, 2023
406ecd6
pull dev
EyalDelarea Sep 13, 2023
39f88fa
When the flag is on, only applicability scanner will exec
EyalDelarea Sep 13, 2023
e1a8177
Edit comment
EyalDelarea Sep 13, 2023
741f55b
cr
EyalDelarea Sep 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions xray/commands/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func (auditCmd *AuditCommand) Run() (err error) {
SetWorkingDirs(workingDirs).
SetMinSeverityFilter(auditCmd.minSeverityFilter).
SetFixableOnly(auditCmd.fixableOnly).
SetGraphBasicParams(auditCmd.AuditBasicParams)
SetGraphBasicParams(auditCmd.AuditBasicParams).
SetThirdPartyApplicabilityScan(auditCmd.thirdPartyApplicabilityScan)
auditResults, err := RunAudit(auditParams)
if err != nil {
return
Expand Down Expand Up @@ -186,7 +187,7 @@ func RunAudit(auditParams *AuditParams) (results *Results, err error) {

// Run scanners only if the user is entitled for Advanced Security
if results.ExtendedScanResults.EntitledForJas {
results.JasError = runJasScannersAndSetResults(results.ExtendedScanResults, auditParams.DirectDependencies(), serverDetails, auditParams.workingDirs, auditParams.Progress(), auditParams.xrayGraphScanParams.MultiScanId)
results.JasError = runJasScannersAndSetResults(results.ExtendedScanResults, auditParams.DirectDependencies(), serverDetails, auditParams.workingDirs, auditParams.Progress(), auditParams.xrayGraphScanParams.MultiScanId, auditParams.thirdPartyApplicabilityScan)
}
return
}
Expand Down
7 changes: 7 additions & 0 deletions xray/commands/audit/auditparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type AuditParams struct {
minSeverityFilter string
*xrayutils.AuditBasicParams
xrayVersion string
// Include third party dependencies source code in the applicability scan.
thirdPartyApplicabilityScan bool
}

func NewAuditParams() *AuditParams {
Expand Down Expand Up @@ -75,3 +77,8 @@ func (params *AuditParams) SetMinSeverityFilter(minSeverityFilter string) *Audit
params.minSeverityFilter = minSeverityFilter
return params
}

func (params *AuditParams) SetThirdPartyApplicabilityScan(includeThirdPartyDeps bool) *AuditParams {
params.thirdPartyApplicabilityScan = includeThirdPartyDeps
return params
}
23 changes: 19 additions & 4 deletions xray/commands/audit/jas/applicability/applicabilitymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type ApplicabilityScanManager struct {
directDependenciesCves []string
xrayResults []services.ScanResponse
scanner *jas.JasScanner
thirdPartyScan bool
}

// The getApplicabilityScanResults function runs the applicability scan flow, which includes the following steps:
Expand All @@ -37,8 +38,8 @@ type ApplicabilityScanManager struct {
// bool: true if the user is entitled to the applicability scan, false otherwise.
// error: An error object (if any).
func RunApplicabilityScan(xrayResults []services.ScanResponse, directDependencies []string,
scannedTechnologies []coreutils.Technology, scanner *jas.JasScanner) (results []*sarif.Run, err error) {
applicabilityScanManager := newApplicabilityScanManager(xrayResults, directDependencies, scanner)
scannedTechnologies []coreutils.Technology, scanner *jas.JasScanner, thirdPartyContextualAnalysis bool) (results []*sarif.Run, err error) {
applicabilityScanManager := newApplicabilityScanManager(xrayResults, directDependencies, scanner, thirdPartyContextualAnalysis)
if !applicabilityScanManager.shouldRunApplicabilityScan(scannedTechnologies) {
log.Debug("The technologies that have been scanned are currently not supported for contextual analysis scanning, or we couldn't find any vulnerable direct dependencies. Skipping....")
return
Expand All @@ -51,13 +52,14 @@ func RunApplicabilityScan(xrayResults []services.ScanResponse, directDependencie
return
}

func newApplicabilityScanManager(xrayScanResults []services.ScanResponse, directDependencies []string, scanner *jas.JasScanner) (manager *ApplicabilityScanManager) {
func newApplicabilityScanManager(xrayScanResults []services.ScanResponse, directDependencies []string, scanner *jas.JasScanner, thirdPartyScan bool) (manager *ApplicabilityScanManager) {
directDependenciesCves := extractDirectDependenciesCvesFromScan(xrayScanResults, directDependencies)
return &ApplicabilityScanManager{
applicabilityScanResults: []*sarif.Run{},
directDependenciesCves: directDependenciesCves,
xrayResults: xrayScanResults,
scanner: scanner,
thirdPartyScan: thirdPartyScan,
}
}

Expand Down Expand Up @@ -140,6 +142,11 @@ type scanConfiguration struct {
}

func (asm *ApplicabilityScanManager) createConfigFile(workingDir string) error {
skipDirs := jas.SkippedDirs
if asm.thirdPartyScan {
log.Info("Including node modules folder in applicability scan")
skipDirs = removeElementFromSlice(skipDirs, jas.NodeModulesPattern)
}
configFileContent := applicabilityScanConfig{
Scans: []scanConfiguration{
{
Expand All @@ -148,7 +155,7 @@ func (asm *ApplicabilityScanManager) createConfigFile(workingDir string) error {
Type: applicabilityScanType,
GrepDisable: false,
CveWhitelist: asm.directDependenciesCves,
SkippedDirs: jas.SkippedDirs,
SkippedDirs: skipDirs,
},
},
}
Expand All @@ -160,3 +167,11 @@ func (asm *ApplicabilityScanManager) createConfigFile(workingDir string) error {
func (asm *ApplicabilityScanManager) runAnalyzerManager() error {
return asm.scanner.AnalyzerManager.Exec(asm.scanner.ConfigFileName, applicabilityScanCommand, filepath.Dir(asm.scanner.AnalyzerManager.AnalyzerManagerFullPath), asm.scanner.ServerDetails)
}

func removeElementFromSlice(skipDirs []string, element string) []string {
deleteIndex := slices.Index(skipDirs, element)
if deleteIndex == -1 {
return skipDirs
}
return slices.Delete(skipDirs, deleteIndex, deleteIndex+1)
}
32 changes: 18 additions & 14 deletions xray/commands/audit/jas/applicability/applicabilitymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestNewApplicabilityScanManager_InputIsValid(t *testing.T) {
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()
// Act
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner, false)

// Assert
if assert.NotNil(t, applicabilityManager) {
Expand All @@ -31,7 +31,7 @@ func TestNewApplicabilityScanManager_DependencyTreeDoesntExist(t *testing.T) {
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()
// Act
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, nil, scanner)
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, nil, scanner, false)

// Assert
if assert.NotNil(t, applicabilityManager) {
Expand Down Expand Up @@ -68,9 +68,14 @@ func TestNewApplicabilityScanManager_NoDirectDependenciesInScan(t *testing.T) {
// Act
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()
applicabilityManager := newApplicabilityScanManager(noDirectDependenciesResults, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(noDirectDependenciesResults, mockDirectDependencies, scanner, false)
assertApplicabilityScanner(t, applicabilityManager)
// ThirdPartyContextual shouldn't change anything here as this is not npm.
applicabilityManager = newApplicabilityScanManager(noDirectDependenciesResults, mockDirectDependencies, scanner, true)
assertApplicabilityScanner(t, applicabilityManager)
}

// Assert
func assertApplicabilityScanner(t *testing.T, applicabilityManager *ApplicabilityScanManager) {
if assert.NotNil(t, applicabilityManager) {
assert.NotEmpty(t, applicabilityManager.scanner.ConfigFileName)
assert.NotEmpty(t, applicabilityManager.scanner.ResultsFileName)
Expand All @@ -84,7 +89,7 @@ func TestNewApplicabilityScanManager_MultipleDependencyTrees(t *testing.T) {
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()
// Act
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockMultiRootDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockMultiRootDirectDependencies, scanner, false)

// Assert
if assert.NotNil(t, applicabilityManager) {
Expand All @@ -110,7 +115,7 @@ func TestNewApplicabilityScanManager_ViolationsDontExistInResults(t *testing.T)
defer cleanUp()

// Act
applicabilityManager := newApplicabilityScanManager(noViolationScanResponse, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(noViolationScanResponse, mockDirectDependencies, scanner, false)

// Assert
if assert.NotNil(t, applicabilityManager) {
Expand All @@ -136,7 +141,7 @@ func TestNewApplicabilityScanManager_VulnerabilitiesDontExist(t *testing.T) {
defer cleanUp()

// Act
applicabilityManager := newApplicabilityScanManager(noVulnerabilitiesScanResponse, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(noVulnerabilitiesScanResponse, mockDirectDependencies, scanner, false)

// Assert
if assert.NotNil(t, applicabilityManager) {
Expand All @@ -150,8 +155,7 @@ func TestApplicabilityScanManager_ShouldRun_TechnologiesNotEligibleForScan(t *te
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()

results, err := RunApplicabilityScan(jas.FakeBasicXrayResults, mockDirectDependencies,
[]coreutils.Technology{coreutils.Nuget, coreutils.Go}, scanner)
results, err := RunApplicabilityScan(jas.FakeBasicXrayResults, mockDirectDependencies, []coreutils.Technology{coreutils.Nuget, coreutils.Go}, scanner, false)

// Assert
assert.Nil(t, results)
Expand All @@ -163,7 +167,7 @@ func TestApplicabilityScanManager_ShouldRun_ScanResultsAreEmpty(t *testing.T) {
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()

applicabilityManager := newApplicabilityScanManager(nil, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(nil, mockDirectDependencies, scanner, false)

// Assert
eligible := applicabilityManager.shouldRunApplicabilityScan([]coreutils.Technology{coreutils.Npm})
Expand Down Expand Up @@ -247,7 +251,7 @@ func TestCreateConfigFile_VerifyFileWasCreated(t *testing.T) {
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()

applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, []string{"issueId_1_direct_dependency", "issueId_2_direct_dependency"}, scanner)
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, []string{"issueId_1_direct_dependency", "issueId_2_direct_dependency"}, scanner, false)

currWd, err := coreutils.GetWorkingDirectory()
assert.NoError(t, err)
Expand All @@ -271,7 +275,7 @@ func TestParseResults_EmptyResults_AllCvesShouldGetUnknown(t *testing.T) {
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()

applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner, false)
applicabilityManager.scanner.ResultsFileName = filepath.Join(jas.GetTestDataPath(), "applicability-scan", "empty-results.sarif")

// Act
Expand All @@ -288,7 +292,7 @@ func TestParseResults_ApplicableCveExist(t *testing.T) {
// Arrange
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner, false)
applicabilityManager.scanner.ResultsFileName = filepath.Join(jas.GetTestDataPath(), "applicability-scan", "applicable-cve-results.sarif")

// Act
Expand All @@ -305,7 +309,7 @@ func TestParseResults_AllCvesNotApplicable(t *testing.T) {
// Arrange
scanner, cleanUp := jas.InitJasTest(t)
defer cleanUp()
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner)
applicabilityManager := newApplicabilityScanManager(jas.FakeBasicXrayResults, mockDirectDependencies, scanner, false)
applicabilityManager.scanner.ResultsFileName = filepath.Join(jas.GetTestDataPath(), "applicability-scan", "no-applicable-cves-results.sarif")

// Act
Expand Down
6 changes: 5 additions & 1 deletion xray/commands/audit/jas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ import (
"gopkg.in/yaml.v3"
)

const (
NodeModulesPattern = "**/*node_modules*/**"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NodeModulesPattern = "**/*node_modules*/**"
nodeModulesPattern = "**/*node_modules*/**"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

been used from applicablitymanager.go so has to be public

)

var (
SkippedDirs = []string{"**/*test*/**", "**/*venv*/**", "**/*node_modules*/**", "**/*target*/**"}
SkippedDirs = []string{"**/*test*/**", "**/*venv*/**", NodeModulesPattern, "**/*target*/**"}

mapSeverityToScore = map[string]string{
"": "0.0",
Expand Down
4 changes: 2 additions & 2 deletions xray/commands/audit/jasrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func runJasScannersAndSetResults(scanResults *utils.ExtendedScanResults, directDependencies []string,
serverDetails *config.ServerDetails, workingDirs []string, progress io.ProgressMgr, multiScanId string) (err error) {
serverDetails *config.ServerDetails, workingDirs []string, progress io.ProgressMgr, multiScanId string, thirdPartyContextualAnalysis bool) (err error) {
if serverDetails == nil || len(serverDetails.Url) == 0 {
log.Warn("To include 'Advanced Security' scan as part of the audit output, please run the 'jf c add' command before running this command.")
return
Expand All @@ -30,7 +30,7 @@ func runJasScannersAndSetResults(scanResults *utils.ExtendedScanResults, directD
if progress != nil {
progress.SetHeadlineMsg("Running applicability scanning")
}
scanResults.ApplicabilityScanResults, err = applicability.RunApplicabilityScan(scanResults.XrayResults, directDependencies, scanResults.ScannedTechnologies, scanner)
scanResults.ApplicabilityScanResults, err = applicability.RunApplicabilityScan(scanResults.XrayResults, directDependencies, scanResults.ScannedTechnologies, scanner, thirdPartyContextualAnalysis)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions xray/commands/audit/jasrunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ func TestGetExtendedScanResults_AnalyzerManagerDoesntExist(t *testing.T) {
assert.NoError(t, os.Unsetenv(coreutils.HomeDir))
}()
scanResults := &utils.ExtendedScanResults{XrayResults: jas.FakeBasicXrayResults, ScannedTechnologies: []coreutils.Technology{coreutils.Yarn}}
err = runJasScannersAndSetResults(scanResults, []string{"issueId_1_direct_dependency", "issueId_2_direct_dependency"}, &jas.FakeServerDetails, nil, nil, "")
err = runJasScannersAndSetResults(scanResults, []string{"issueId_1_direct_dependency", "issueId_2_direct_dependency"}, &jas.FakeServerDetails, nil, nil, "", false)
// Expect error:
assert.Error(t, err)
}

func TestGetExtendedScanResults_ServerNotValid(t *testing.T) {
scanResults := &utils.ExtendedScanResults{XrayResults: jas.FakeBasicXrayResults, ScannedTechnologies: []coreutils.Technology{coreutils.Pip}}
err := runJasScannersAndSetResults(scanResults, []string{"issueId_1_direct_dependency", "issueId_2_direct_dependency"}, nil, nil, nil, "")
err := runJasScannersAndSetResults(scanResults, []string{"issueId_1_direct_dependency", "issueId_2_direct_dependency"}, nil, nil, nil, "", false)
assert.NoError(t, err)
}

func TestGetExtendedScanResults_AnalyzerManagerReturnsError(t *testing.T) {
mockDirectDependencies := []string{"issueId_2_direct_dependency", "issueId_1_direct_dependency"}
assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded())
scanResults := &utils.ExtendedScanResults{XrayResults: jas.FakeBasicXrayResults, ScannedTechnologies: []coreutils.Technology{coreutils.Yarn}}
err := runJasScannersAndSetResults(scanResults, mockDirectDependencies, &jas.FakeServerDetails, nil, nil, "")
err := runJasScannersAndSetResults(scanResults, mockDirectDependencies, &jas.FakeServerDetails, nil, nil, "", false)

// Expect error:
assert.ErrorContains(t, err, "failed to run Applicability scan")
Expand Down
10 changes: 5 additions & 5 deletions xray/commands/audit/sca/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
buildinfo "github.com/jfrog/build-info-go/entities"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit/sca"
"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
"github.com/jfrog/jfrog-client-go/utils/log"
xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils"
"golang.org/x/exp/slices"
)

const (
npmPackageTypeIdentifier = "npm://"
ignoreScriptsFlag = "--ignore-scripts"
ignoreScriptsFlag = "--ignore-scripts"
)

func BuildDependencyTree(npmArgs []string) (dependencyTrees []*xrayUtils.GraphNode, uniqueDeps []string, err error) {
Expand Down Expand Up @@ -58,17 +58,17 @@ func addIgnoreScriptsFlag(npmArgs []string) []string {
func parseNpmDependenciesList(dependencies []buildinfo.Dependency, packageInfo *biutils.PackageInfo) (*xrayUtils.GraphNode, []string) {
treeMap := make(map[string][]string)
for _, dependency := range dependencies {
dependencyId := npmPackageTypeIdentifier + dependency.Id
dependencyId := utils.NpmPackageTypeIdentifier + dependency.Id
for _, requestedByNode := range dependency.RequestedBy {
parent := npmPackageTypeIdentifier + requestedByNode[0]
parent := utils.NpmPackageTypeIdentifier + requestedByNode[0]
if children, ok := treeMap[parent]; ok {
treeMap[parent] = appendUniqueChild(children, dependencyId)
} else {
treeMap[parent] = []string{dependencyId}
}
}
}
return sca.BuildXrayDependencyTree(treeMap, npmPackageTypeIdentifier+packageInfo.BuildInfoModuleId())
return sca.BuildXrayDependencyTree(treeMap, utils.NpmPackageTypeIdentifier+packageInfo.BuildInfoModuleId())
}

func appendUniqueChild(children []string, candidateDependency string) []string {
Expand Down
3 changes: 2 additions & 1 deletion xray/commands/audit/sca/npm/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package npm
import (
"encoding/json"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit/sca"
"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils"
"os"
"testing"
Expand Down Expand Up @@ -102,7 +103,7 @@ func TestParseNpmDependenciesList(t *testing.T) {
}
expectedUniqueDeps := []string{xrayDependenciesTree.Id}
for _, dep := range dependencies {
expectedUniqueDeps = append(expectedUniqueDeps, npmPackageTypeIdentifier+dep.Id)
expectedUniqueDeps = append(expectedUniqueDeps, utils.NpmPackageTypeIdentifier+dep.Id)
}
assert.ElementsMatch(t, uniqueDeps, expectedUniqueDeps, "First is actual, Second is Expected")

Expand Down
7 changes: 2 additions & 5 deletions xray/commands/audit/sca/yarn/yarn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import (
biUtils "github.com/jfrog/build-info-go/build/utils"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit/sca"
"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils"
)

const (
npmPackageTypeIdentifier = "npm://"
)

func BuildDependencyTree() (dependencyTrees []*xrayUtils.GraphNode, uniqueDeps []string, err error) {
currentDir, err := coreutils.GetWorkingDirectory()
if err != nil {
Expand Down Expand Up @@ -55,5 +52,5 @@ func parseYarnDependenciesMap(dependencies map[string]*biUtils.YarnDependency, r
}

func getXrayDependencyId(yarnDependency *biUtils.YarnDependency) string {
return npmPackageTypeIdentifier + yarnDependency.Name() + ":" + yarnDependency.Details.Version
return utils.NpmPackageTypeIdentifier + yarnDependency.Name() + ":" + yarnDependency.Details.Version
}
Loading
Loading