-
Notifications
You must be signed in to change notification settings - Fork 916
Fix for Signing Error when ampersand character included in HttpQuery when using DefaultAwsCrtV4aSigner #4800
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "bugfix", | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"description": "Fix for Signing Error when ampersand character included in HttpQuery when using DefaultAwsCrtV4aSigner." | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ | |
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import software.amazon.awssdk.crt.http.HttpHeader; | ||
import software.amazon.awssdk.crt.http.HttpRequest; | ||
import software.amazon.awssdk.crt.http.HttpRequestBodyStream; | ||
|
@@ -71,6 +74,49 @@ public void request_withHeaders_isConvertedToCrtFormat() { | |
assertHttpRequestSame(request, crtHttpRequest); | ||
} | ||
|
||
public static List<Arguments> specialCharactersEncoding() { | ||
return Arrays.asList( | ||
Arguments.of("hello world", "hello%20world"), | ||
Arguments.of("apple & orange", "apple%20%26%20orange"), | ||
Arguments.of("/path/to/resource", "%2Fpath%2Fto%2Fresource"), | ||
Arguments.of("search?q=term", "search%3Fq%3Dterm"), | ||
Arguments.of("key=value", "key%3Dvalue"), | ||
Arguments.of("section#1", "section%231"), | ||
Arguments.of("one+two", "one%2Btwo"), | ||
Arguments.of("[email protected]", "user%40domain.com"), | ||
Arguments.of("protocol:8080", "protocol%3A8080"), | ||
Arguments.of("item1;item2", "item1%3Bitem2"), | ||
Arguments.of("apple,orange", "apple%2Corange"), | ||
Arguments.of("quoted text", "quoted%20text"), | ||
Arguments.of("don't", "don%27t"), | ||
Arguments.of("20% discount", "20%25%20discount"), | ||
Arguments.of("important!", "important%21"), | ||
Arguments.of("(example)", "%28example%29"), | ||
Arguments.of("items[1]", "items%5B1%5D"), | ||
Arguments.of("{key: 'value'}", "%7Bkey%3A%20%27value%27%7D"), | ||
Arguments.of("first line\nsecond line", "first%20line%0Asecond%20line"), | ||
Arguments.of("before\rafter", "before%0Dafter"), | ||
Arguments.of("left\tcenter\tright", "left%09center%09right") | ||
); | ||
} | ||
|
||
@ParameterizedTest(name = "{index} {0}") | ||
@MethodSource("specialCharactersEncoding") | ||
public void request_withSpecialCharactersQueryParams_isConvertedToCrtFormat(String rawParameters, String encodedParameters) { | ||
SdkHttpFullRequest request = SdkHttpFullRequest.builder() | ||
.method(SdkHttpMethod.GET) | ||
.putRawQueryParameter("headerOne", rawParameters) | ||
.putHeader("Host", "demo.us-east-1.amazonaws.com") | ||
.encodedPath("/path") | ||
.uri(URI.create("https://demo.us-east-1.amazonaws.com")) | ||
.build(); | ||
HttpRequest crtHttpRequest = converter.requestToCrt(request); | ||
assertThat(crtHttpRequest.getMethod()).isEqualTo("GET"); | ||
assertThat(crtHttpRequest.getEncodedPath()).isEqualTo(String.format("/path?headerOne=%s", encodedParameters)); | ||
assertHttpRequestSame(request, crtHttpRequest); | ||
} | ||
|
||
|
||
@Test | ||
public void request_withQueryParams_isConvertedToCrtFormat() { | ||
SdkHttpFullRequest request = SdkHttpFullRequest.builder() | ||
|
@@ -87,6 +133,55 @@ public void request_withQueryParams_isConvertedToCrtFormat() { | |
assertHttpRequestSame(request, crtHttpRequest); | ||
} | ||
|
||
|
||
@Test | ||
public void request_withQueryParams_WithAmpersandAndEqualsInKeyAndValue_isConvertedToCrtFormat() { | ||
SdkHttpFullRequest request = SdkHttpFullRequest.builder() | ||
.method(SdkHttpMethod.GET) | ||
.putRawQueryParameter("ampersand&", "one & two") | ||
.putRawQueryParameter("equals=", "three = three") | ||
.putHeader("Host", "demo.us-east-1.amazonaws.com") | ||
.encodedPath("/path") | ||
.uri(URI.create("https://demo.us-east-1.amazonaws.com")) | ||
.build(); | ||
HttpRequest crtHttpRequest = converter.requestToCrt(request); | ||
assertThat(crtHttpRequest.getMethod()).isEqualTo("GET"); | ||
assertThat(crtHttpRequest.getEncodedPath()).isEqualTo("/path?ampersand%26=one%20%26%20two&equals%3D=three%20%3D%20three"); | ||
assertHttpRequestSame(request, crtHttpRequest); | ||
} | ||
|
||
@Test | ||
public void request_withQueryParams_AmpersandAndEqualsInValue_isConvertedToCrtFormat() { | ||
SdkHttpFullRequest request = SdkHttpFullRequest.builder() | ||
.method(SdkHttpMethod.GET) | ||
.putRawQueryParameter("ampersand", "one & two") | ||
.putRawQueryParameter("equals", "three = three") | ||
.putHeader("Host", "demo.us-east-1.amazonaws.com") | ||
.encodedPath("/path") | ||
.uri(URI.create("https://demo.us-east-1.amazonaws.com")) | ||
.build(); | ||
HttpRequest crtHttpRequest = converter.requestToCrt(request); | ||
assertThat(crtHttpRequest.getMethod()).isEqualTo("GET"); | ||
assertThat(crtHttpRequest.getEncodedPath()).isEqualTo("/path?ampersand=one%20%26%20two&equals=three%20%3D%20three"); | ||
assertHttpRequestSame(request, crtHttpRequest); | ||
} | ||
|
||
@Test | ||
public void request_withQueryParams_EmptyApersandAndEqualsInValue_isConvertedToCrtFormat() { | ||
SdkHttpFullRequest request = SdkHttpFullRequest.builder() | ||
.method(SdkHttpMethod.GET) | ||
.putRawQueryParameter("&ersand&", "") | ||
.putRawQueryParameter("=equals=", "") | ||
.putHeader("Host", "demo.us-east-1.amazonaws.com") | ||
.encodedPath("/path") | ||
.uri(URI.create("https://demo.us-east-1.amazonaws.com")) | ||
.build(); | ||
HttpRequest crtHttpRequest = converter.requestToCrt(request); | ||
assertThat(crtHttpRequest.getMethod()).isEqualTo("GET"); | ||
assertThat(crtHttpRequest.getEncodedPath()).isEqualTo("/path?%26ampersand%26=&%3Dequals%3D="); | ||
assertHttpRequestSame(request, crtHttpRequest); | ||
} | ||
|
||
@Test | ||
public void request_withEmptyPath_isConvertedToCrtFormat() { | ||
SdkHttpFullRequest request = SdkHttpFullRequest.builder() | ||
|
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.
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.
Can you add a test that includes other values besides
=
and&
that should be URL encoded? Like a newline or something? Just to make sure CRT handles those tooThere 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.
done