Skip to content

Commit

Permalink
fixing bugs adding docker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Sep 15, 2024
1 parent 3c98706 commit 2840382
Show file tree
Hide file tree
Showing 24 changed files with 2,857 additions and 16,500 deletions.
5 changes: 1 addition & 4 deletions commands/scan/dockerscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (dsc *DockerScanCommand) Run() (err error) {
Pattern(imageTarPath).
Target(dsc.targetRepoPath).
BuildSpec()).SetThreads(1)
dsc.ScanCommand.SetRunJasScans(true)
dsc.ScanCommand.SetTargetNameOverride(dsc.imageTag).SetRunJasScans(true)
err = dsc.setCredentialEnvsForIndexerApp()
if err != nil {
return errorutils.CheckError(err)
Expand All @@ -102,9 +102,6 @@ func (dsc *DockerScanCommand) Run() (err error) {
if scanResults == nil {
return
}
for _, scan := range scanResults.Targets {
scan.Name = dsc.imageTag
}
dsc.analyticsMetricsService.UpdateGeneralEvent(dsc.analyticsMetricsService.CreateXscAnalyticsGeneralEventFinalizeFromAuditResults(scanResults))
return dsc.recordResults(scanResults)
})
Expand Down
23 changes: 18 additions & 5 deletions commands/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type ScanCommand struct {
progress ioUtils.ProgressMgr
// JAS is only supported for Docker images.
commandSupportsJAS bool
targetNameOverride string
analyticsMetricsService *xsc.AnalyticsMetricsService
}

Expand All @@ -90,6 +91,11 @@ func (scanCmd *ScanCommand) SetRunJasScans(run bool) *ScanCommand {
return scanCmd
}

func (scanCmd *ScanCommand) SetTargetNameOverride(targetName string) *ScanCommand {
scanCmd.targetNameOverride = targetName
return scanCmd
}

func (scanCmd *ScanCommand) SetProgress(progress ioUtils.ProgressMgr) {
scanCmd.progress = progress
}
Expand Down Expand Up @@ -305,10 +311,6 @@ func (scanCmd *ScanCommand) RunAndRecordResults(cmdType utils.CommandType, recor
err = errors.New("failed while trying to get Analyzer Manager: " + err.Error())
}

if err = recordResFunc(cmdResults); err != nil {
return err
}

if err = output.NewResultsWriter(cmdResults).
SetOutputFormat(scanCmd.outputFormat).
SetHasViolationContext(scanCmd.hasViolationContext()).
Expand All @@ -320,6 +322,10 @@ func (scanCmd *ScanCommand) RunAndRecordResults(cmdType utils.CommandType, recor
return
}

if err = recordResFunc(cmdResults); err != nil {
return err
}

// If includeVulnerabilities is false it means that context was provided, so we need to check for build violations.
// If user provided --fail=false, don't fail the build.
if scanCmd.fail && !scanCmd.includeVulnerabilities {
Expand Down Expand Up @@ -361,12 +367,19 @@ func (scanCmd *ScanCommand) prepareScanTasks(fileProducer, indexedFileProducer p
}()
}

func (scanCmd *ScanCommand) getBinaryTargetName(binaryPath string) string {
if scanCmd.targetNameOverride != "" {
return scanCmd.targetNameOverride
}
return filepath.Base(binaryPath)
}

func (scanCmd *ScanCommand) createIndexerHandlerFunc(file *spec.File, cmdResults *results.SecurityCommandResults, indexedFileProducer parallel.Runner, jasFileProducerConsumer *utils.SecurityParallelRunner) FileContext {
return func(filePath string) parallel.TaskFunc {
return func(threadId int) (err error) {
logMsgPrefix := clientutils.GetLogMsgPrefix(threadId, false)
// Create a scan target for the file.
targetResults := cmdResults.NewScanResults(results.ScanTarget{Target: filePath, Name: filepath.Base(filePath)})
targetResults := cmdResults.NewScanResults(results.ScanTarget{Target: filePath, Name: scanCmd.getBinaryTargetName(filePath)})
log.Info(logMsgPrefix+"Indexing file:", targetResults.Target)
if scanCmd.progress != nil {
scanCmd.progress.SetHeadlineMsg("Indexing file: " + targetResults.Name + " 🗄")
Expand Down
2 changes: 1 addition & 1 deletion jas/secrets/secretsscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func processSecretScanRuns(sarifRuns []*sarif.Run) []*sarif.Run {
// Hide discovered secrets value
for _, secretResult := range secretRun.Results {
for _, location := range secretResult.Locations {
sarifutils.SetLocationSnippet(location, maskSecret(sarifutils.GetLocationSnippet(location)))
sarifutils.SetLocationSnippet(location, maskSecret(sarifutils.GetLocationSnippetText(location)))
}
}
}
Expand Down
62 changes: 31 additions & 31 deletions tests/testdata/other/sast-scan/contains-sast-violations.sarif

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/testdata/other/sast-scan/no-violations.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
{
"executionSuccessful": true,
"arguments": [
"/Users/assafa/.jfrog/dependencies/analyzerManager/zd_scanner/scanner",
"/users/user/.jfrog/dependencies/analyzerManager/zd_scanner/scanner",
"scan",
"/var/folders/xv/th4cksxn7jv9wjrdnn1h4tj00000gq/T/jfrog.cli.temp.-1693477603-3697552683/results.sarif"
],
"workingDirectory": {
"uri": "file:///Users/assafa/Documents/code/terraform"
"uri": "file:///Users/user/testdata/terraform"
}
}
],
Expand Down
22 changes: 11 additions & 11 deletions tests/testdata/output/audit/audit_results.json

Large diffs are not rendered by default.

17,047 changes: 839 additions & 16,208 deletions tests/testdata/output/dockerscan/docker_results.json

Large diffs are not rendered by default.

778 changes: 778 additions & 0 deletions tests/testdata/output/dockerscan/docker_sarif.json

Large diffs are not rendered by default.

Loading

0 comments on commit 2840382

Please sign in to comment.