-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/aws: Add JSON validation to the aws_cloudwatch_event_rule resource. #8897
provider/aws: Add JSON validation to the aws_cloudwatch_event_rule resource. #8897
Conversation
This commit adds support for new helper function which is used to normalise and validate JSON string. Also adds new validation function to wrap around the aforementioned helper. Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Part of work which began in #8028. |
Tests are passing: (unit)
(acceptance)
|
} | ||
if _, err := normalizeJsonString(value); err != nil { | ||
errors = append(errors, fmt.Errorf("%q contains an invalid JSON: %s", k, err)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We send the minified (normalized) JSON to the API which is the one that is limited to 2048 characters, not the original JSON string with spaces, newlines etc.
At this point we would prevent the user from sending minified JSON to the API which can be below 2048 chars after stripping whitespaces etc. Also I'm not sure if there is any point in checking length of invalid JSON.
It may be worth covering this particular edge case by a test.
I'm happy to merge this once the mentioned edge case w/ normalization & length check is addressed - this otherwise looks good. |
@radeksimko ah, that is a very good point! I will fix this right away. |
This commit changes the logic of the function so that it would check length of the normalised JSON string over the given string, plus short-circuit early should JSON would not be valid. Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Unit test is passing:
|
@radeksimko I have updated the |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This commit adds support for new helper function which is used to
normalise and validate JSON string. Also adds new validation function
to wrap around the aforementioned helper.
Signed-off-by: Krzysztof Wilczynski krzysztof.wilczynski@linux.com