Skip to content

Commit

Permalink
fix(Config Schema): validate resourcePolicy is array
Browse files Browse the repository at this point in the history
In the AWS provider, the `resourcePolicy` must be an array. If you paste
a resource policy from the console, your stack will fail to create.
  • Loading branch information
glb committed Aug 5, 2020
1 parent 0b91a3b commit e63a48c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/plugins/aws/provider/awsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ class AwsProvider {

// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8016
serverless.configSchemaHandler.defineProvider('aws', {
provider: {
properties: {
resourcePolicy: { type: 'array' },
},
},
function: {
// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8017
properties: { handler: { type: 'string' } },
Expand Down
52 changes: 52 additions & 0 deletions lib/plugins/aws/provider/awsProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const Serverless = require('../../../Serverless');
const { replaceEnv } = require('../../../../tests/utils/misc');
const { getTmpFilePath } = require('../../../../tests/utils/fs');

const runServerless = require('../../../../tests/utils/run-serverless');

chai.use(require('chai-as-promised'));
chai.use(require('sinon-chai'));

Expand Down Expand Up @@ -1529,4 +1531,54 @@ describe('AwsProvider', () => {
return expect(awsProvider.options['aws-s3-accelerate']).to.be.undefined;
});
});

describe('schema validation', () => {
const cases = [
{
name: 'should reject if resourcePolicy is not an array',
config: {
service: 'test',
provider: {
name: 'aws',
stage: 'test',
resourcePolicy: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Principal: {},
Action: 'test:action',
Resource: 'arn:...',
},
],
},
},
},
expected: "'provider.resourcePolicy': should be array",
},
];

for (const someCase of cases) {
it(someCase.name, () => {
return runServerless({
config: someCase.config,
cliArgs: ['info'],
awsRequestStubMap: {
CloudFormation: {
describeStacks: {
Stacks: [
{
Outputs: [],
},
],
},
listStackResources: {},
},
},
}).then(({ stdoutData }) => {
expect(stdoutData).to.include(someCase.expected);
});
});
}
});
});

0 comments on commit e63a48c

Please sign in to comment.