@@ -10,8 +10,13 @@ import (
10
10
"github.com/stretchr/testify/require"
11
11
12
12
"github.com/aquasecurity/trivy/internal/testutil"
13
+ "github.com/aquasecurity/trivy/pkg/iac/providers"
14
+ "github.com/aquasecurity/trivy/pkg/iac/rules"
13
15
"github.com/aquasecurity/trivy/pkg/iac/scan"
14
16
"github.com/aquasecurity/trivy/pkg/iac/scanners/options"
17
+ "github.com/aquasecurity/trivy/pkg/iac/severity"
18
+ "github.com/aquasecurity/trivy/pkg/iac/state"
19
+ "github.com/aquasecurity/trivy/pkg/iac/types"
15
20
)
16
21
17
22
const emptyBucketRule = `
@@ -1065,3 +1070,50 @@ deny[res] {
1065
1070
occurrences := failed [0 ].Occurrences ()
1066
1071
assert .Equal (t , "code/example/main.tf" , occurrences [0 ].Filename )
1067
1072
}
1073
+
1074
+ func TestSkipDeprecatedGoChecks (t * testing.T ) {
1075
+
1076
+ check := scan.Rule {
1077
+ Provider : providers .AWSProvider ,
1078
+ Service : "service" ,
1079
+ ShortCode : "abc" ,
1080
+ Severity : severity .High ,
1081
+ Check : func (s * state.State ) (results scan.Results ) {
1082
+ results .Add ("Deny" , types .NewTestMetadata ())
1083
+ return
1084
+ },
1085
+ }
1086
+
1087
+ fsys := testutil .CreateFS (t , map [string ]string {
1088
+ "main.tf" : `resource "foo" "bar" {}` ,
1089
+ })
1090
+
1091
+ scanner := New (
1092
+ options .ScannerWithPolicyFilesystem (fsys ),
1093
+ options .ScannerWithEmbeddedLibraries (false ),
1094
+ options .ScannerWithEmbeddedPolicies (false ),
1095
+ ScannerWithAllDirectories (true ),
1096
+ )
1097
+
1098
+ t .Run ("deprecated" , func (t * testing.T ) {
1099
+ check .Deprecated = true
1100
+ reg := rules .Register (check )
1101
+ defer rules .Deregister (reg )
1102
+
1103
+ results , err := scanner .ScanFS (context .TODO (), fsys , "." )
1104
+ require .NoError (t , err )
1105
+
1106
+ require .Empty (t , results )
1107
+ })
1108
+
1109
+ t .Run ("not deprecated" , func (t * testing.T ) {
1110
+ check .Deprecated = false
1111
+ reg := rules .Register (check )
1112
+ defer rules .Deregister (reg )
1113
+
1114
+ results , err := scanner .ScanFS (context .TODO (), fsys , "." )
1115
+ require .NoError (t , err )
1116
+
1117
+ require .Len (t , results , 1 )
1118
+ })
1119
+ }
0 commit comments