From 5deae505ddb76edc282b13c42e78e1aa8873e382 Mon Sep 17 00:00:00 2001 From: Ivan Milchev Date: Mon, 8 Apr 2024 13:20:41 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20set=20IsDetected=20for=20scored?= =?UTF-8?q?=20risks=20(#1241)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ivan Milchev --- policy/risk_factor.go | 16 ++++++++++------ policy/risk_factor_test.go | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/policy/risk_factor.go b/policy/risk_factor.go index 0829a591..15888af5 100644 --- a/policy/risk_factor.go +++ b/policy/risk_factor.go @@ -140,6 +140,7 @@ func (r *RiskFactor) AdjustRiskScore(score *Score, isDetected bool) { Mrn: r.Mrn, Risk: r.Magnitude, IsAbsolute: true, + IsDetected: isDetected, }) return } @@ -154,8 +155,9 @@ func (r *RiskFactor) AdjustRiskScore(score *Score, isDetected bool) { score.RiskFactors = &ScoredRiskFactors{} } score.RiskFactors.Items = append(score.RiskFactors.Items, &ScoredRiskFactor{ - Mrn: r.Mrn, - Risk: r.Magnitude, + Mrn: r.Mrn, + Risk: r.Magnitude, + IsDetected: isDetected, }) return } @@ -173,8 +175,9 @@ func (r *RiskFactor) AdjustRiskScore(score *Score, isDetected bool) { score.RiskFactors = &ScoredRiskFactors{} } score.RiskFactors.Items = append(score.RiskFactors.Items, &ScoredRiskFactor{ - Mrn: r.Mrn, - Risk: r.Magnitude, + Mrn: r.Mrn, + Risk: r.Magnitude, + IsDetected: isDetected, }) return } @@ -184,8 +187,9 @@ func (r *RiskFactor) AdjustRiskScore(score *Score, isDetected bool) { score.RiskFactors = &ScoredRiskFactors{} } score.RiskFactors.Items = append(score.RiskFactors.Items, &ScoredRiskFactor{ - Mrn: r.Mrn, - Risk: -r.Magnitude, + Mrn: r.Mrn, + Risk: -r.Magnitude, + IsDetected: isDetected, }) } diff --git a/policy/risk_factor_test.go b/policy/risk_factor_test.go index 58ac65ce..126c5df0 100644 --- a/policy/risk_factor_test.go +++ b/policy/risk_factor_test.go @@ -193,76 +193,76 @@ func TestRiskFactor_AdjustRiskScore(t *testing.T) { { risk: RiskFactor{Magnitude: 0.4}, score: Score{RiskScore: 40}, - onDetect: Score{RiskScore: 40, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.4})}, + onDetect: Score{RiskScore: 40, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.4, IsDetected: true})}, onFail: Score{RiskScore: 64, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4})}, }, { risk: RiskFactor{Mrn: "internet-facing", Magnitude: 0.4}, score: Score{RiskScore: 10}, - onDetect: Score{RiskScore: 10, RiskFactors: risks(&ScoredRiskFactor{Mrn: "internet-facing", Risk: 0.4})}, + onDetect: Score{RiskScore: 10, RiskFactors: risks(&ScoredRiskFactor{Mrn: "internet-facing", Risk: 0.4, IsDetected: true})}, onFail: Score{RiskScore: 45, RiskFactors: risks(&ScoredRiskFactor{Mrn: "internet-facing", Risk: -0.4})}, }, { risk: RiskFactor{Magnitude: 0.4}, score: Score{RiskScore: 90}, - onDetect: Score{RiskScore: 90, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.4})}, + onDetect: Score{RiskScore: 90, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.4, IsDetected: true})}, onFail: Score{RiskScore: 94, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4})}, }, // Absolute, decrease risk { risk: RiskFactor{Magnitude: -0.4}, score: Score{RiskScore: 40}, - onDetect: Score{RiskScore: 64, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4})}, + onDetect: Score{RiskScore: 64, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4, IsDetected: true})}, onFail: Score{RiskScore: 40}, }, { risk: RiskFactor{Magnitude: -0.4}, score: Score{RiskScore: 10}, - onDetect: Score{RiskScore: 45, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4})}, + onDetect: Score{RiskScore: 45, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4, IsDetected: true})}, onFail: Score{RiskScore: 10}, }, { risk: RiskFactor{Magnitude: -0.4}, score: Score{RiskScore: 90}, - onDetect: Score{RiskScore: 94, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4})}, + onDetect: Score{RiskScore: 94, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.4, IsDetected: true})}, onFail: Score{RiskScore: 90}, }, // Absolute, increase risk { risk: RiskFactor{Magnitude: 0.2, IsAbsolute: true}, score: Score{RiskScore: 40}, - onDetect: Score{RiskScore: 20, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.2, IsAbsolute: true})}, + onDetect: Score{RiskScore: 20, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.2, IsAbsolute: true, IsDetected: true})}, onFail: Score{RiskScore: 40}, }, { risk: RiskFactor{Magnitude: 0.2, IsAbsolute: true}, score: Score{RiskScore: 10}, - onDetect: Score{RiskScore: 0, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.2, IsAbsolute: true})}, + onDetect: Score{RiskScore: 0, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.2, IsAbsolute: true, IsDetected: true})}, onFail: Score{RiskScore: 10}, }, { risk: RiskFactor{Magnitude: 0.2, IsAbsolute: true}, score: Score{RiskScore: 90}, - onDetect: Score{RiskScore: 70, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.2, IsAbsolute: true})}, + onDetect: Score{RiskScore: 70, RiskFactors: risks(&ScoredRiskFactor{Risk: 0.2, IsAbsolute: true, IsDetected: true})}, onFail: Score{RiskScore: 90}, }, // Absolute, decrease risk { risk: RiskFactor{Magnitude: -0.2, IsAbsolute: true}, score: Score{RiskScore: 40}, - onDetect: Score{RiskScore: 60, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.2, IsAbsolute: true})}, + onDetect: Score{RiskScore: 60, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.2, IsAbsolute: true, IsDetected: true})}, onFail: Score{RiskScore: 40}, }, { risk: RiskFactor{Magnitude: -0.2, IsAbsolute: true}, score: Score{RiskScore: 10}, - onDetect: Score{RiskScore: 30, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.2, IsAbsolute: true})}, + onDetect: Score{RiskScore: 30, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.2, IsAbsolute: true, IsDetected: true})}, onFail: Score{RiskScore: 10}, }, { risk: RiskFactor{Magnitude: -0.2, IsAbsolute: true}, score: Score{RiskScore: 90}, - onDetect: Score{RiskScore: 100, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.2, IsAbsolute: true})}, + onDetect: Score{RiskScore: 100, RiskFactors: risks(&ScoredRiskFactor{Risk: -0.2, IsAbsolute: true, IsDetected: true})}, onFail: Score{RiskScore: 90}, }, }