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

Adding fields to Policy struct to support skip not applicable #1067

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions tests/xraypolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createMinSeverity(t *testing.T) {

policyRule := utils.PolicyRule{
Name: "min-severity" + getRunId(),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Low),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Low, false),
Priority: 1,
}
createAndCheckPolicy(t, policyName, true, utils.Security, policyRule)
Expand Down Expand Up @@ -78,12 +78,12 @@ func create2Priorities(t *testing.T) {

policyRule1 := utils.PolicyRule{
Name: "priority-1" + getRunId(),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Low),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Low, false),
Priority: 1,
}
policyRule2 := utils.PolicyRule{
Name: "priority-2" + getRunId(),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Medium),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Medium, false),
Priority: 2,
}
createAndCheckPolicy(t, policyName, true, utils.Security, policyRule1, policyRule2)
Expand All @@ -95,7 +95,7 @@ func createPolicyActions(t *testing.T) {

policyRule := utils.PolicyRule{
Name: "policy-actions" + getRunId(),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.High),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.High, false),
Priority: 1,
Actions: &utils.PolicyAction{
BlockDownload: utils.PolicyBlockDownload{
Expand All @@ -118,14 +118,14 @@ func createUpdatePolicy(t *testing.T) {

policyRule := utils.PolicyRule{
Name: "low-severity" + getRunId(),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Low),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Low, false),
Priority: 1,
}
createAndCheckPolicy(t, policyName, true, utils.Security, policyRule)

policyRule = utils.PolicyRule{
Name: "medium-severity" + getRunId(),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Medium),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Medium, false),
Priority: 1,
}

Expand Down
2 changes: 1 addition & 1 deletion tests/xraywatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func createDummyPolicy(policyName string) error {
Type: utils.Security,
Rules: []utils.PolicyRule{{
Name: "sec_rule",
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Medium),
Criteria: *utils.CreateSeverityPolicyCriteria(utils.Medium, false),
Actions: &utils.PolicyAction{
Webhooks: []string{},
BlockDownload: utils.PolicyBlockDownload{
Expand Down
7 changes: 5 additions & 2 deletions xray/services/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,11 @@ type JfrogResearchSeverityReason struct {
}

type Policy struct {
Policy string `json:"policy,omitempty"`
Rule string `json:"rule,omitempty"`
Policy string `json:"policy,omitempty"`
Rule string `json:"rule,omitempty"`
IsBlocking bool `json:"is_blocking,omitempty"`
IgnoreRuleId string `json:"ignore_rule_id,omitempty"`
SkipNotApplicable bool `json:"is_skip_not_applicable,omitempty"`
}

func (gp *XrayGraphScanParams) GetProjectKey() string {
Expand Down
14 changes: 8 additions & 6 deletions xray/services/utils/policybody.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ type PolicyRule struct {

type PolicyCriteria struct {
// Security
MinSeverity Severity `json:"min_severity,omitempty"`
CvssRange *PolicyCvssRange `json:"cvss_range,omitempty"`
Exposures *PolicyExposureCriteria `json:"exposures,omitempty"`
Sast *PolicySastCriteria `json:"sast,omitempty"`
MinSeverity Severity `json:"min_severity,omitempty"`
CvssRange *PolicyCvssRange `json:"cvss_range,omitempty"`
Exposures *PolicyExposureCriteria `json:"exposures,omitempty"`
Sast *PolicySastCriteria `json:"sast,omitempty"`
SkipNotApplicableCVEs bool `json:"applicable_cves_only,omitempty"`

// License
AllowedLicenses []string `json:"allowed_licenses,omitempty"`
Expand Down Expand Up @@ -102,9 +103,10 @@ type PolicyBlockDownload struct {
}

// Create security policy criteria with min severity
func CreateSeverityPolicyCriteria(minSeverity Severity) *PolicyCriteria {
func CreateSeverityPolicyCriteria(minSeverity Severity, skipNotApplicableCves bool) *PolicyCriteria {
return &PolicyCriteria{
MinSeverity: minSeverity,
MinSeverity: minSeverity,
SkipNotApplicableCVEs: skipNotApplicableCves,
}
}

Expand Down
Loading