Skip to content

Commit

Permalink
feat(Config Schema): Fix cloudFront event behavior schema (#8308)
Browse files Browse the repository at this point in the history
  • Loading branch information
jede committed Oct 1, 2020
1 parent ab5cdd1 commit 5b740f6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 5 deletions.
67 changes: 63 additions & 4 deletions lib/plugins/aws/package/compile/events/cloudFront/index.js
Expand Up @@ -85,13 +85,72 @@ class AwsCompileCloudFrontEvents {
properties: {
AllowedMethods: {
oneOf: [
{ enum: ['GET', 'HEAD'] },
{ enum: ['GET', 'HEAD', 'OPTIONS'] },
{ enum: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'PATCH', 'POST', 'DELETE'] },
{
type: 'array',
uniqueItems: true,
minItems: 2,
items: { enum: ['GET', 'HEAD'] },
},
{
type: 'array',
uniqueItems: true,
minItems: 3,
items: { enum: ['GET', 'HEAD', 'OPTIONS'] },
},
{
type: 'array',
uniqueItems: true,
minItems: 7,
items: { enum: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'PATCH', 'POST', 'DELETE'] },
},
],
},
CachedMethods: {
oneOf: [{ enum: ['GET', 'HEAD'] }, { enum: ['GET', 'HEAD', 'OPTIONS'] }],
oneOf: [
{
type: 'array',
uniqueItems: true,
minItems: 2,
items: { enum: ['GET', 'HEAD'] },
},
{
type: 'array',
uniqueItems: true,
minItems: 3,
items: { enum: ['GET', 'HEAD', 'OPTIONS'] },
},
],
},
ForwardedValues: {
type: 'object',
properties: {
Cookies: {
oneOf: [
{
type: 'object',
properties: {
Forward: { enum: ['all', 'none'] },
},
additionalProperties: false,
required: ['Forward'],
},
{
type: 'object',
properties: {
Forward: { const: 'whitelist' },
WhitelistedNames: { type: 'array', items: { type: 'string' } },
},
additionalProperties: false,
required: ['Forward', 'WhitelistedNames'],
},
],
},
Headers: { type: 'array', items: { type: 'string' } },
QueryString: { type: 'boolean' },
QueryStringCacheKeys: { type: 'array', items: { type: 'string' } },
},
additionalProperties: false,
required: ['QueryString'],
},
CachePolicyId: { type: 'string' },
Compress: { type: 'boolean' },
Expand Down
39 changes: 38 additions & 1 deletion lib/plugins/aws/package/compile/events/cloudFront/index.test.js
Expand Up @@ -1662,14 +1662,51 @@ 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,
Cookies: {
Forward: 'all',
},
},
AllowedMethods: ['GET', 'HEAD'],
CachedMethods: ['HEAD', 'GET', 'OPTIONS'],
},
},
},
],
},
},
}).then(({ cfTemplate }) => {
const behavior =
cfTemplate.Resources.CloudFrontDistribution.Properties.DistributionConfig
.DefaultCacheBehavior;
expect(behavior.AllowedMethods).to.deep.eq(['GET', 'HEAD']);
expect(behavior.CachedMethods).to.deep.eq(['HEAD', 'GET', 'OPTIONS']);
expect(behavior.ForwardedValues.QueryString).to.eq(true);
expect(behavior.ForwardedValues.Cookies.Forward).to.eq('all');
});
});

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

0 comments on commit 5b740f6

Please sign in to comment.