Skip to content

Commit

Permalink
🐛 set IsDetected for scored risks (#1241)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Apr 8, 2024
1 parent eca571a commit 5deae50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
16 changes: 10 additions & 6 deletions policy/risk_factor.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (r *RiskFactor) AdjustRiskScore(score *Score, isDetected bool) {
Mrn: r.Mrn,
Risk: r.Magnitude,
IsAbsolute: true,
IsDetected: isDetected,
})
return
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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,
})
}

Expand Down
24 changes: 12 additions & 12 deletions policy/risk_factor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
}
Expand Down

0 comments on commit 5deae50

Please sign in to comment.