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

Bugfix: properly aggregate rule findings #207

Merged
merged 1 commit into from Sep 13, 2023
Merged
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
17 changes: 12 additions & 5 deletions chirps/scan/views.py
Expand Up @@ -57,16 +57,23 @@ def get_unique_rules_and_findings(results):
rule = result.rule

if rule.id not in rule_dict:
rule.finding_count = 0
rule.findings = []
rule_dict[rule.id] = rule
rule_dict[rule.id] = {'rule': rule, 'findings_count': 0, 'findings': []}

rule_data = rule_dict[rule.id]

findings = list(result.findings.all())
count = len(findings)
rule.finding_count += count
rule.findings.extend(findings)

rule_data['findings_count'] += count
rule_data['findings'].extend(findings)

finding_count += count
finding_severities[rule.severity] += count

for rule_data in rule_dict.values():
rule = rule_data['rule']
rule.findings_count = rule_data['findings_count']
rule.findings = rule_data['findings']
unique_rules[type(rule)].add(rule)

return unique_rules, finding_count, finding_severities
Expand Down