Skip to content

fix(ecr): Repository.addToResourcePolicy returns incorrect result#21137

Merged
mergify[bot] merged 5 commits intoaws:mainfrom
watany-dev:fix-ecr-result
Jul 22, 2022
Merged

fix(ecr): Repository.addToResourcePolicy returns incorrect result#21137
mergify[bot] merged 5 commits intoaws:mainfrom
watany-dev:fix-ecr-result

Conversation

@watany-dev
Copy link
Copy Markdown
Contributor

@watany-dev watany-dev commented Jul 14, 2022

fixes #12412

To fix Repository.addToResourcePolicy returning incorrect result (false-> true)


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license


@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Jul 14, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team July 14, 2022 11:21
@github-actions github-actions bot added p2 bug This issue is a bug. effort/medium Medium work item – several days of effort labels Jul 14, 2022
@watany-dev
Copy link
Copy Markdown
Contributor Author

hmm… lets add test

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. We'll need tests for this change before we can provide a meaningful review. Please also ensure the title and body of the PR align to the guidelines in the Pull Request section of our contributing guide.

@watany-dev watany-dev changed the title fix(ecr) Repository.addToResourcePolicy returns incorrect result #12412 fix(ecr): Repository.addToResourcePolicy returns incorrect result Jul 15, 2022
@watany-dev
Copy link
Copy Markdown
Contributor Author

Thank you for your comment. As a starting point, I reviewed the title and text of the PR. I'm going to add a test

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 17, 2022 15:17

Pull request has been modified.

@TheRealAmazonKendra
Copy link
Copy Markdown
Contributor

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 18, 2022

update

✅ Branch has been successfully updated

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

I'd like to see a little bit more robust testing. Please see my comment below and let me know if you have any questions. Once you've made the change and/or if you have questions, please assign this review to me so I can follow up quickly.

})).toThrow(/must follow the specified pattern/);
});

test('return value addToResourcePolicy', () => {
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.

Thanks for adding this test. Let's also add a test that looks at the actual output of calling this on a policy statement with concrete values. One test where the policy document is already defined and one where it is not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok. Update to a test that checks all return values, not just singular

@TheRealAmazonKendra
Copy link
Copy Markdown
Contributor

Did this build locally? I'm seeing that the build hangs in the same spot each time I run it in CodeBuild.

@TheRealAmazonKendra
Copy link
Copy Markdown
Contributor

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 18, 2022

update

✅ Branch has been successfully updated

@TheRealAmazonKendra
Copy link
Copy Markdown
Contributor

OK, so I pulled this down locally to run and see what the result was and I'm getting this

(node:60431) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    --- property 'grantPrincipal' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (internal/child_process/serialization.js:127:20)
    at process.target._send (internal/child_process.js:836:17)
    at process.target.send (internal/child_process.js:734:19)
    at reportSuccess (/Volumes/workplace/aws-cdk/node_modules/jest-worker/build/workers/processChild.js:59:11)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:60431) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:60431) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 19, 2022 00:29

Pull request has been modified.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Looks good, just one more thing: Can you add one more test where there is already a policy document and test against the full output of that as well?

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 20, 2022 09:19

Pull request has been modified.

@watany-dev
Copy link
Copy Markdown
Contributor Author

Looks good, just one more thing: Can you add one more test where there is already a policy document and test against the full output of that as well?

@TheRealAmazonKendra
I tried to fix the test. I hope there is a corresponding image.

Copy link
Copy Markdown
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Looks good, just one more thing: Can you add one more test where there is already a policy document and test against the full output of that as well?

@TheRealAmazonKendra I tried to fix the test. I hope there is a corresponding image.

That test is great. I'd like a second test, though, where there is an already existing policy statement within the policy document and that the entire policy document is as expected after performing the mutation on it with const artifact = new ecr.Repository(stack, 'Repo1').addToResourcePolicy(policyStmt); Your test shows that it adds the statement to an empty policy document properly, but let's make sure it also adds it correctly to one with content already in it.

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review July 22, 2022 10:43

Pull request has been modified.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 22, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 12d28d8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 5435215 into aws:main Jul 22, 2022
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 22, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

comcalvi pushed a commit to comcalvi/aws-cdk that referenced this pull request Jul 25, 2022
…s#21137)

fixes aws#12412

To fix Repository.addToResourcePolicy returning incorrect result (false-> true)

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*

----
@watany-dev watany-dev deleted the fix-ecr-result branch July 26, 2022 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-ecr): Repository.addToResourcePolicy returns incorrect result

3 participants