Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Dec 20, 2024
1 parent f6421f9 commit f11f066
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 99 deletions.
2 changes: 1 addition & 1 deletion scanpullrequest/scanpullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func getAllIssues(cmdResults *results.SecurityCommandResults, allowedLicenses []
return nil, err
}
return &issues.ScansIssuesCollection{
ResultContext: cmdResults.ResultContext,
ResultContext: cmdResults.ResultContext,
ScanStatus: simpleJsonResults.Statuses,
ScaVulnerabilities: simpleJsonResults.Vulnerabilities,
ScaViolations: simpleJsonResults.SecurityViolations,
Expand Down
8 changes: 4 additions & 4 deletions scanrepository/scanrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ func TestPackageTypeFromScan(t *testing.T) {
frogbotParams.Projects[0].InstallCommandName = pkg.commandName
frogbotParams.Projects[0].InstallCommandArgs = pkg.commandArgs
scanSetup := utils.ScanDetails{
XrayVersion: xrayVersion,
XscVersion: xscVersion,
XrayVersion: xrayVersion,
XscVersion: xscVersion,
Project: &frogbotParams.Projects[0],
ServerDetails: &frogbotParams.Server,
}
Expand Down Expand Up @@ -550,7 +550,7 @@ func TestCreateVulnerabilitiesMap(t *testing.T) {
Violations: []services.Violation{
{
ViolationType: "security",
WatchName: "w1",
WatchName: "w1",
Cves: []services.Cve{
{Id: "CVE-2023-1234", CvssV3Score: "9.1"},
{Id: "CVE-2023-4321", CvssV3Score: "8.9"},
Expand All @@ -565,7 +565,7 @@ func TestCreateVulnerabilitiesMap(t *testing.T) {
},
{
ViolationType: "security",
WatchName: "w1",
WatchName: "w1",
Cves: []services.Cve{
{Id: "CVE-2022-1234", CvssV3Score: "7.1"},
{Id: "CVE-2022-4321", CvssV3Score: "7.9"},
Expand Down
14 changes: 7 additions & 7 deletions utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ const (
PullRequestSecretCommentsEnv = "JF_PR_SHOW_SECRETS_COMMENTS"

// Repository environment variables - Ignored if the frogbot-config.yml file is used
InstallCommandEnv = "JF_INSTALL_DEPS_CMD"
RequirementsFileEnv = "JF_REQUIREMENTS_FILE"
WorkingDirectoryEnv = "JF_WORKING_DIR"
PathExclusionsEnv = "JF_PATH_EXCLUSIONS"
jfrogWatchesEnv = "JF_WATCHES"
jfrogProjectEnv = "JF_PROJECT"
InstallCommandEnv = "JF_INSTALL_DEPS_CMD"
RequirementsFileEnv = "JF_REQUIREMENTS_FILE"
WorkingDirectoryEnv = "JF_WORKING_DIR"
PathExclusionsEnv = "JF_PATH_EXCLUSIONS"
jfrogWatchesEnv = "JF_WATCHES"
jfrogProjectEnv = "JF_PROJECT"
// To include vulnerabilities and violations
IncludeVulnerabilitiesEnv = "JF_INCLUDE_VULNERABILITIES"
IncludeVulnerabilitiesEnv = "JF_INCLUDE_VULNERABILITIES"
// To include all the vulnerabilities in the source branch at PR scan
IncludeAllVulnerabilitiesEnv = "JF_INCLUDE_ALL_VULNERABILITIES"
AvoidPreviousPrCommentsDeletionEnv = "JF_AVOID_PREVIOUS_PR_COMMENTS_DELETION"
Expand Down
8 changes: 4 additions & 4 deletions utils/issues/issuescollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (ic *ScansIssuesCollection) GetScanIssuesSeverityCount(scanType utils.SubSc
for _, violation := range ic.LicensesViolations {
scanDetails[severityutils.GetSeverity(violation.Severity)]++
}
}
}
if vulnerabilities {
for _, vulnerability := range ic.ScaVulnerabilities {
scanDetails[severityutils.GetSeverity(vulnerability.Severity)]++
Expand All @@ -157,23 +157,23 @@ func (ic *ScansIssuesCollection) GetScanIssuesSeverityCount(scanType utils.SubSc
// Count Iac issues only if requested
if violation {
jasViolations = ic.IacViolations
}
}
if vulnerabilities {
jasVulnerabilities = ic.IacVulnerabilities
}
case utils.SecretsScan:
// Count Secrets issues only if requested
if violation {
jasViolations = ic.SecretsViolations
}
}
if vulnerabilities {
jasVulnerabilities = ic.SecretsVulnerabilities
}
case utils.SastScan:
// Count Sast issues only if requested
if violation {
jasViolations = ic.SastViolations
}
}
if vulnerabilities {
jasVulnerabilities = ic.SastVulnerabilities
}
Expand Down
26 changes: 13 additions & 13 deletions utils/issues/issuescollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ func TestGetScanIssuesSeverityCount(t *testing.T) {
name string
scanType utils.SubScanType
violation bool
vulnerabilities bool
vulnerabilities bool
expectedSeverityCount map[string]int
}{
{
name: "Sca Vulnerabilities",
scanType: utils.ScaScan,
vulnerabilities: true,
vulnerabilities: true,
expectedSeverityCount: map[string]int{"High": 1, "Low": 1},
},
{
Expand All @@ -248,16 +248,16 @@ func TestGetScanIssuesSeverityCount(t *testing.T) {
expectedSeverityCount: map[string]int{"Critical": 1, "Medium": 1},
},
{
name: "Sca Vulnerabilities and Violations",
name: "Sca Vulnerabilities and Violations",
scanType: utils.ScaScan,
vulnerabilities: true,
vulnerabilities: true,
violation: true,
expectedSeverityCount: map[string]int{"High": 1, "Low": 1, "Critical": 1, "Medium": 1},
},
{
name: "Iac Vulnerabilities",
scanType: utils.IacScan,
vulnerabilities: true,
vulnerabilities: true,
expectedSeverityCount: map[string]int{"Low": 1},
},
{
Expand All @@ -267,16 +267,16 @@ func TestGetScanIssuesSeverityCount(t *testing.T) {
expectedSeverityCount: map[string]int{},
},
{
name: "Iac Vulnerabilities and Violations",
name: "Iac Vulnerabilities and Violations",
scanType: utils.IacScan,
vulnerabilities: true,
vulnerabilities: true,
violation: true,
expectedSeverityCount: map[string]int{"Low": 1},
},
{
name: "Secrets Vulnerabilities",
scanType: utils.SecretsScan,
vulnerabilities: true,
vulnerabilities: true,
expectedSeverityCount: map[string]int{"High": 1},
},
{
Expand All @@ -286,16 +286,16 @@ func TestGetScanIssuesSeverityCount(t *testing.T) {
expectedSeverityCount: map[string]int{"High": 1},
},
{
name: "Secrets Vulnerabilities and Violations",
name: "Secrets Vulnerabilities and Violations",
scanType: utils.SecretsScan,
vulnerabilities: true,
vulnerabilities: true,
violation: true,
expectedSeverityCount: map[string]int{"High": 2},
},
{
name: "Sast Vulnerabilities",
scanType: utils.SastScan,
vulnerabilities: true,
vulnerabilities: true,
expectedSeverityCount: map[string]int{"High": 1, "Unknown": 1},
},
{
Expand All @@ -305,9 +305,9 @@ func TestGetScanIssuesSeverityCount(t *testing.T) {
expectedSeverityCount: map[string]int{},
},
{
name: "Sast Vulnerabilities and Violations",
name: "Sast Vulnerabilities and Violations",
scanType: utils.SastScan,
vulnerabilities: true,
vulnerabilities: true,
violation: true,
expectedSeverityCount: map[string]int{"High": 1, "Unknown": 1},
},
Expand Down
20 changes: 10 additions & 10 deletions utils/outputwriter/outputcontent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

"github.com/jfrog/frogbot/v2/utils/issues"
"github.com/jfrog/froggit-go/vcsutils"
xrayApi "github.com/jfrog/jfrog-client-go/xray/services/utils"
"github.com/jfrog/jfrog-cli-security/utils"
"github.com/jfrog/jfrog-cli-security/utils/formats"
"github.com/jfrog/jfrog-cli-security/utils/jasutils"
"github.com/jfrog/jfrog-cli-security/utils/results"
"github.com/jfrog/jfrog-cli-security/utils/severityutils"
xrayApi "github.com/jfrog/jfrog-client-go/xray/services/utils"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -233,12 +233,12 @@ func TestScanSummaryContent(t *testing.T) {
}

testCases := []struct {
name string
context results.ResultContext
includeSecrets bool
scanStatus formats.ScanStatus
issues issues.ScansIssuesCollection
cases []OutputTestCase
name string
context results.ResultContext
includeSecrets bool
scanStatus formats.ScanStatus
issues issues.ScansIssuesCollection
cases []OutputTestCase
}{
{
name: "No issues",
Expand All @@ -261,7 +261,7 @@ func TestScanSummaryContent(t *testing.T) {
name: "Vulnerabilities",
issues: testIssues,
scanStatus: testScanStatus,
context: results.ResultContext{GitRepoHttpsCloneUrl: "url", IncludeVulnerabilities: true},
context: results.ResultContext{GitRepoHttpsCloneUrl: "url", IncludeVulnerabilities: true},
cases: []OutputTestCase{
{
name: "Standard output",
Expand All @@ -279,7 +279,7 @@ func TestScanSummaryContent(t *testing.T) {
name: "Violations",
issues: testIssues,
scanStatus: testScanStatus,
context: results.ResultContext{Watches: []string{"watch"}},
context: results.ResultContext{Watches: []string{"watch"}},
cases: []OutputTestCase{
{
name: "Standard output",
Expand All @@ -297,7 +297,7 @@ func TestScanSummaryContent(t *testing.T) {
name: "Violations and Vulnerabilities",
issues: testIssues,
scanStatus: testScanStatus,
context: results.ResultContext{GitRepoHttpsCloneUrl: "url", PlatformWatches: &xrayApi.ResourcesWatchesBody{GitRepositoryWatches: []string{"watch"}}, IncludeVulnerabilities: true},
context: results.ResultContext{GitRepoHttpsCloneUrl: "url", PlatformWatches: &xrayApi.ResourcesWatchesBody{GitRepositoryWatches: []string{"watch"}}, IncludeVulnerabilities: true},
cases: []OutputTestCase{
{
name: "Standard output",
Expand Down
42 changes: 21 additions & 21 deletions utils/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ func (s *Scan) setDefaultsIfNeeded() (err error) {
}

type JFrogPlatform struct {
XrayVersion string
XscVersion string
Watches []string `yaml:"watches,omitempty"`
IncludeVulnerabilities bool `yaml:"includeVulnerabilities,omitempty"`
JFrogProjectKey string `yaml:"jfrogProjectKey,omitempty"`
XrayVersion string
XscVersion string
Watches []string `yaml:"watches,omitempty"`
IncludeVulnerabilities bool `yaml:"includeVulnerabilities,omitempty"`
JFrogProjectKey string `yaml:"jfrogProjectKey,omitempty"`
}

func (jp *JFrogPlatform) setDefaultsIfNeeded() (err error) {
Expand Down Expand Up @@ -306,22 +306,22 @@ func (jp *JFrogPlatform) setDefaultsIfNeeded() (err error) {
type Git struct {
GitProvider vcsutils.VcsProvider
vcsclient.VcsInfo
UseMostCommonAncestorAsTarget bool `yaml:"useMostCommonAncestorAsTarget,omitempty"`
RepoOwner string
RepoName string `yaml:"repoName,omitempty"`
Branches []string `yaml:"branches,omitempty"`
BranchNameTemplate string `yaml:"branchNameTemplate,omitempty"`
CommitMessageTemplate string `yaml:"commitMessageTemplate,omitempty"`
PullRequestTitleTemplate string `yaml:"pullRequestTitleTemplate,omitempty"`
PullRequestCommentTitle string `yaml:"pullRequestCommentTitle,omitempty"`
PullRequestSecretComments bool `yaml:"pullRequestSecretComments,omitempty"`
PullRequestDisableErrorComment bool `yaml:"pullRequestDisableErrorComment,omitempty"`
AvoidExtraMessages bool `yaml:"avoidExtraMessages,omitempty"`
EmailAuthor string `yaml:"emailAuthor,omitempty"`
AggregateFixes bool `yaml:"aggregateFixes,omitempty"`
PullRequestDetails vcsclient.PullRequestInfo
RepositoryCloneUrl string
UseLocalRepository bool
UseMostCommonAncestorAsTarget bool `yaml:"useMostCommonAncestorAsTarget,omitempty"`
RepoOwner string
RepoName string `yaml:"repoName,omitempty"`
Branches []string `yaml:"branches,omitempty"`
BranchNameTemplate string `yaml:"branchNameTemplate,omitempty"`
CommitMessageTemplate string `yaml:"commitMessageTemplate,omitempty"`
PullRequestTitleTemplate string `yaml:"pullRequestTitleTemplate,omitempty"`
PullRequestCommentTitle string `yaml:"pullRequestCommentTitle,omitempty"`
PullRequestSecretComments bool `yaml:"pullRequestSecretComments,omitempty"`
PullRequestDisableErrorComment bool `yaml:"pullRequestDisableErrorComment,omitempty"`
AvoidExtraMessages bool `yaml:"avoidExtraMessages,omitempty"`
EmailAuthor string `yaml:"emailAuthor,omitempty"`
AggregateFixes bool `yaml:"aggregateFixes,omitempty"`
PullRequestDetails vcsclient.PullRequestInfo
RepositoryCloneUrl string
UseLocalRepository bool
}

func (g *Git) setDefaultsIfNeeded(gitParamsFromEnv *Git, commandName string) (err error) {
Expand Down
16 changes: 8 additions & 8 deletions utils/scandetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type ScanDetails struct {
*Project
*Git

// *services.XrayGraphScanParams
*xscservices.XscGitInfoContext
*config.ServerDetails
Expand All @@ -42,8 +42,8 @@ type ScanDetails struct {
results.ResultContext
MultiScanId string
XrayVersion string
XscVersion string
StartTime time.Time
XscVersion string
StartTime time.Time
}

func NewScanDetails(client vcsclient.VcsClient, server *config.ServerDetails, git *Git) *ScanDetails {
Expand Down Expand Up @@ -152,12 +152,12 @@ func (sc *ScanDetails) AllowPartialResults() bool {

func createXrayScanParams(httpCloneUrl string, watches []string, project string, includeVulnerabilities, includeLicenses bool) (params *services.XrayGraphScanParams) {
return &services.XrayGraphScanParams{
Watches: watches,
ProjectKey: project,
GitRepoHttpsCloneUrl: httpCloneUrl,
Watches: watches,
ProjectKey: project,
GitRepoHttpsCloneUrl: httpCloneUrl,
IncludeVulnerabilities: includeVulnerabilities,
IncludeLicenses: includeLicenses,
ScanType: services.Dependency,
IncludeLicenses: includeLicenses,
ScanType: services.Dependency,
}
}

Expand Down
Loading

0 comments on commit f11f066

Please sign in to comment.