@@ -1153,3 +1153,87 @@ deny {
1153
1153
})
1154
1154
}
1155
1155
}
1156
+
1157
+ func Test_RegoScanner_WithDisabledCheckIDs (t * testing.T ) {
1158
+
1159
+ check := `# METADATA
1160
+ # custom:
1161
+ # id: TEST-001
1162
+ # avd_id: AVD-TEST-001
1163
+ # severity: LOW
1164
+ # provider: aws
1165
+ # service: s3
1166
+ # short_code: test
1167
+ package builtin.test
1168
+
1169
+ deny {
1170
+ true
1171
+ }
1172
+ `
1173
+
1174
+ tests := []struct {
1175
+ name string
1176
+ disabledChecks []string
1177
+ inputCheck string
1178
+ expected bool
1179
+ }{
1180
+ {
1181
+ name : "no disabled checks" ,
1182
+ expected : true ,
1183
+ inputCheck : check ,
1184
+ },
1185
+ {
1186
+ name : "disable check by ID" ,
1187
+ disabledChecks : []string {"TEST-001" },
1188
+ inputCheck : check ,
1189
+ },
1190
+ {
1191
+ name : "disabling a non-existent check" ,
1192
+ disabledChecks : []string {"FOO" },
1193
+ expected : true ,
1194
+ inputCheck : check ,
1195
+ },
1196
+ {
1197
+ name : "one of the identifiers does not exist" ,
1198
+ disabledChecks : []string {"FOO" , "TEST-001" },
1199
+ inputCheck : check ,
1200
+ },
1201
+ {
1202
+ name : "do not disable user checks with builtin IDs" ,
1203
+ inputCheck : `# METADATA
1204
+ # custom:
1205
+ # id: TEST-001
1206
+ # avd_id: AVD-TEST-001
1207
+ # severity: LOW
1208
+ # provider: aws
1209
+ # service: s3
1210
+ # short_code: test
1211
+ package user.test
1212
+
1213
+ deny {
1214
+ true
1215
+ }
1216
+ ` ,
1217
+ disabledChecks : []string {"TEST-001" },
1218
+ expected : true ,
1219
+ },
1220
+ }
1221
+
1222
+ for _ , tt := range tests {
1223
+ t .Run (tt .name , func (t * testing.T ) {
1224
+
1225
+ scanner := rego .NewScanner (
1226
+ types .SourceYAML ,
1227
+ rego .WithPolicyReader (strings .NewReader (tt .inputCheck )),
1228
+ rego .WithDisabledCheckIDs (tt .disabledChecks ... ),
1229
+ rego .WithPolicyNamespaces ("user" ),
1230
+ )
1231
+
1232
+ require .NoError (t , scanner .LoadPolicies (nil ))
1233
+ results , err := scanner .ScanInput (context .TODO (), rego.Input {})
1234
+ require .NoError (t , err )
1235
+
1236
+ require .Equal (t , tt .expected , len (results .GetFailed ()) > 0 )
1237
+ })
1238
+ }
1239
+ }
0 commit comments