Repository navigation
Fix S3CrtClient to use origin-form request-target #3957
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| #include <aws/core/http/standard/StandardHttpRequest.h> | ||
| #include <aws/core/client/ClientConfiguration.h> | ||
| #include <aws/core/utils/logging/LogMacros.h> | ||
| #include <aws/crt/http/HttpRequestResponse.h> | ||
| #include <future> | ||
| #include <chrono> | ||
|
|
||
|
|
@@ -385,4 +386,84 @@ TEST_F(CURLHttpClientTest, TestHttpRequestWorksFine) | |
| #endif // ENABLE_CURL_CLIENT | ||
| #endif // ENABLE_HTTP_CLIENT_TESTING | ||
| #endif // NO_HTTP_CLIENT | ||
|
|
||
| #endif // DISABLE_DNS_REQUIRED_TESTS | ||
|
|
||
| // Test ToCrtHttpRequest conversion (no network required) | ||
| #include <aws/testing/AwsCppSdkGTestSuite.h> | ||
| #include <aws/core/http/standard/StandardHttpRequest.h> | ||
| #include <aws/crt/http/HttpRequestResponse.h> | ||
|
|
||
| class HttpRequestConversionTest : public Aws::Testing::AwsCppSdkGTestSuite | ||
| { | ||
| }; | ||
|
|
||
| // Test that ToCrtHttpRequest produces origin-form request-target (path + query only) | ||
| TEST_F(HttpRequestConversionTest, ToCrtHttpRequestOriginForm) | ||
| { | ||
| // Test with HTTP scheme and non-default port | ||
| { | ||
| Aws::Http::URI uri("http://example.com:9000/bucket/key?uploadId=abc&partNumber=1"); | ||
| Aws::Http::Standard::StandardHttpRequest request(uri, Aws::Http::HttpMethod::HTTP_PUT); | ||
|
|
||
| auto crtRequest = request.ToCrtHttpRequest(); | ||
| ASSERT_NE(nullptr, crtRequest); | ||
|
|
||
| // The path should be origin-form: /path?query | ||
| // NOT absolute-form: http://example.com:9000/path?query | ||
| auto pathOpt = crtRequest->GetPath(); | ||
| ASSERT_TRUE(pathOpt.has_value()); | ||
| Aws::String path(reinterpret_cast<const char*>(pathOpt->ptr), pathOpt->len); | ||
| EXPECT_EQ("/bucket/key?uploadId=abc&partNumber=1", path); | ||
| EXPECT_FALSE(path.find("http://") == 0); | ||
| EXPECT_FALSE(path.find("https://") == 0); | ||
| } | ||
|
|
||
| // Test with HTTPS scheme and default port | ||
| { | ||
| Aws::Http::URI uri("https://s3.amazonaws.com/my-bucket/my-key"); | ||
| Aws::Http::Standard::StandardHttpRequest request(uri, Aws::Http::HttpMethod::HTTP_GET); | ||
|
|
||
| auto crtRequest = request.ToCrtHttpRequest(); | ||
| ASSERT_NE(nullptr, crtRequest); | ||
|
|
||
| auto pathOpt = crtRequest->GetPath(); | ||
| ASSERT_TRUE(pathOpt.has_value()); | ||
| Aws::String path(reinterpret_cast<const char*>(pathOpt->ptr), pathOpt->len); | ||
| EXPECT_EQ("/my-bucket/my-key", path); | ||
| EXPECT_FALSE(path.find("http://") == 0); | ||
| EXPECT_FALSE(path.find("https://") == 0); | ||
| } | ||
|
|
||
| // Test with query string | ||
| { | ||
| Aws::Http::URI uri("https://storage.example.com:443/path/to/file?query=value&foo=bar"); | ||
| Aws::Http::Standard::StandardHttpRequest request(uri, Aws::Http::HttpMethod::HTTP_POST); | ||
|
|
||
| auto crtRequest = request.ToCrtHttpRequest(); | ||
| ASSERT_NE(nullptr, crtRequest); | ||
|
|
||
| auto pathOpt = crtRequest->GetPath(); | ||
| ASSERT_TRUE(pathOpt.has_value()); | ||
| Aws::String path(reinterpret_cast<const char*>(pathOpt->ptr), pathOpt->len); | ||
| EXPECT_EQ("/path/to/file?query=value&foo=bar", path); | ||
| EXPECT_FALSE(path.find("http://") == 0); | ||
| EXPECT_FALSE(path.find("https://") == 0); | ||
| } | ||
|
|
||
| // Test with root path | ||
| { | ||
| Aws::Http::URI uri("http://localhost:8080/"); | ||
| Aws::Http::Standard::StandardHttpRequest request(uri, Aws::Http::HttpMethod::HTTP_HEAD); | ||
|
|
||
| auto crtRequest = request.ToCrtHttpRequest(); | ||
| ASSERT_NE(nullptr, crtRequest); | ||
|
|
||
| auto pathOpt = crtRequest->GetPath(); | ||
| ASSERT_TRUE(pathOpt.has_value()); | ||
| Aws::String path(reinterpret_cast<const char*>(pathOpt->ptr), pathOpt->len); | ||
| // Root path should be "/" | ||
| EXPECT_EQ("/", path); | ||
| EXPECT_FALSE(path.find("http://") == 0); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add cases for the following paths whose behavior changes?
also, each case should be a separate TEST_F instead of scoped blocks in one test, so a failure points at the specific case
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this to its own file, e.g. |
||
| } | ||
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.
GetPath()adds a / before every segment, and adds one more when there are no segments. Every possible result therefore starts with / and the result will never be empty. This can be simplified toss << uri.GetURLEncodedPath() << uri.GetQueryString();