Skip to content

Commit 7b43839

Browse files
committed
Fix tests
Signed-off-by: Tushar Goel <[email protected]>
1 parent 847754f commit 7b43839

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

vulnerabilities/pipelines/v2_improvers/compute_package_risk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from vulnerabilities.models import AdvisoryV2
1212
from vulnerabilities.models import PackageV2
1313
from vulnerabilities.pipelines import VulnerableCodePipeline
14-
from vulnerabilities.risk import compute_package_risk
14+
from vulnerabilities.risk import compute_package_risk_v2
1515
from vulnerabilities.risk import compute_vulnerability_risk_factors
1616

1717

vulnerabilities/risk.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ def compute_vulnerability_risk_factors(references, severities, exploits):
101101

102102

103103
def compute_package_risk(package):
104+
"""
105+
Calculate the risk for a package by iterating over all vulnerabilities that affects this package
106+
and determining the associated risk.
107+
"""
108+
result = []
109+
for relation in package.affectedbypackagerelatedvulnerability_set.all():
110+
if risk := relation.vulnerability.risk_score:
111+
result.append(float(risk))
112+
113+
if not result:
114+
return
115+
116+
return round(max(result), 1)
117+
118+
119+
def compute_package_risk_v2(package):
104120
"""
105121
Calculate the risk for a package by iterating over all vulnerabilities that affects this package
106122
and determining the associated risk.
@@ -113,4 +129,4 @@ def compute_package_risk(package):
113129
if not result:
114130
return
115131

116-
return round(max(result), 1)
132+
return round(max(result), 1)

0 commit comments

Comments
 (0)