github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/internal/adapters/cloudformation/aws/config/adapt_test.go (about) 1 package config 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/aquasecurity/defsec/pkg/providers/aws/config" 8 "github.com/aquasecurity/defsec/pkg/types" 9 "github.com/stretchr/testify/require" 10 11 "github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/parser" 12 "github.com/aquasecurity/trivy-iac/test/testutil" 13 ) 14 15 func TestAdapt(t *testing.T) { 16 tests := []struct { 17 name string 18 source string 19 expected config.Config 20 }{ 21 { 22 name: "Config aggregator with AccountAggregationSources", 23 source: `AWSTemplateFormatVersion: "2010-09-09" 24 Resources: 25 ConfigurationAggregator: 26 Type: AWS::Config::ConfigurationAggregator 27 Properties: 28 AccountAggregationSources: 29 - AllAwsRegions: "true" 30 `, 31 expected: config.Config{ 32 ConfigurationAggregrator: config.ConfigurationAggregrator{ 33 Metadata: types.NewTestMetadata(), 34 SourceAllRegions: types.Bool(true, types.NewTestMetadata()), 35 }, 36 }, 37 }, 38 { 39 name: "Config aggregator with OrganizationAggregationSource", 40 source: `AWSTemplateFormatVersion: "2010-09-09" 41 Resources: 42 ConfigurationAggregator: 43 Type: AWS::Config::ConfigurationAggregator 44 Properties: 45 OrganizationAggregationSource: 46 AllAwsRegions: "true" 47 `, 48 expected: config.Config{ 49 ConfigurationAggregrator: config.ConfigurationAggregrator{ 50 Metadata: types.NewTestMetadata(), 51 SourceAllRegions: types.Bool(true, types.NewTestMetadata()), 52 }, 53 }, 54 }, 55 } 56 57 for _, tt := range tests { 58 t.Run(tt.name, func(t *testing.T) { 59 fs := testutil.CreateFS(t, map[string]string{ 60 "template.yaml": tt.source, 61 }) 62 63 p := parser.New() 64 fctx, err := p.ParseFile(context.TODO(), fs, "template.yaml") 65 require.NoError(t, err) 66 67 testutil.AssertDefsecEqual(t, tt.expected, Adapt(*fctx)) 68 }) 69 } 70 71 }