Skip to content

Commit 4c206b4

Browse files
fix compliance score- case of passed-irrelevant
Signed-off-by: YiscahLevySilas1 <[email protected]>
1 parent 4cd9101 commit 4c206b4

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

score/score.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,13 @@ func (su *ScoreUtil) GetControlComplianceScore(ctrl reportsummary.IControlSummar
425425
if numOfAllResources > 0 {
426426
ctrlScore = (numOfPassedResources / numOfAllResources) * 100
427427
} else {
428-
logger.L().Debug("no resources were given for this control, score is 0", helpers.String("controlID", ctrl.GetID()))
428+
// in case the control didn't run on any resources:
429+
// If the control passed (irrelevant): score = 100 , else (skipped): score = 0
430+
if ctrl.GetStatus().IsPassed() {
431+
ctrlScore = 100
432+
} else {
433+
logger.L().Debug("no resources were given for this control, score is 0", helpers.String("controlID", ctrl.GetID()))
434+
}
429435
}
430436

431437
return ctrlScore

score/score_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,46 @@ func TestGetControlComplianceScore(t *testing.T) {
814814
)
815815
})
816816

817+
t.Run("skipped control", func(t *testing.T) {
818+
t.Parallel()
819+
820+
resources := mockResources(t)
821+
s := ScoreUtil{isDebugMode: true, resources: resources}
822+
controlReport := reportsummary.ControlSummary{
823+
Name: "skipped-control",
824+
ControlID: "skipped1",
825+
StatusInfo: apis.StatusInfo{
826+
InnerInfo: "enable-host-scan flag not used. For more information: https://hub.armosec.io/docs/host-sensor",
827+
InnerStatus: "skipped",
828+
},
829+
ResourceIDs: helpers.AllLists{},
830+
}
831+
832+
require.Equal(t, float32(0), s.GetControlComplianceScore(&controlReport, ""),
833+
"skipped control report should return a score equals to 0",
834+
)
835+
})
836+
837+
t.Run("passed (irrelevant) control", func(t *testing.T) {
838+
t.Parallel()
839+
840+
resources := mockResources(t)
841+
s := ScoreUtil{isDebugMode: true, resources: resources}
842+
controlReport := reportsummary.ControlSummary{
843+
Name: "irrelevant-control",
844+
ControlID: "irrelevant1",
845+
StatusInfo: apis.StatusInfo{
846+
SubStatus: "irrelevant",
847+
InnerStatus: "passed",
848+
},
849+
ResourceIDs: helpers.AllLists{},
850+
}
851+
852+
require.Equal(t, float32(100), s.GetControlComplianceScore(&controlReport, ""),
853+
"passed (irrelevant) control report should return a score equals to 100",
854+
)
855+
})
856+
817857
t.Run("with control report", func(t *testing.T) {
818858
t.Parallel()
819859

0 commit comments

Comments
 (0)