Skip to content

fix(Config Schema): validate resourcePolicy is array#8051

Merged
medikoo merged 1 commit into
serverless:masterfrom
glb:7795-check-apigateway-resource-policy-structure
Aug 17, 2020
Merged

fix(Config Schema): validate resourcePolicy is array#8051
medikoo merged 1 commit into
serverless:masterfrom
glb:7795-check-apigateway-resource-policy-structure

Conversation

@glb

@glb glb commented Aug 5, 2020

Copy link
Copy Markdown
Contributor

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.

Closes: #7795
Addresses: #8018

@glb

glb commented Aug 5, 2020

Copy link
Copy Markdown
Contributor Author

I don't love that the test takes so long to run but I don't know a faster way to do it; based on tests in #7335. If there is a better way to test this I'd be happy to make the change.

@codecov-commenter

codecov-commenter commented Aug 5, 2020

Copy link
Copy Markdown

Codecov Report

Merging #8051 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8051      +/-   ##
==========================================
+ Coverage   88.36%   88.37%   +0.01%     
==========================================
  Files         248      248              
  Lines        9446     9446              
==========================================
+ Hits         8347     8348       +1     
+ Misses       1099     1098       -1     
Impacted Files Coverage Δ
lib/plugins/aws/provider/awsProvider.js 92.77% <ø> (ø)
lib/classes/ConfigSchemaHandler/index.js 93.02% <0.00%> (+1.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4660acd...f8c1f28. Read the comment docs.

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glb Great thanks for that!

Still please see my comment about testing, I think value of such tests is neglible, while maintanance cost becomes significant

Comment thread lib/plugins/aws/provider/awsProvider.test.js Outdated
Comment thread lib/plugins/aws/provider/awsProvider.js Outdated
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.
@glb
glb force-pushed the 7795-check-apigateway-resource-policy-structure branch from 954a060 to f8c1f28 Compare August 11, 2020 19:45
@glb

glb commented Aug 11, 2020

Copy link
Copy Markdown
Contributor Author

Thanks @medikoo ! I have updated, rebased, and done manual testing with invalid and valid values for resourcePolicy:

serverless.yml
service: test

provider:
  name: aws
  resourcePolicy:
    - test

Output:

Serverless: Configuration error at 'provider.resourcePolicy[0]': should be object
serverless.yml
service: test

provider:
  name: aws
  resourcePolicy: {}

Output:

Serverless: Configuration error at 'provider.resourcePolicy': should be array
serverless.yml
service: test

provider:
  name: aws
  resourcePolicy: 
  - Effect: Allow
    Principal: "*"
    Action: "*"
    Resource: "*"

Output: no error (though arguably that's a terrible resource policy. 😆 )

@glb
glb requested a review from medikoo August 17, 2020 13:59

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @glb !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add checks for API Gateway resource policy structure

3 participants