fix: state machine input escaping#2253
Closed
hoffa wants to merge 11 commits into
Closed
Conversation
4 tasks
Contributor
Author
|
A number of changes to physical IDs on Python 2.7 (see AppVeyor runs), e.g. @@ -62,9 +62,9 @@
},
"Type": "AWS::ApiGateway::RestApi"
},
- "MyApiDeployment05bc9f394c": {
- "Properties": {
- "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e",
+ "MyApiDeployment6bf6e42383": {
+ "Properties": {
+ "Description": "RestApi deployment id: 6bf6e423834ff79351f695c325893ac1ff6830dc",
"RestApiId": {
"Ref": "MyApi"
},
@@ -75,7 +75,7 @@
"MyApiProdStage": {
"Properties": {
"DeploymentId": {
- "Ref": "MyApiDeployment05bc9f394c"
+ "Ref": "MyApiDeployment6bf6e42383"
},
"RestApiId": {
"Ref": "MyApi"Will try against the |
Contributor
Author
|
Using Python 2.7: git clone --branch py27hash-20210918 [email protected]:aws/serverless-application-model.git sam
cd sam
curl -L https://github.com/aws/serverless-application-model/pull/2253.diff | git apply --exclude tests/translator/test_translator.py
make init
pytest -v tests |
hoffa
marked this pull request as ready for review
January 1, 2022 21:01
hoffa
marked this pull request as draft
January 1, 2022 21:01
Contributor
Author
|
For posterity, using this to show a more useful diff in failed tests: diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py
index 577ad26..c6debf5 100644
--- a/tests/translator/test_translator.py
+++ b/tests/translator/test_translator.py
@@ -174,9 +174,13 @@ class AbstractTestTranslator(TestCase):
output_fragment = transform(manifest, parameter_values, mock_policy_loader)
- print(json.dumps(output_fragment, indent=2))
-
- self.assertEqual(deep_sort_lists(output_fragment), deep_sort_lists(expected))
+ def diff(before, after):
+ import difflib
+ return "\n".join(difflib.unified_diff(before.splitlines(), after.splitlines()))
+ actual = json.dumps(deep_sort_lists(output_fragment), sort_keys=True, indent=2)
+ expected = json.dumps(deep_sort_lists(expected), sort_keys=True, indent=2)
+ print(diff(expected, actual))
+ self.assertEqual(actual, expected)
def _update_logical_id_hash(self, resources):
""" |
Codecov Report
@@ Coverage Diff @@
## develop #2253 +/- ##
===========================================
+ Coverage 93.58% 94.39% +0.81%
===========================================
Files 90 97 +7
Lines 6124 7084 +960
Branches 1260 1433 +173
===========================================
+ Hits 5731 6687 +956
+ Misses 183 181 -2
- Partials 210 216 +6
Continue to review full report at Codecov.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available
#1895
Description of changes
Unescapes singles quotes in state machine input escaped by
escapeJavaScript(which isn't valid JSON).The final mapping template isn't JSON by design, so can't use
json.dumps(). For example:{"input": "$util.escapeJavaScript($input.json('$')).replaceAll("\\'","'")", "stateMachineArn": "arn:aws:states:us-east-1:792766875239:stateMachine:Post-n7ZKNljUJsZZ"}Description of how you validated changes
pytest integration --no-cov -k test_state_machine_with_api_single_quotes_input -s -vvv make testChecklist
make prpassesExamples?
Please reach out in the comments, if you want to add an example. Examples will be
added to
sam initthrough https://github.com/awslabs/aws-sam-cli-app-templates/By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.