-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
2,660 additions
and
349 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
pkg/iac/adapters/cloudformation/aws/accessanalyzer/accessanalyzer_test.go
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,54 @@ | ||
package accessanalyzer | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/trivy/pkg/iac/adapters/cloudformation/testutil" | ||
"github.com/aquasecurity/trivy/pkg/iac/providers/aws/accessanalyzer" | ||
"github.com/aquasecurity/trivy/pkg/iac/types" | ||
) | ||
|
||
func TestAdapt(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
source string | ||
expected accessanalyzer.AccessAnalyzer | ||
}{ | ||
{ | ||
name: "complete", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
Analyzer: | ||
Type: 'AWS::AccessAnalyzer::Analyzer' | ||
Properties: | ||
AnalyzerName: MyAccountAnalyzer | ||
`, | ||
expected: accessanalyzer.AccessAnalyzer{ | ||
Analyzers: []accessanalyzer.Analyzer{ | ||
{ | ||
Name: types.StringTest("MyAccountAnalyzer"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "empty", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
Analyzer: | ||
Type: 'AWS::AccessAnalyzer::Analyzer' | ||
`, | ||
expected: accessanalyzer.AccessAnalyzer{ | ||
Analyzers: []accessanalyzer.Analyzer{ | ||
{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
testutil.AdaptAndCompare(t, tt.source, tt.expected, Adapt) | ||
}) | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
pkg/iac/adapters/cloudformation/aws/apigateway/apigateway_test.go
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,84 @@ | ||
package apigateway | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/trivy/pkg/iac/adapters/cloudformation/testutil" | ||
"github.com/aquasecurity/trivy/pkg/iac/providers/aws/apigateway" | ||
v2 "github.com/aquasecurity/trivy/pkg/iac/providers/aws/apigateway/v2" | ||
"github.com/aquasecurity/trivy/pkg/iac/types" | ||
) | ||
|
||
func TestAdapt(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
source string | ||
expected apigateway.APIGateway | ||
}{ | ||
{ | ||
name: "complete", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
MyApi: | ||
Type: 'AWS::ApiGatewayV2::Api' | ||
Properties: | ||
Name: MyApi | ||
ProtocolType: WEBSOCKET | ||
MyStage: | ||
Type: 'AWS::ApiGatewayV2::Stage' | ||
Properties: | ||
StageName: Prod | ||
ApiId: !Ref MyApi | ||
AccessLogSettings: | ||
DestinationArn: some-arn | ||
`, | ||
expected: apigateway.APIGateway{ | ||
V2: v2.APIGateway{ | ||
APIs: []v2.API{ | ||
{ | ||
Name: types.StringTest("MyApi"), | ||
ProtocolType: types.StringTest("WEBSOCKET"), | ||
Stages: []v2.Stage{ | ||
{ | ||
Name: types.StringTest("Prod"), | ||
AccessLogging: v2.AccessLogging{ | ||
CloudwatchLogGroupARN: types.StringTest("some-arn"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "empty", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
MyApi: | ||
Type: 'AWS::ApiGatewayV2::Api' | ||
MyStage: | ||
Type: 'AWS::ApiGatewayV2::Stage' | ||
MyStage2: | ||
Type: 'AWS::ApiGatewayV2::Stage' | ||
Properties: | ||
ApiId: !Ref MyApi | ||
`, | ||
expected: apigateway.APIGateway{ | ||
V2: v2.APIGateway{ | ||
APIs: []v2.API{ | ||
{ | ||
Stages: []v2.Stage{{}}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
testutil.AdaptAndCompare(t, tt.source, tt.expected, Adapt) | ||
}) | ||
} | ||
} |
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,61 @@ | ||
package athena | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/trivy/pkg/iac/adapters/cloudformation/testutil" | ||
"github.com/aquasecurity/trivy/pkg/iac/providers/aws/athena" | ||
"github.com/aquasecurity/trivy/pkg/iac/types" | ||
) | ||
|
||
func TestAdapt(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
source string | ||
expected athena.Athena | ||
}{ | ||
{ | ||
name: "complete", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
MyAthenaWorkGroup: | ||
Type: AWS::Athena::WorkGroup | ||
Properties: | ||
Name: MyCustomWorkGroup | ||
WorkGroupConfiguration: | ||
EnforceWorkGroupConfiguration: true | ||
ResultConfiguration: | ||
EncryptionOption: SSE_KMS | ||
`, | ||
expected: athena.Athena{ | ||
Workgroups: []athena.Workgroup{ | ||
{ | ||
Name: types.StringTest("MyCustomWorkGroup"), | ||
EnforceConfiguration: types.BoolTest(true), | ||
Encryption: athena.EncryptionConfiguration{ | ||
Type: types.StringTest("SSE_KMS"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "empty", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
MyAthenaWorkGroup: | ||
Type: AWS::Athena::WorkGroup | ||
`, | ||
expected: athena.Athena{ | ||
Workgroups: []athena.Workgroup{{}}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
testutil.AdaptAndCompare(t, tt.source, tt.expected, Adapt) | ||
}) | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
pkg/iac/adapters/cloudformation/aws/cloudfront/cloudfront_test.go
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,68 @@ | ||
package cloudfront | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aquasecurity/trivy/pkg/iac/adapters/cloudformation/testutil" | ||
"github.com/aquasecurity/trivy/pkg/iac/providers/aws/cloudfront" | ||
"github.com/aquasecurity/trivy/pkg/iac/types" | ||
) | ||
|
||
func TestAdapt(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
source string | ||
expected cloudfront.Cloudfront | ||
}{ | ||
{ | ||
name: "complete", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
cloudfrontdistribution: | ||
Type: AWS::CloudFront::Distribution | ||
Properties: | ||
DistributionConfig: | ||
WebACLId: "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" | ||
Logging: | ||
Bucket: "myawslogbucket.s3.amazonaws.com" | ||
ViewerCertificate: | ||
MinimumProtocolVersion: SSLv3 | ||
DefaultCacheBehavior: | ||
ViewerProtocolPolicy: "redirect-to-https" | ||
`, | ||
expected: cloudfront.Cloudfront{ | ||
Distributions: []cloudfront.Distribution{ | ||
{ | ||
WAFID: types.StringTest("a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"), | ||
Logging: cloudfront.Logging{ | ||
Bucket: types.StringTest("myawslogbucket.s3.amazonaws.com"), | ||
}, | ||
ViewerCertificate: cloudfront.ViewerCertificate{ | ||
MinimumProtocolVersion: types.StringTest("SSLv3"), | ||
}, | ||
DefaultCacheBehaviour: cloudfront.CacheBehaviour{ | ||
ViewerProtocolPolicy: types.StringTest("redirect-to-https"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "empty", | ||
source: `AWSTemplateFormatVersion: 2010-09-09 | ||
Resources: | ||
cloudfrontdistribution: | ||
Type: AWS::CloudFront::Distribution | ||
`, | ||
expected: cloudfront.Cloudfront{ | ||
Distributions: []cloudfront.Distribution{{}}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
testutil.AdaptAndCompare(t, tt.source, tt.expected, Adapt) | ||
}) | ||
} | ||
} |
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.