forked from aquasecurity/trivy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudfront_test.go
More file actions
144 lines (136 loc) · 3.76 KB
/
Copy pathcloudfront_test.go
File metadata and controls
144 lines (136 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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{{}},
},
},
{
name: "v2 logging configured",
source: `AWSTemplateFormatVersion: 2010-09-09
Resources:
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
ViewerProtocolPolicy: "redirect-to-https"
CloudFrontAccessLogsDeliverySource:
Type: AWS::Logs::DeliverySource
Properties:
LogType: ACCESS_LOGS
Name: cloudfront-log-delivery-source
ResourceArn: !Sub
- arn:aws:cloudfront::${AWS::AccountId}:distribution/${D}
- D: !GetAtt CloudFrontDistribution.Id
CloudFrontAccessLogsDelivery:
Type: AWS::Logs::Delivery
Properties:
DeliverySourceName: cloudfront-log-delivery-source
`,
expected: cloudfront.Cloudfront{
Distributions: []cloudfront.Distribution{
{
Logging: cloudfront.Logging{
V2: cloudfront.LoggingV2{
Enabled: types.BoolTest(true),
},
},
DefaultCacheBehaviour: cloudfront.CacheBehaviour{
ViewerProtocolPolicy: types.StringTest("redirect-to-https"),
},
},
},
},
},
{
name: "v2 logging source exists but no delivery",
source: `AWSTemplateFormatVersion: 2010-09-09
Resources:
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
DefaultCacheBehavior:
ViewerProtocolPolicy: "redirect-to-https"
CloudFrontAccessLogsDeliverySource:
Type: AWS::Logs::DeliverySource
Properties:
LogType: ACCESS_LOGS
Name: cloudfront-log-delivery-source
ResourceArn: !Sub
- arn:aws:cloudfront::${AWS::AccountId}:distribution/${D}
- D: !GetAtt CloudFrontDistribution.Id
`,
expected: cloudfront.Cloudfront{
Distributions: []cloudfront.Distribution{
{
Logging: cloudfront.Logging{
V2: cloudfront.LoggingV2{
Enabled: types.BoolTest(false),
},
},
DefaultCacheBehaviour: cloudfront.CacheBehaviour{
ViewerProtocolPolicy: types.StringTest("redirect-to-https"),
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
testutil.AdaptAndCompare(t, tt.source, tt.expected, Adapt)
})
}
}