Skip to content

Commit fdda434

Browse files
set configuration status if there are no conf
Signed-off-by: YiscahLevySilas1 <[email protected]>
1 parent e68640b commit fdda434

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

reporthandling/results/v1/resourcesresults/controls.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (control *ResourceAssociatedControl) SetStatus(c reporthandling.Control) {
103103
}
104104

105105
// If the control type is configuration and the configuration is not set, the status is skipped and the sub status is configuration
106-
if actionRequired == apis.SubStatusConfiguration && controlMissingConfiguration(control) {
106+
if actionRequired == apis.SubStatusConfiguration && controlMissingAllConfigurations(control) {
107107
status = apis.StatusSkipped
108108
subStatus = apis.SubStatusConfiguration
109109
statusInfo = string(apis.SubStatusConfigurationInfo)
@@ -120,17 +120,17 @@ func (control *ResourceAssociatedControl) ListRules() []ResourceAssociatedRule {
120120
return control.ResourceAssociatedRules
121121
}
122122

123-
// controlMissingConfiguration return true if the control is missing configuration
124-
func controlMissingConfiguration(control *ResourceAssociatedControl) bool {
123+
// controlMissingAllConfiguration returns true if all control configurations are missing
124+
func controlMissingAllConfigurations(control *ResourceAssociatedControl) bool {
125125
for _, rule := range control.ResourceAssociatedRules {
126126
if len(rule.ControlConfigurations) == 0 {
127127
return true
128128
}
129129
for _, configuration := range rule.ControlConfigurations {
130-
if len(configuration) == 0 {
131-
return true
130+
if len(configuration) != 0 {
131+
return false
132132
}
133133
}
134134
}
135-
return false
135+
return true
136136
}

reporthandling/results/v1/resourcesresults/controls_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,73 @@ func Test_GetStatusAndSubStatus_NewResourceAssociatedControls(t *testing.T) {
162162
assert.Equal(t, controlIdToExpectedSubStatus[control.ControlID], string(control.GetSubStatus()))
163163
}
164164
}
165+
166+
func TestControlMissingAllConfigurations(t *testing.T) {
167+
tests := []struct {
168+
name string
169+
control *ResourceAssociatedControl
170+
want bool
171+
}{
172+
{
173+
name: "TestControlNoConfigurations",
174+
control: &ResourceAssociatedControl{
175+
ResourceAssociatedRules: []ResourceAssociatedRule{
176+
{
177+
ControlConfigurations: map[string][]string{},
178+
},
179+
},
180+
},
181+
want: true,
182+
}, {
183+
name: "TestControlOneEmptyConfiguration",
184+
control: &ResourceAssociatedControl{
185+
ResourceAssociatedRules: []ResourceAssociatedRule{
186+
{
187+
ControlConfigurations: map[string][]string{
188+
"EmptyConfiguration": {},
189+
},
190+
},
191+
},
192+
},
193+
want: true,
194+
},
195+
{
196+
name: "TestControlOneNonEmptyConfiguration",
197+
control: &ResourceAssociatedControl{
198+
ResourceAssociatedRules: []ResourceAssociatedRule{
199+
{
200+
ControlConfigurations: map[string][]string{
201+
"NonEmptyConfiguration": {
202+
"key", "value",
203+
},
204+
},
205+
},
206+
},
207+
},
208+
want: false,
209+
},
210+
{
211+
name: "TestControlMultipleConfigurations",
212+
control: &ResourceAssociatedControl{
213+
ResourceAssociatedRules: []ResourceAssociatedRule{
214+
{
215+
ControlConfigurations: map[string][]string{
216+
"EmptyConfiguration": {},
217+
"NonEmptyConfiguration": {
218+
"key", "value",
219+
},
220+
},
221+
},
222+
},
223+
},
224+
want: false,
225+
},
226+
}
227+
for _, tt := range tests {
228+
t.Run(tt.name, func(t *testing.T) {
229+
if got := controlMissingAllConfigurations(tt.control); got != tt.want {
230+
t.Errorf("Control.missingAllConfigurations() = %v, want %v", got, tt.want)
231+
}
232+
})
233+
}
234+
}

0 commit comments

Comments
 (0)