1
1
package podsecurityreadinesscontroller
2
2
3
3
import (
4
+ "strings"
4
5
"testing"
5
6
6
7
operatorv1 "github.com/openshift/api/operator/v1"
@@ -117,6 +118,7 @@ func TestOperatorStatus(t *testing.T) {
117
118
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
118
119
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
119
120
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
121
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
120
122
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
121
123
},
122
124
},
@@ -138,6 +140,7 @@ func TestOperatorStatus(t *testing.T) {
138
140
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
139
141
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
140
142
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionTrue ,
143
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
141
144
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
142
145
},
143
146
},
@@ -159,6 +162,7 @@ func TestOperatorStatus(t *testing.T) {
159
162
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
160
163
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
161
164
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
165
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
162
166
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
163
167
},
164
168
},
@@ -177,6 +181,7 @@ func TestOperatorStatus(t *testing.T) {
177
181
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionTrue ,
178
182
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
179
183
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
184
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
180
185
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
181
186
},
182
187
},
@@ -195,6 +200,7 @@ func TestOperatorStatus(t *testing.T) {
195
200
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
196
201
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionTrue ,
197
202
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
203
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
198
204
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
199
205
},
200
206
},
@@ -221,6 +227,7 @@ func TestOperatorStatus(t *testing.T) {
221
227
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
222
228
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
223
229
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionTrue ,
230
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
224
231
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
225
232
},
226
233
},
@@ -251,6 +258,7 @@ func TestOperatorStatus(t *testing.T) {
251
258
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionTrue ,
252
259
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionTrue ,
253
260
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
261
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
254
262
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
255
263
},
256
264
},
@@ -270,6 +278,7 @@ func TestOperatorStatus(t *testing.T) {
270
278
"PodSecurityOpenshiftEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
271
279
"PodSecurityRunLevelZeroEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
272
280
"PodSecurityDisabledSyncerEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
281
+ "PodSecurityUserSCCEvaluationConditionsDetected" : operatorv1 .ConditionFalse ,
273
282
"PodSecurityInconclusiveEvaluationConditionsDetected" : operatorv1 .ConditionTrue ,
274
283
},
275
284
},
@@ -280,7 +289,17 @@ func TestOperatorStatus(t *testing.T) {
280
289
281
290
for _ , ns := range tt .namespace {
282
291
if tt .addViolation {
283
- cond .addViolation (ns )
292
+ // Classify namespace based on the same logic as classifyViolatingNamespace
293
+ if runLevelZeroNamespaces .Has (ns .Name ) {
294
+ cond .addViolatingRunLevelZero (ns )
295
+ } else if strings .HasPrefix (ns .Name , "openshift" ) {
296
+ cond .addViolatingOpenShift (ns )
297
+ } else if ns .Labels [labelSyncControlLabel ] == "false" {
298
+ cond .addViolatingDisabledSyncer (ns )
299
+ } else {
300
+ // Default to customer violation for test purposes
301
+ cond .addViolatingCustomer (ns )
302
+ }
284
303
}
285
304
if tt .addInconclusive {
286
305
cond .addInconclusive (ns )
0 commit comments