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

feat(report): Include licenses and secrets filtered by rego to ModifiedFindings #6483

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/result/filter.go
Expand Up @@ -303,6 +303,8 @@ func applyPolicy(ctx context.Context, result *types.Result, policyFile string) e
return err
}
if ignored {
result.ModifiedFindings = append(result.ModifiedFindings,
types.NewModifiedFinding(scrt, types.FindingStatusIgnored, "Filtered by Rego", policyFile))
continue
}
filteredSecrets = append(filteredSecrets, scrt)
Expand All @@ -317,6 +319,8 @@ func applyPolicy(ctx context.Context, result *types.Result, policyFile string) e
return err
}
if ignored {
result.ModifiedFindings = append(result.ModifiedFindings,
types.NewModifiedFinding(lic, types.FindingStatusIgnored, "Filtered by Rego", policyFile))
continue
}
filteredLicenses = append(filteredLicenses, lic)
Expand Down
65 changes: 21 additions & 44 deletions pkg/result/filter_test.go
Expand Up @@ -648,65 +648,42 @@ func TestFilter(t *testing.T) {
Results: types.Results{
{
Licenses: []types.DetectedLicense{
{
Name: "GPL-3.0",
Severity: dbTypes.SeverityLow.String(),
FilePath: "usr/share/gcc/python/libstdcxx/v6/__init__.py",
Category: "restricted",
Confidence: 1,
},
{
Name: "GPL-3.0",
Severity: dbTypes.SeverityLow.String(),
FilePath: "usr/share/gcc/python/libstdcxx/v6/printers.py",
Category: "restricted",
Confidence: 1,
},
license1,
license2,
},
Secrets: []types.DetectedSecret{
{
RuleID: "generic-passed-rule",
Severity: dbTypes.SeverityLow.String(),
Title: "Secret should pass filter",
StartLine: 1,
EndLine: 2,
Match: "*****",
},
{
RuleID: "generic-ignored-rule",
Severity: dbTypes.SeverityLow.String(),
Title: "Secret should be ignored",
StartLine: 3,
EndLine: 4,
Match: "*****",
},
secret1,
secret2,
},
},
},
},
severities: []dbTypes.Severity{dbTypes.SeverityLow},
severities: []dbTypes.Severity{dbTypes.SeverityLow, dbTypes.SeverityHigh},
policyFile: "./testdata/test-ignore-policy-licenses-and-secrets.rego",
},
want: types.Report{
Results: types.Results{
{
Licenses: []types.DetectedLicense{
{
Name: "GPL-3.0",
Severity: dbTypes.SeverityLow.String(),
FilePath: "usr/share/gcc/python/libstdcxx/v6/__init__.py",
Category: "restricted",
Confidence: 1,
},
license1,
},
Secrets: []types.DetectedSecret{
secret1,
},
ModifiedFindings: []types.ModifiedFinding{
{
Type: types.FindingTypeSecret,
Status: types.FindingStatusIgnored,
Statement: "Filtered by Rego",
Source: "testdata/test-ignore-policy-licenses-and-secrets.rego",
Finding: secret2,
},
{
RuleID: "generic-passed-rule",
Severity: dbTypes.SeverityLow.String(),
Title: "Secret should pass filter",
StartLine: 1,
EndLine: 2,
Match: "*****",
Type: types.FindingTypeLicense,
Status: types.FindingStatusIgnored,
Statement: "Filtered by Rego",
Source: "testdata/test-ignore-policy-licenses-and-secrets.rego",
Finding: license2,
},
},
},
Expand Down
Expand Up @@ -10,6 +10,6 @@ ignore {
}

ignore {
input.RuleID == "generic-ignored-rule"
input.Title == "Secret should be ignored"
input.RuleID == "generic-unwanted-rule"
input.Title == "Secret that should not pass filter on rule id"
}