diff --git a/policy/score_calculator.go b/policy/score_calculator.go index cf03d67f..4a5f9060 100644 --- a/policy/score_calculator.go +++ b/policy/score_calculator.go @@ -67,28 +67,6 @@ func AddSpecdScore(calculator ScoreCalculator, s *Score, found bool, impact *exp return } - // everything else is modify or activate - - if impact.Scoring == explorer.ScoringSystem_IGNORE_SCORE { - calculator.Add(&Score{ - // We override the type because: - // 1. If it is set to Result, its value will be added to the total - // calculation in most calculators despite its weight. - // 2. We don't want to set it to unscored, because technically we - // just ignore the score. - // Thus we set the score to unknown for the sake of the calculator, - // thus it knows it is handling a scored result, but also knows not - // to count it. - Type: ScoreType_Unknown, - Value: score.Value, - Weight: 0, - ScoreCompletion: score.ScoreCompletion, - DataCompletion: score.DataCompletion, - DataTotal: score.DataTotal, - }, nil) - return - } - if impact.Weight > 0 { score.Weight = uint32(impact.Weight) } else if score.Weight == 0 { @@ -490,22 +468,22 @@ func (c *bandedScoreCalculator) Add(score *Score, impact *explorer.Impact) { if category <= 10 { c.critMax += score.Weight - if score.Value == 100 { + if score.Value < 100 { c.crit += score.Weight } } else if category <= 30 { c.highMax += score.Weight - if score.Value == 100 { + if score.Value < 100 { c.high += score.Weight } } else if category <= 60 { c.midMax += score.Weight - if score.Value == 100 { + if score.Value < 100 { c.mid += score.Weight } } else { c.lowMax += score.Weight - if score.Value == 100 { + if score.Value < 100 { c.low += score.Weight } } diff --git a/policy/score_calculator_test.go b/policy/score_calculator_test.go index e0e50174..6b277e7b 100644 --- a/policy/score_calculator_test.go +++ b/policy/score_calculator_test.go @@ -222,7 +222,7 @@ func TestBandedScores(t *testing.T) { {Value: &explorer.ImpactValue{Value: 100}}, {Action: explorer.Action_IGNORE}, }, - out: &Score{Value: 25, ScoreCompletion: 100, DataCompletion: 66, Weight: 10, Type: ScoreType_Result}, + out: &Score{Value: 22, ScoreCompletion: 100, DataCompletion: 66, Weight: 10, Type: ScoreType_Result}, }, { in: []*Score{ @@ -239,7 +239,24 @@ func TestBandedScores(t *testing.T) { // 10 high checks {Value: &explorer.ImpactValue{Value: 80}}, }, - out: &Score{Value: 45, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result}, + out: &Score{Value: 1, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result}, + }, + { + in: []*Score{ + // 10 critical checks (9ok, 1not) + {Value: 1000, ScoreCompletion: 100, DataCompletion: 80, DataTotal: 5, Weight: 1, Type: ScoreType_Result}, + {Value: 100, ScoreCompletion: 100, DataCompletion: 100, DataTotal: 1, Weight: 9, Type: ScoreType_Result}, + // 10 high checks (ok) + {Value: 100, ScoreCompletion: 100, DataCompletion: 33, DataTotal: 3, Weight: 10, Type: ScoreType_Result}, + }, + impacts: []*explorer.Impact{ + // 10 critical checks + {Value: &explorer.ImpactValue{Value: 100}}, + {Value: &explorer.ImpactValue{Value: 100}}, + // 10 high checks + {Value: &explorer.ImpactValue{Value: 80}}, + }, + out: &Score{Value: 100, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result}, }, { in: []*Score{ @@ -256,7 +273,7 @@ func TestBandedScores(t *testing.T) { // 10 high checks {Value: &explorer.ImpactValue{Value: 80}}, }, - out: &Score{Value: 9, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result}, + out: &Score{Value: 5, ScoreCompletion: 100, DataCompletion: 66, Weight: 20, Type: ScoreType_Result}, }, }) }