diff --git a/xray/audit/jas/applicabilitymanager.go b/xray/audit/jas/applicabilitymanager.go index 1546ea28c..373d15d6d 100644 --- a/xray/audit/jas/applicabilitymanager.go +++ b/xray/audit/jas/applicabilitymanager.go @@ -1,6 +1,9 @@ package jas import ( + "path/filepath" + "strings" + "github.com/jfrog/gofrog/datastructures" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/jfrog/jfrog-cli-core/v2/xray/utils" @@ -10,7 +13,6 @@ import ( "github.com/owenrumney/go-sarif/v2/sarif" "golang.org/x/exp/maps" "golang.org/x/exp/slices" - "strings" ) const ( @@ -109,7 +111,9 @@ func (a *ApplicabilityScanManager) Run(wd string) (err error) { return } var workingDirResults map[string]string - workingDirResults, err = a.getScanResults() + if workingDirResults, err = a.getScanResults(); err != nil { + return + } for cve, result := range workingDirResults { a.applicabilityScanResults[cve] = result } @@ -156,7 +160,7 @@ func (a *ApplicabilityScanManager) createConfigFile(workingDir string) error { // Runs the analyzerManager app and returns a boolean to indicate whether the user is entitled for // advance security feature func (a *ApplicabilityScanManager) runAnalyzerManager() error { - return a.scanner.analyzerManager.Exec(a.scanner.configFileName, applicabilityScanCommand, a.scanner.analyzerManager.GetAnalyzerManagerDir(), a.scanner.serverDetails) + return a.scanner.analyzerManager.Exec(a.scanner.configFileName, applicabilityScanCommand, filepath.Dir(a.scanner.analyzerManager.AnalyzerManagerFullPath), a.scanner.serverDetails) } func (a *ApplicabilityScanManager) getScanResults() (map[string]string, error) { diff --git a/xray/audit/jas/applicabilitymanager_test.go b/xray/audit/jas/applicabilitymanager_test.go index 3c8ffc5a8..8f970034d 100644 --- a/xray/audit/jas/applicabilitymanager_test.go +++ b/xray/audit/jas/applicabilitymanager_test.go @@ -12,48 +12,37 @@ import ( ) func TestNewApplicabilityScanManager_InputIsValid(t *testing.T) { + scanner, cleanUp := initJasTest(t) + defer cleanUp() // Act - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() applicabilityManager := newApplicabilityScanManager(fakeBasicXrayResults, mockDirectDependencies, scanner) // Assert - assert.NotEmpty(t, applicabilityManager) - assert.NotEmpty(t, applicabilityManager.scanner.configFileName) - assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) - assert.Equal(t, applicabilityManager.directDependenciesCves.Size(), 5) + if assert.NotNil(t, applicabilityManager) { + assert.NotEmpty(t, applicabilityManager.scanner.configFileName) + assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) + assert.Equal(t, applicabilityManager.directDependenciesCves.Size(), 5) + } } func TestNewApplicabilityScanManager_DependencyTreeDoesntExist(t *testing.T) { + scanner, cleanUp := initJasTest(t) + defer cleanUp() // Act - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() applicabilityManager := newApplicabilityScanManager(fakeBasicXrayResults, nil, scanner) // Assert - assert.NotEmpty(t, applicabilityManager) - assert.NotNil(t, applicabilityManager.scanner.scannerDirCleanupFunc) - assert.Len(t, applicabilityManager.scanner.workingDirs, 1) - assert.NotEmpty(t, applicabilityManager.scanner.configFileName) - assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) - assert.Equal(t, applicabilityManager.directDependenciesCves.Size(), 0) + if assert.NotNil(t, applicabilityManager) { + assert.NotNil(t, applicabilityManager.scanner.scannerDirCleanupFunc) + assert.Len(t, applicabilityManager.scanner.workingDirs, 1) + assert.NotEmpty(t, applicabilityManager.scanner.configFileName) + assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) + assert.Equal(t, applicabilityManager.directDependenciesCves.Size(), 0) + } } func TestNewApplicabilityScanManager_NoDirectDependenciesInScan(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) var noDirectDependenciesResults = []services.ScanResponse{ { ScanId: "scanId_1", @@ -75,47 +64,36 @@ func TestNewApplicabilityScanManager_NoDirectDependenciesInScan(t *testing.T) { fakeBasicXrayResults[0].Violations[0].Components["issueId_2_non_direct_dependency"] = services.Component{} // Act - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() + scanner, cleanUp := initJasTest(t) + defer cleanUp() applicabilityManager := newApplicabilityScanManager(noDirectDependenciesResults, mockDirectDependencies, scanner) // Assert - assert.NotEmpty(t, applicabilityManager) - assert.NotEmpty(t, applicabilityManager.scanner.configFileName) - assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) - // Non-direct dependencies should not be added - assert.Equal(t, 0, applicabilityManager.directDependenciesCves.Size()) + if assert.NotNil(t, applicabilityManager) { + assert.NotEmpty(t, applicabilityManager.scanner.configFileName) + assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) + // Non-direct dependencies should not be added + assert.Equal(t, 0, applicabilityManager.directDependenciesCves.Size()) + } } func TestNewApplicabilityScanManager_MultipleDependencyTrees(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - + scanner, cleanUp := initJasTest(t) + defer cleanUp() // Act - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() applicabilityManager := newApplicabilityScanManager(fakeBasicXrayResults, mockMultiRootDirectDependencies, scanner) // Assert - assert.NotEmpty(t, applicabilityManager) - assert.NotEmpty(t, applicabilityManager.scanner.configFileName) - assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) - assert.Equal(t, 5, applicabilityManager.directDependenciesCves.Size()) + if assert.NotNil(t, applicabilityManager) { + assert.NotEmpty(t, applicabilityManager.scanner.configFileName) + assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) + assert.Equal(t, 5, applicabilityManager.directDependenciesCves.Size()) + } } func TestNewApplicabilityScanManager_ViolationsDontExistInResults(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) noViolationScanResponse := []services.ScanResponse{ { ScanId: "scanId_1", @@ -126,28 +104,22 @@ func TestNewApplicabilityScanManager_ViolationsDontExistInResults(t *testing.T) }, }, } + scanner, cleanUp := initJasTest(t) + defer cleanUp() // Act - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() applicabilityManager := newApplicabilityScanManager(noViolationScanResponse, mockDirectDependencies, scanner) // Assert - assert.NoError(t, err) - assert.NotEmpty(t, applicabilityManager) - assert.NotEmpty(t, applicabilityManager.scanner.configFileName) - assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) - assert.Equal(t, 3, applicabilityManager.directDependenciesCves.Size()) + if assert.NotNil(t, applicabilityManager) { + assert.NotEmpty(t, applicabilityManager.scanner.configFileName) + assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) + assert.Equal(t, 3, applicabilityManager.directDependenciesCves.Size()) + } } func TestNewApplicabilityScanManager_VulnerabilitiesDontExist(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) noVulnerabilitiesScanResponse := []services.ScanResponse{ { ScanId: "scanId_1", @@ -158,33 +130,24 @@ func TestNewApplicabilityScanManager_VulnerabilitiesDontExist(t *testing.T) { }, }, } + scanner, cleanUp := initJasTest(t) + defer cleanUp() // Act - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() applicabilityManager := newApplicabilityScanManager(noVulnerabilitiesScanResponse, mockDirectDependencies, scanner) // Assert - assert.NotEmpty(t, applicabilityManager) - assert.NotEmpty(t, applicabilityManager.scanner.configFileName) - assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) - assert.Equal(t, 2, applicabilityManager.directDependenciesCves.Size()) + if assert.NotNil(t, applicabilityManager) { + assert.NotEmpty(t, applicabilityManager.scanner.configFileName) + assert.NotEmpty(t, applicabilityManager.scanner.resultsFileName) + assert.Equal(t, 2, applicabilityManager.directDependenciesCves.Size()) + } } func TestApplicabilityScanManager_ShouldRun_TechnologiesNotEligibleForScan(t *testing.T) { - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() + scanner, cleanUp := initJasTest(t) + defer cleanUp() + results, err := getApplicabilityScanResults(fakeBasicXrayResults, mockDirectDependencies, []coreutils.Technology{coreutils.Nuget, coreutils.Go}, scanner) @@ -195,16 +158,11 @@ func TestApplicabilityScanManager_ShouldRun_TechnologiesNotEligibleForScan(t *te func TestApplicabilityScanManager_ShouldRun_ScanResultsAreEmpty(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() + scanner, cleanUp := initJasTest(t) + defer cleanUp() + applicabilityManager := newApplicabilityScanManager(nil, mockDirectDependencies, scanner) - assert.NoError(t, err) + // Assert eligible := applicabilityManager.shouldRunApplicabilityScan([]coreutils.Technology{coreutils.Npm}) assert.False(t, eligible) @@ -284,14 +242,9 @@ func TestExtractXrayDirectVulnerabilities(t *testing.T) { func TestCreateConfigFile_VerifyFileWasCreated(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() + scanner, cleanUp := initJasTest(t) + defer cleanUp() + applicabilityManager := newApplicabilityScanManager(fakeBasicXrayResults, []string{"issueId_1_direct_dependency", "issueId_2_direct_dependency"}, scanner) currWd, err := coreutils.GetWorkingDirectory() @@ -313,14 +266,9 @@ func TestCreateConfigFile_VerifyFileWasCreated(t *testing.T) { func TestParseResults_EmptyResults_AllCvesShouldGetUnknown(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() + scanner, cleanUp := initJasTest(t) + defer cleanUp() + applicabilityManager := newApplicabilityScanManager(fakeBasicXrayResults, mockDirectDependencies, scanner) applicabilityManager.scanner.resultsFileName = filepath.Join("..", "..", "commands", "testdata", "applicability-scan", "empty-results.sarif") @@ -337,14 +285,8 @@ func TestParseResults_EmptyResults_AllCvesShouldGetUnknown(t *testing.T) { func TestParseResults_ApplicableCveExist(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() + scanner, cleanUp := initJasTest(t) + defer cleanUp() applicabilityManager := newApplicabilityScanManager(fakeBasicXrayResults, mockDirectDependencies, scanner) applicabilityManager.scanner.resultsFileName = filepath.Join("..", "..", "commands", "testdata", "applicability-scan", "applicable-cve-results.sarif") @@ -360,14 +302,8 @@ func TestParseResults_ApplicableCveExist(t *testing.T) { func TestParseResults_AllCvesNotApplicable(t *testing.T) { // Arrange - assert.NoError(t, rtutils.DownloadAnalyzerManagerIfNeeded()) - scanner, err := NewAdvancedSecurityScanner(nil, &fakeServerDetails) - assert.NoError(t, err) - defer func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } - }() + scanner, cleanUp := initJasTest(t) + defer cleanUp() applicabilityManager := newApplicabilityScanManager(fakeBasicXrayResults, mockDirectDependencies, scanner) applicabilityManager.scanner.resultsFileName = filepath.Join("..", "..", "commands", "testdata", "applicability-scan", "no-applicable-cves-results.sarif") diff --git a/xray/audit/jas/iacscanner.go b/xray/audit/jas/iacscanner.go index 221accf24..56c9dad96 100644 --- a/xray/audit/jas/iacscanner.go +++ b/xray/audit/jas/iacscanner.go @@ -1,6 +1,8 @@ package jas import ( + "path/filepath" + "github.com/jfrog/jfrog-cli-core/v2/xray/utils" "github.com/jfrog/jfrog-client-go/utils/log" ) @@ -53,7 +55,9 @@ func (iac *IacScanManager) Run(wd string) (err error) { return } var workingDirResults []utils.SourceCodeScanResult - workingDirResults, err = getSourceCodeScanResults(scanner.resultsFileName, wd, utils.IaC) + if workingDirResults, err = getSourceCodeScanResults(scanner.resultsFileName, wd, utils.IaC); err != nil { + return + } iac.iacScannerResults = append(iac.iacScannerResults, workingDirResults...) return } @@ -84,5 +88,5 @@ func (iac *IacScanManager) createConfigFile(currentWd string) error { } func (iac *IacScanManager) runAnalyzerManager() error { - return iac.scanner.analyzerManager.Exec(iac.scanner.configFileName, iacScanCommand, iac.scanner.analyzerManager.GetAnalyzerManagerDir(), iac.scanner.serverDetails) + return iac.scanner.analyzerManager.Exec(iac.scanner.configFileName, iacScanCommand, filepath.Dir(iac.scanner.analyzerManager.AnalyzerManagerFullPath), iac.scanner.serverDetails) } diff --git a/xray/audit/jas/iacscanner_test.go b/xray/audit/jas/iacscanner_test.go index e33a9b158..42a5d9d3c 100644 --- a/xray/audit/jas/iacscanner_test.go +++ b/xray/audit/jas/iacscanner_test.go @@ -17,11 +17,12 @@ func TestNewIacScanManager(t *testing.T) { iacScanManager := newIacScanManager(scanner) // Assert - assert.NotEmpty(t, iacScanManager) - assert.NotEmpty(t, iacScanManager.scanner.configFileName) - assert.NotEmpty(t, iacScanManager.scanner.resultsFileName) - assert.NotEmpty(t, iacScanManager.scanner.workingDirs) - assert.Equal(t, &fakeServerDetails, iacScanManager.scanner.serverDetails) + if assert.NotNil(t, iacScanManager) { + assert.NotEmpty(t, iacScanManager.scanner.configFileName) + assert.NotEmpty(t, iacScanManager.scanner.resultsFileName) + assert.NotEmpty(t, iacScanManager.scanner.workingDirs) + assert.Equal(t, &fakeServerDetails, iacScanManager.scanner.serverDetails) + } } func TestIacScan_CreateConfigFile_VerifyFileWasCreated(t *testing.T) { diff --git a/xray/audit/jas/jasmanager.go b/xray/audit/jas/jasmanager.go index de5e28263..35e62f4c9 100644 --- a/xray/audit/jas/jasmanager.go +++ b/xray/audit/jas/jasmanager.go @@ -127,7 +127,7 @@ func deleteJasProcessFiles(configFile string, resultFile string) error { return errorutils.CheckError(err) } -func getSourceCodeScanResults(resultsFileName, workingDir string, scanType utils.ScanType) ([]utils.SourceCodeScanResult, error) { +func getSourceCodeScanResults(resultsFileName, workingDir string, scanType utils.JasScanType) ([]utils.SourceCodeScanResult, error) { report, err := sarif.Open(resultsFileName) if errorutils.CheckError(err) != nil { return nil, err diff --git a/xray/audit/jas/jasmanager_test.go b/xray/audit/jas/jasmanager_test.go index 8ecc672b4..405930553 100644 --- a/xray/audit/jas/jasmanager_test.go +++ b/xray/audit/jas/jasmanager_test.go @@ -43,9 +43,7 @@ func initJasTest(t *testing.T, workingDirs ...string) (*AdvancedSecurityScanner, scanner, err := NewAdvancedSecurityScanner(workingDirs, &fakeServerDetails) assert.NoError(t, err) return scanner, func() { - if scanner.scannerDirCleanupFunc != nil { - assert.NoError(t, scanner.scannerDirCleanupFunc()) - } + assert.NoError(t, scanner.scannerDirCleanupFunc()) } } diff --git a/xray/audit/jas/sastscanner.go b/xray/audit/jas/sastscanner.go index 6a511f47e..62116b4ca 100644 --- a/xray/audit/jas/sastscanner.go +++ b/xray/audit/jas/sastscanner.go @@ -28,7 +28,9 @@ func (zd *SastScanManager) Run(wd string) (err error) { return } var workingDirResults []utils.SourceCodeScanResult - workingDirResults, err = getSourceCodeScanResults(scanner.resultsFileName, wd, utils.Sast) + if workingDirResults, err = getSourceCodeScanResults(scanner.resultsFileName, wd, utils.Sast); err != nil { + return + } zd.sastScannerResults = append(zd.sastScannerResults, workingDirResults...) return } @@ -45,7 +47,7 @@ func getSastScanResults(scanner *AdvancedSecurityScanner) (results []utils.Sourc return } if len(sastScanManager.sastScannerResults) > 0 { - log.Info(len(sastScanManager.sastScannerResults), "SAST vulnerabilities") + log.Info("Found", len(sastScanManager.sastScannerResults), "SAST vulnerabilities") } results = sastScanManager.sastScannerResults return diff --git a/xray/audit/jas/secretsscanner.go b/xray/audit/jas/secretsscanner.go index 42179b552..38648e47b 100644 --- a/xray/audit/jas/secretsscanner.go +++ b/xray/audit/jas/secretsscanner.go @@ -1,6 +1,7 @@ package jas import ( + "path/filepath" "strings" "github.com/jfrog/jfrog-cli-core/v2/xray/utils" @@ -33,7 +34,7 @@ func getSecretsScanResults(scanner *AdvancedSecurityScanner) (results []utils.So } results = secretScanManager.secretsScannerResults if len(results) > 0 { - log.Info(len(results), "secrets were found") + log.Info("Found", len(results), "secrets") } return } @@ -54,7 +55,9 @@ func (s *SecretScanManager) Run(wd string) (err error) { return } var workingDirResults []utils.SourceCodeScanResult - workingDirResults, err = getSourceCodeScanResults(scanner.resultsFileName, wd, utils.Secrets) + if workingDirResults, err = getSourceCodeScanResults(scanner.resultsFileName, wd, utils.Secrets); err != nil { + return + } s.secretsScannerResults = append(s.secretsScannerResults, workingDirResults...) return } @@ -85,7 +88,7 @@ func (s *SecretScanManager) createConfigFile(currentWd string) error { } func (s *SecretScanManager) runAnalyzerManager() error { - return s.scanner.analyzerManager.Exec(s.scanner.configFileName, secretsScanCommand, s.scanner.analyzerManager.GetAnalyzerManagerDir(), s.scanner.serverDetails) + return s.scanner.analyzerManager.Exec(s.scanner.configFileName, secretsScanCommand, filepath.Dir(s.scanner.analyzerManager.AnalyzerManagerFullPath), s.scanner.serverDetails) } func hideSecret(secret string) string { diff --git a/xray/utils/analyzermanager.go b/xray/utils/analyzermanager.go index 69d347679..9ca2c457d 100644 --- a/xray/utils/analyzermanager.go +++ b/xray/utils/analyzermanager.go @@ -50,16 +50,16 @@ const ( ApplicabilityUndeterminedStringValue = "Undetermined" ) -type ScanType string +type JasScanType string const ( - Applicability ScanType = "Applicability" - Secrets ScanType = "Secrets" - IaC ScanType = "IaC" - Sast ScanType = "Sast" + Applicability JasScanType = "Applicability" + Secrets JasScanType = "Secrets" + IaC JasScanType = "IaC" + Sast JasScanType = "Sast" ) -func (st ScanType) FormattedError(err error) error { +func (st JasScanType) FormattedError(err error) error { if err != nil { return fmt.Errorf(ErrFailedScannerRun, st, err.Error()) } @@ -103,10 +103,6 @@ type AnalyzerManager struct { AnalyzerManagerFullPath string } -func (am *AnalyzerManager) GetAnalyzerManagerDir() string { - return filepath.Dir(am.AnalyzerManagerFullPath) -} - func (am *AnalyzerManager) Exec(configFile, scanCommand, workingDir string, serverDetails *config.ServerDetails) (err error) { if err = SetAnalyzerManagerEnvVariables(serverDetails); err != nil { return err @@ -190,7 +186,7 @@ func SetAnalyzerManagerEnvVariables(serverDetails *config.ServerDetails) error { return nil } -func ParseAnalyzerManagerError(scanner ScanType, err error) error { +func ParseAnalyzerManagerError(scanner JasScanType, err error) error { var exitError *exec.ExitError if errors.As(err, &exitError) { exitCode := exitError.ExitCode() diff --git a/xray/utils/analyzermanager_test.go b/xray/utils/analyzermanager_test.go index a0fedcca1..61a6a834c 100644 --- a/xray/utils/analyzermanager_test.go +++ b/xray/utils/analyzermanager_test.go @@ -3,11 +3,12 @@ package utils import ( "errors" "fmt" + "path/filepath" + "testing" + "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/owenrumney/go-sarif/v2/sarif" "github.com/stretchr/testify/assert" - "path/filepath" - "testing" ) func TestRemoveDuplicateValues(t *testing.T) { @@ -140,7 +141,7 @@ func TestGetResultSeverity(t *testing.T) { func TestScanTypeErrorMsg(t *testing.T) { tests := []struct { - scanner ScanType + scanner JasScanType err error wantMsg string }{ diff --git a/xray/utils/resultwriter.go b/xray/utils/resultwriter.go index 765561e27..f5b593537 100644 --- a/xray/utils/resultwriter.go +++ b/xray/utils/resultwriter.go @@ -238,7 +238,7 @@ func convertToSourceCodeResultSarif(run *sarif.Run, jsonTable *formats.SimpleJso return } -func getSourceCodeProperties(sourceCodeIssue formats.SourceCodeRow, markdownOutput bool, scanType ScanType) sarifProperties { +func getSourceCodeProperties(sourceCodeIssue formats.SourceCodeRow, markdownOutput bool, scanType JasScanType) sarifProperties { file := strings.TrimPrefix(sourceCodeIssue.File, string(os.PathSeparator)) mapSeverityToScore := map[string]string{ "": "0.0", diff --git a/xray/utils/resultwriter_test.go b/xray/utils/resultwriter_test.go index a12a7b671..8a015267c 100644 --- a/xray/utils/resultwriter_test.go +++ b/xray/utils/resultwriter_test.go @@ -106,7 +106,7 @@ func TestGetIacOrSecretsProperties(t *testing.T) { name string row formats.SourceCodeRow markdownOutput bool - isSecret ScanType + isSecret JasScanType expectedOutput sarifProperties }{ {