Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions scanpullrequest/scanpullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func auditPullRequestSourceCode(repoConfig *utils.Repository, scanDetails *utils
issuesCollection = &issues.ScansIssuesCollection{ScanStatus: getResultScanStatues(scanResults)}
return
}
utils.PrintScanResultsTable(scanResults)
// Set JAS output flags based on the scan results
repoConfig.OutputWriter.SetJasOutputFlags(scanResults.Entitlements.Jas, scanResults.HasJasScansResults(jasutils.Applicability))
filterFailedResultsIfScannersFailuresAreAllowed(scanDetails.ResultsToCompare, scanResults, repoConfig.Params.ConfigProfile.GeneralConfig.FailUponAnyScannerError, sourceBranchWd, targetBranchWd)
Expand Down
1 change: 1 addition & 0 deletions scanrepository/scanrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (sr *ScanRepositoryCmd) scanAndFixBranch(repository *utils.Repository) (tot
// Always check policy even if an error occurred during the scan
err = errors.Join(err, policy.CheckPolicyFailBuildError(scanResults))
}()
utils.PrintScanResultsTable(scanResults)
totalFindings = getTotalFindingsFromScanResults(scanResults)
sr.uploadResultsToGithubDashboardsIfNeeded(repository, scanResults)
sr.uploadGitLabScanResultsIfNeeded(repository, scanResults)
Expand Down
12 changes: 12 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/jfrog/froggit-go/vcsclient"
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/common/format"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-security/utils"
"github.com/jfrog/jfrog-cli-security/utils/formats"
Expand Down Expand Up @@ -516,3 +517,14 @@ func writeCycloneDxToDir(outputDir string, scanResults *results.SecurityCommandR
log.Info(fmt.Sprintf("CycloneDX SBOM written to %s", path))
return nil
}

func PrintScanResultsTable(scanResults *results.SecurityCommandResults) {
if scanResults == nil {
return
}
if err := output.NewResultsWriter(scanResults).
SetOutputFormat(format.Table).
PrintScanResults(); err != nil {
log.Warn(fmt.Sprintf("Failed to print scan results table: %s", err.Error()))
}
}
49 changes: 49 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"encoding/json"
"github.com/jfrog/jfrog-client-go/xray/services"
"net/http/httptest"
"os"
"path"
Expand Down Expand Up @@ -635,3 +636,51 @@ func TestWriteScanResultsToGitlabDir(t *testing.T) {
})
}
}

func TestPrintScanResultsTable(t *testing.T) {
tests := []struct {
name string
scanResults *results.SecurityCommandResults
}{
{
name: "nil scan results should not panic",
scanResults: nil,
},
{
name: "empty scan results should not panic",
scanResults: &results.SecurityCommandResults{
Targets: []*results.TargetResults{},
},
},
{
name: "scan results with vulnerabilities should print without error",
scanResults: &results.SecurityCommandResults{
ResultsMetaData: results.ResultsMetaData{
ResultContext: results.ResultContext{IncludeVulnerabilities: true},
},
Targets: []*results.TargetResults{{
ScanTarget: results.ScanTarget{Target: "test-target"},
ScaResults: &results.ScaScanResults{
DeprecatedXrayResults: []services.ScanResponse{{
Vulnerabilities: []services.Vulnerability{
{
Cves: []services.Cve{{Id: "CVE-2022-0001"}},
Severity: "High",
Components: map[string]services.Component{"test-dep:1.0.0": {FixedVersions: []string{"1.0.1"}}},
},
},
}},
},
}},
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
assert.NotPanics(t, func() {
PrintScanResultsTable(test.scanResults)
})
})
}
}
Loading