@@ -31,7 +31,6 @@ func CreateFS(t *testing.T, files map[string]string) fs.FS {
31
31
}
32
32
33
33
func Test_RegoScanning_Deny (t * testing.T ) {
34
-
35
34
srcFS := CreateFS (t , map [string ]string {
36
35
"policies/test.rego" : `
37
36
package defsec.test
@@ -64,14 +63,13 @@ deny {
64
63
}
65
64
66
65
func Test_RegoScanning_AbsolutePolicyPath_Deny (t * testing.T ) {
67
-
68
66
tmp := t .TempDir ()
69
- require .NoError (t , os .Mkdir (filepath .Join (tmp , "policies" ), 0755 ))
67
+ require .NoError (t , os .Mkdir (filepath .Join (tmp , "policies" ), 0o755 ))
70
68
require .NoError (t , os .WriteFile (filepath .Join (tmp , "policies" , "test.rego" ), []byte (`package defsec.test
71
69
72
70
deny {
73
71
input.evil
74
- }` ), 0600 ))
72
+ }` ), 0o600 ))
75
73
76
74
srcFS := os .DirFS (tmp )
77
75
@@ -128,7 +126,6 @@ deny {
128
126
}
129
127
130
128
func Test_RegoScanning_WithRuntimeValues (t * testing.T ) {
131
-
132
129
t .Setenv ("DEFSEC_RUNTIME_VAL" , "AOK" )
133
130
134
131
srcFS := CreateFS (t , map [string ]string {
@@ -230,7 +227,6 @@ deny[res] {
230
227
assert .Equal (t , "/evil.lol" , results .GetFailed ()[0 ].Metadata ().Range ().GetFilename ())
231
228
assert .Equal (t , 123 , results .GetFailed ()[0 ].Metadata ().Range ().GetStartLine ())
232
229
assert .Equal (t , 456 , results .GetFailed ()[0 ].Metadata ().Range ().GetEndLine ())
233
-
234
230
}
235
231
236
232
func Test_RegoScanning_WithDenyMetadata_PersistedPath (t * testing.T ) {
@@ -271,7 +267,6 @@ deny[res] {
271
267
assert .Equal (t , "/blah.txt" , results .GetFailed ()[0 ].Metadata ().Range ().GetFilename ())
272
268
assert .Equal (t , 123 , results .GetFailed ()[0 ].Metadata ().Range ().GetStartLine ())
273
269
assert .Equal (t , 456 , results .GetFailed ()[0 ].Metadata ().Range ().GetEndLine ())
274
-
275
270
}
276
271
277
272
func Test_RegoScanning_WithStaticMetadata (t * testing.T ) {
@@ -332,7 +327,6 @@ deny[res] {
332
327
assert .Equal (t , severity .Low , failure .Rule ().Severity )
333
328
assert .Equal (t , "This is a recommendation" , failure .Rule ().Resolution )
334
329
assert .Equal (t , "https://google.com" , failure .Rule ().Links [0 ])
335
-
336
330
}
337
331
338
332
func Test_RegoScanning_WithMatchingInputSelector (t * testing.T ) {
@@ -403,7 +397,6 @@ deny {
403
397
}
404
398
405
399
func Test_RegoScanning_NoTracingByDefault (t * testing.T ) {
406
-
407
400
srcFS := CreateFS (t , map [string ]string {
408
401
"policies/test.rego" : `
409
402
package defsec.test
@@ -435,7 +428,6 @@ deny {
435
428
}
436
429
437
430
func Test_RegoScanning_GlobalTracingEnabled (t * testing.T ) {
438
-
439
431
srcFS := CreateFS (t , map [string ]string {
440
432
"policies/test.rego" : `
441
433
package defsec.test
@@ -471,7 +463,6 @@ deny {
471
463
}
472
464
473
465
func Test_RegoScanning_PerResultTracingEnabled (t * testing.T ) {
474
-
475
466
srcFS := CreateFS (t , map [string ]string {
476
467
"policies/test.rego" : `
477
468
package defsec.test
@@ -504,7 +495,6 @@ deny {
504
495
}
505
496
506
497
func Test_dynamicMetadata (t * testing.T ) {
507
-
508
498
srcFS := CreateFS (t , map [string ]string {
509
499
"policies/test.rego" : `
510
500
package defsec.test
@@ -536,7 +526,6 @@ deny {
536
526
}
537
527
538
528
func Test_staticMetadata (t * testing.T ) {
539
-
540
529
srcFS := CreateFS (t , map [string ]string {
541
530
"policies/test.rego" : `
542
531
package defsec.test
@@ -568,7 +557,6 @@ deny {
568
557
}
569
558
570
559
func Test_annotationMetadata (t * testing.T ) {
571
-
572
560
srcFS := CreateFS (t , map [string ]string {
573
561
"policies/test.rego" : `# METADATA
574
562
# title: i am a title
@@ -623,7 +611,6 @@ deny {
623
611
}
624
612
625
613
func Test_RegoScanning_WithInvalidInputSchema (t * testing.T ) {
626
-
627
614
srcFS := CreateFS (t , map [string ]string {
628
615
"policies/test.rego" : `# METADATA
629
616
# schemas:
@@ -643,7 +630,6 @@ deny {
643
630
}
644
631
645
632
func Test_RegoScanning_WithValidInputSchema (t * testing.T ) {
646
-
647
633
srcFS := CreateFS (t , map [string ]string {
648
634
"policies/test.rego" : `# METADATA
649
635
# schemas:
@@ -766,7 +752,6 @@ deny {
766
752
}
767
753
768
754
func Test_NoErrorsWhenUsingBadRegoCheck (t * testing.T ) {
769
-
770
755
// this check cause eval_conflict_error
771
756
// https://www.openpolicyagent.org/docs/latest/policy-language/#functions
772
757
fsys := fstest.MapFS {
@@ -793,7 +778,7 @@ deny {
793
778
}
794
779
795
780
func Test_RegoScanning_WithDeprecatedCheck (t * testing.T ) {
796
- var testCases = []struct {
781
+ testCases : = []struct {
797
782
name string
798
783
policy string
799
784
expectedResults int
@@ -865,7 +850,6 @@ deny {
865
850
}
866
851
867
852
func Test_RegoScanner_WithCustomSchemas (t * testing.T ) {
868
-
869
853
schema := `{
870
854
"$id": "https://example.com/test.schema.json",
871
855
"$schema": "https://json-schema.org/draft/2020-12/schema",
@@ -934,7 +918,6 @@ deny {
934
918
}
935
919
936
920
func Test_RegoScanner_WithDisabledCheckIDs (t * testing.T ) {
937
-
938
921
check := `# METADATA
939
922
# custom:
940
923
# id: TEST-001
@@ -1000,7 +983,6 @@ deny {
1000
983
1001
984
for _ , tt := range tests {
1002
985
t .Run (tt .name , func (t * testing.T ) {
1003
-
1004
986
scanner := rego .NewScanner (
1005
987
rego .WithPolicyReader (strings .NewReader (tt .inputCheck )),
1006
988
rego .WithDisabledCheckIDs (tt .disabledChecks ... ),
0 commit comments