-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cloudformation): fix some resources
- Loading branch information
Showing
10 changed files
with
406 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/aquasecurity/defsec/pkg/providers/aws/config" | ||
"github.com/aquasecurity/defsec/pkg/types" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/parser" | ||
"github.com/aquasecurity/trivy-iac/test/testutil" | ||
) | ||
|
||
func TestAdapt(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
source string | ||
expected config.Config | ||
}{ | ||
{ | ||
name: "Config aggregator with AccountAggregationSources", | ||
source: `AWSTemplateFormatVersion: "2010-09-09" | ||
Resources: | ||
ConfigurationAggregator: | ||
Type: AWS::Config::ConfigurationAggregator | ||
Properties: | ||
AccountAggregationSources: | ||
- AllAwsRegions: "true" | ||
`, | ||
expected: config.Config{ | ||
ConfigurationAggregrator: config.ConfigurationAggregrator{ | ||
Metadata: types.NewTestMetadata(), | ||
SourceAllRegions: types.Bool(true, types.NewTestMetadata()), | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Config aggregator with OrganizationAggregationSource", | ||
source: `AWSTemplateFormatVersion: "2010-09-09" | ||
Resources: | ||
ConfigurationAggregator: | ||
Type: AWS::Config::ConfigurationAggregator | ||
Properties: | ||
OrganizationAggregationSource: | ||
AllAwsRegions: "true" | ||
`, | ||
expected: config.Config{ | ||
ConfigurationAggregrator: config.ConfigurationAggregrator{ | ||
Metadata: types.NewTestMetadata(), | ||
SourceAllRegions: types.Bool(true, types.NewTestMetadata()), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
fs := testutil.CreateFS(t, map[string]string{ | ||
"template.yaml": tt.source, | ||
}) | ||
|
||
p := parser.New() | ||
fctx, err := p.ParseFile(context.TODO(), fs, "template.yaml") | ||
require.NoError(t, err) | ||
|
||
testutil.AssertDefsecEqual(t, tt.expected, Adapt(*fctx)) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package ec2 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/aquasecurity/defsec/pkg/providers/aws/ec2" | ||
"github.com/aquasecurity/defsec/pkg/types" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/parser" | ||
"github.com/aquasecurity/trivy-iac/test/testutil" | ||
) | ||
|
||
func TestAdapt(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
source string | ||
expected ec2.EC2 | ||
}{ | ||
{ | ||
name: "EC2 instance", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
MyEC2Instance: | ||
Type: AWS::EC2::Instance | ||
Properties: | ||
ImageId: "ami-79fd7eee" | ||
KeyName: "testkey" | ||
BlockDeviceMappings: | ||
- DeviceName: "/dev/sdm" | ||
Ebs: | ||
VolumeType: "io1" | ||
Iops: "200" | ||
DeleteOnTermination: "false" | ||
VolumeSize: "20" | ||
Encrypted: "true"`, | ||
expected: ec2.EC2{ | ||
Instances: []ec2.Instance{ | ||
{ | ||
Metadata: types.NewTestMetadata(), | ||
MetadataOptions: ec2.MetadataOptions{ | ||
HttpEndpoint: types.StringDefault("enabled", types.NewTestMetadata()), | ||
HttpTokens: types.StringDefault("optional", types.NewTestMetadata()), | ||
}, | ||
RootBlockDevice: &ec2.BlockDevice{ | ||
Metadata: types.NewTestMetadata(), | ||
Encrypted: types.Bool(true, types.NewTestMetadata()), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
fs := testutil.CreateFS(t, map[string]string{ | ||
"template.yaml": tt.source, | ||
}) | ||
p := parser.New() | ||
fctx, err := p.ParseFile(context.TODO(), fs, "template.yaml") | ||
require.NoError(t, err) | ||
testutil.AssertDefsecEqual(t, tt.expected, Adapt(*fctx)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package elb | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/aquasecurity/defsec/pkg/providers/aws/elb" | ||
"github.com/aquasecurity/defsec/pkg/types" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/parser" | ||
"github.com/aquasecurity/trivy-iac/test/testutil" | ||
) | ||
|
||
func TestAdapt(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
source string | ||
expected elb.ELB | ||
}{ | ||
{ | ||
name: "LoadBalancer", | ||
source: `AWSTemplateFormatVersion: "2010-09-09" | ||
Resources: | ||
LoadBalancer: | ||
Type: AWS::ElasticLoadBalancingV2::LoadBalancer | ||
DependsOn: | ||
- ALBLogsBucketPermission | ||
Properties: | ||
Name: "k8s-dev" | ||
IpAddressType: ipv4 | ||
LoadBalancerAttributes: | ||
- Key: routing.http2.enabled | ||
Value: "true" | ||
- Key: deletion_protection.enabled | ||
Value: "true" | ||
- Key: routing.http.drop_invalid_header_fields.enabled | ||
Value: "true" | ||
- Key: access_logs.s3.enabled | ||
Value: "true" | ||
Tags: | ||
- Key: ingress.k8s.aws/resource | ||
Value: LoadBalancer | ||
- Key: elbv2.k8s.aws/cluster | ||
Value: "biomage-dev" | ||
Type: application | ||
`, | ||
expected: elb.ELB{ | ||
LoadBalancers: []elb.LoadBalancer{ | ||
{ | ||
Metadata: types.NewTestMetadata(), | ||
Type: types.String("application", types.NewTestMetadata()), | ||
DropInvalidHeaderFields: types.Bool(true, types.NewTestMetadata()), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
fs := testutil.CreateFS(t, map[string]string{ | ||
"template.yaml": tt.source, | ||
}) | ||
|
||
p := parser.New() | ||
fctx, err := p.ParseFile(context.TODO(), fs, "template.yaml") | ||
require.NoError(t, err) | ||
|
||
testutil.AssertDefsecEqual(t, tt.expected, Adapt(*fctx)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.