Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix schema validation of CloudFront distribution config #8308

Merged
merged 3 commits into from Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 36 additions & 4 deletions lib/plugins/aws/package/compile/events/cloudFront/index.js
Expand Up @@ -85,13 +85,45 @@ class AwsCompileCloudFrontEvents {
properties: {
AllowedMethods: {
oneOf: [
{ enum: ['GET', 'HEAD'] },
{ enum: ['GET', 'HEAD', 'OPTIONS'] },
{ enum: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'PATCH', 'POST', 'DELETE'] },
{
uniqueItems: true,
minItems: 2,
items: { enum: ['GET', 'HEAD'] },
},
{
uniqueItems: true,
minItems: 3,
items: { enum: ['GET', 'HEAD', 'OPTIONS'] },
},
{
uniqueItems: true,
minItems: 7,
items: { enum: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'PATCH', 'POST', 'DELETE'] },
},
],
},
CachedMethods: {
oneOf: [{ enum: ['GET', 'HEAD'] }, { enum: ['GET', 'HEAD', 'OPTIONS'] }],
oneOf: [
{
uniqueItems: true,
minItems: 2,
items: { enum: ['GET', 'HEAD'] },
},
{
uniqueItems: true,
minItems: 3,
items: { enum: ['GET', 'HEAD', 'OPTIONS'] },
},
],
jede marked this conversation as resolved.
Show resolved Hide resolved
},
ForwardedValues: {
jede marked this conversation as resolved.
Show resolved Hide resolved
Cookies: {
Forward: { type: 'string' },
WhitelistedNames: { items: { type: 'string' } },
},
Headers: { items: { type: 'string' } },
QueryString: { type: 'boolean' },
QueryStringCacheKeys: { items: { type: 'string' } },
jede marked this conversation as resolved.
Show resolved Hide resolved
},
CachePolicyId: { type: 'string' },
Compress: { type: 'boolean' },
Expand Down
33 changes: 32 additions & 1 deletion lib/plugins/aws/package/compile/events/cloudFront/index.test.js
Expand Up @@ -1662,14 +1662,45 @@ describe('AwsCompileCloudFrontEvents', () => {
});
});

describe('#AwsCompileCloudFrontEvents() Remove VPC & Env Vars', () => {
describe('#AwsCompileCloudFrontEvents() package', () => {
const fixtureName = 'functionCloudFront';
const edgeFunctionName = 'foo';
const otherFunctionName = 'bar';
function extendAndPackage(extension) {
return runServerless({ fixture: fixtureName, configExt: extension, cliArgs: ['package'] });
}

it('Should validate configuration schema', () => {
return extendAndPackage({
functions: {
[edgeFunctionName]: {
handler: 'myLambdaAtEdge.handler',
events: [
{
cloudFront: {
origin: 's3://bucketname.s3.amazonaws.com/files',
eventType: 'viewer-response',
behavior: {
ViewerProtocolPolicy: 'https-only',
ForwardedValues: {
QueryString: true,
},
AllowedMethods: ['GET', 'HEAD'],
CachedMethods: ['GET', 'HEAD', 'OPTIONS'],
},
},
},
],
},
},
}).then(({ cfTemplate }) => {
const behavior =
cfTemplate.Resources.CloudFrontDistribution.Properties.DistributionConfig
.DefaultCacheBehavior;
expect(behavior).to.contain.keys('AllowedMethods', 'CachedMethods', 'ForwardedValues');
});
});

it('Should ignore Environment variables if provided in function properties', () => {
return extendAndPackage({
functions: { [edgeFunctionName]: { environment: { HELLO: 'WORLD' } } },
Expand Down