File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -197,13 +197,13 @@ func (s *Scanner) findMatchedEmbeddedCheck(badPolicy *ast.Module) *ast.Module {
197
197
}
198
198
199
199
badPolicyMeta , err := MetadataFromAnnotations (badPolicy )
200
- if err != nil {
200
+ if err != nil || badPolicyMeta == nil {
201
201
return nil
202
202
}
203
203
204
204
for _ , embeddedCheck := range s .embeddedChecks {
205
205
meta , err := MetadataFromAnnotations (embeddedCheck )
206
- if err != nil {
206
+ if err != nil || meta == nil {
207
207
continue
208
208
}
209
209
if badPolicyMeta .AVDID != "" && badPolicyMeta .AVDID == meta .AVDID {
Original file line number Diff line number Diff line change @@ -205,7 +205,11 @@ deny {
205
205
}` ),
206
206
}
207
207
208
+ originalFS := checks .EmbeddedPolicyFileSystem
208
209
checks .EmbeddedPolicyFileSystem = embeddedChecksFS
210
+ t .Cleanup (func () {
211
+ checks .EmbeddedPolicyFileSystem = originalFS
212
+ })
209
213
err := scanner .LoadPolicies (fstest .MapFS (tt .files ))
210
214
211
215
if tt .expectedErr != "" {
@@ -253,3 +257,19 @@ deny {
253
257
err := scanner .LoadPolicies (fsys )
254
258
require .Error (t , err )
255
259
}
260
+
261
+ func TestFallback_CheckWithoutAnnotation (t * testing.T ) {
262
+ fsys := fstest.MapFS {
263
+ "check.rego" : & fstest.MapFile {Data : []byte (`package builtin.test
264
+ import data.some_func
265
+ deny := some_func(input)
266
+ ` )},
267
+ }
268
+ scanner := rego .NewScanner (
269
+ rego .WithPolicyDirs ("." ),
270
+ rego .WithEmbeddedLibraries (false ),
271
+ rego .WithPolicyFilesystem (fsys ),
272
+ )
273
+ err := scanner .LoadPolicies (nil )
274
+ require .NoError (t , err )
275
+ }
You can’t perform that action at this time.
0 commit comments