Skip to content

Commit eb495bb

Browse files
update bucket policy with cloudfront access
1 parent 6ba193a commit eb495bb

File tree

7 files changed

+222
-166
lines changed

7 files changed

+222
-166
lines changed

__mocks__/aws-sdk.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ const mockCreateCloudFrontOriginAccessIdentityPromise = promisifyMock(
2424
mockCreateCloudFrontOriginAccessIdentity
2525
)
2626

27+
const mockPutBucketPolicy = jest.fn()
28+
const mockPutBucketPolicyPromise = promisifyMock(mockPutBucketPolicy)
29+
2730
module.exports = {
2831
mockCreateDistribution,
2932
mockUpdateDistribution,
3033
mockGetDistributionConfig,
3134
mockDeleteDistribution,
3235
mockCreateCloudFrontOriginAccessIdentity,
36+
mockPutBucketPolicy,
37+
38+
mockPutBucketPolicyPromise,
3339
mockCreateDistributionPromise,
3440
mockUpdateDistributionPromise,
3541
mockGetDistributionConfigPromise,
@@ -42,5 +48,9 @@ module.exports = {
4248
getDistributionConfig: mockGetDistributionConfig,
4349
deleteDistribution: mockDeleteDistribution,
4450
createCloudFrontOriginAccessIdentity: mockCreateCloudFrontOriginAccessIdentity
51+
})),
52+
53+
S3: jest.fn(() => ({
54+
putBucketPolicy: mockPutBucketPolicy
4555
}))
4656
}

__tests__/__snapshots__/s3-origin.test.js.snap

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Input origin as an S3 bucket url creates distribution configured to serve private S3 content 1`] = `
3+
exports[`S3 origins When origin is an S3 URL only accessible via CloudFront creates distribution 1`] = `
44
Object {
55
"DistributionConfig": Object {
66
"Aliases": Object {
@@ -80,7 +80,7 @@ Object {
8080
}
8181
`;
8282

83-
exports[`Input origin as an S3 bucket url creates distribution with S3 origin 1`] = `
83+
exports[`S3 origins When origin is an S3 URL only accessible via CloudFront updates distribution 1`] = `
8484
Object {
8585
"DistributionConfig": Object {
8686
"Aliases": Object {
@@ -149,7 +149,7 @@ Object {
149149
"Id": "mybucket",
150150
"OriginPath": "",
151151
"S3OriginConfig": Object {
152-
"OriginAccessIdentity": "",
152+
"OriginAccessIdentity": "origin-access-identity/cloudfront/access-identity-xyz",
153153
},
154154
},
155155
],
@@ -160,9 +160,15 @@ Object {
160160
}
161161
`;
162162

163-
exports[`Input origin as an S3 bucket url updates distribution 1`] = `
163+
exports[`S3 origins When origin is an S3 bucket URL creates distribution 1`] = `
164164
Object {
165165
"DistributionConfig": Object {
166+
"Aliases": Object {
167+
"Items": Array [],
168+
"Quantity": 0,
169+
},
170+
"CallerReference": "1566599541192",
171+
"Comment": "",
166172
"DefaultCacheBehavior": Object {
167173
"AllowedMethods": Object {
168174
"CachedMethods": Object {
@@ -202,7 +208,7 @@ Object {
202208
"MaxTTL": 31536000,
203209
"MinTTL": 0,
204210
"SmoothStreaming": false,
205-
"TargetOriginId": "anotherbucket",
211+
"TargetOriginId": "mybucket",
206212
"TrustedSigners": Object {
207213
"Enabled": false,
208214
"Items": Array [],
@@ -211,15 +217,16 @@ Object {
211217
"ViewerProtocolPolicy": "redirect-to-https",
212218
},
213219
"Enabled": true,
220+
"HttpVersion": "http2",
214221
"Origins": Object {
215222
"Items": Array [
216223
Object {
217224
"CustomHeaders": Object {
218225
"Items": Array [],
219226
"Quantity": 0,
220227
},
221-
"DomainName": "anotherbucket.s3.amazonaws.com",
222-
"Id": "anotherbucket",
228+
"DomainName": "mybucket.s3.amazonaws.com",
229+
"Id": "mybucket",
223230
"OriginPath": "",
224231
"S3OriginConfig": Object {
225232
"OriginAccessIdentity": "",
@@ -228,21 +235,14 @@ Object {
228235
],
229236
"Quantity": 1,
230237
},
238+
"PriceClass": "PriceClass_All",
231239
},
232-
"Id": "distributionwithS3origin",
233-
"IfMatch": "etag",
234240
}
235241
`;
236242

237-
exports[`Input origin as an S3 bucket url updates distribution configured to serve private S3 content 1`] = `
243+
exports[`S3 origins When origin is an S3 bucket URL updates distribution 1`] = `
238244
Object {
239245
"DistributionConfig": Object {
240-
"Aliases": Object {
241-
"Items": Array [],
242-
"Quantity": 0,
243-
},
244-
"CallerReference": "1566599541192",
245-
"Comment": "",
246246
"DefaultCacheBehavior": Object {
247247
"AllowedMethods": Object {
248248
"CachedMethods": Object {
@@ -282,7 +282,7 @@ Object {
282282
"MaxTTL": 31536000,
283283
"MinTTL": 0,
284284
"SmoothStreaming": false,
285-
"TargetOriginId": "mybucket",
285+
"TargetOriginId": "anotherbucket",
286286
"TrustedSigners": Object {
287287
"Enabled": false,
288288
"Items": Array [],
@@ -291,25 +291,25 @@ Object {
291291
"ViewerProtocolPolicy": "redirect-to-https",
292292
},
293293
"Enabled": true,
294-
"HttpVersion": "http2",
295294
"Origins": Object {
296295
"Items": Array [
297296
Object {
298297
"CustomHeaders": Object {
299298
"Items": Array [],
300299
"Quantity": 0,
301300
},
302-
"DomainName": "mybucket.s3.amazonaws.com",
303-
"Id": "mybucket",
301+
"DomainName": "anotherbucket.s3.amazonaws.com",
302+
"Id": "anotherbucket",
304303
"OriginPath": "",
305304
"S3OriginConfig": Object {
306-
"OriginAccessIdentity": "origin-access-identity/cloudfront/access-identity-xyz",
305+
"OriginAccessIdentity": "",
307306
},
308307
},
309308
],
310309
"Quantity": 1,
311310
},
312-
"PriceClass": "PriceClass_All",
313311
},
312+
"Id": "distributionwithS3origin",
313+
"IfMatch": "etag",
314314
}
315315
`;

0 commit comments

Comments
 (0)