Skip to content

Commit 7287e41

Browse files
committed
added testing for httpclient override
1 parent 86518de commit 7287e41

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

tests/aws-cpp-sdk-core-tests/utils/stream/ChunkingInterceptorTest.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#include <aws/core/utils/crypto/CRC32.h>
77
#include <smithy/client/features/ChunkingInterceptor.h>
88
#include <aws/testing/AwsCppSdkGTestSuite.h>
9+
#include <aws/core/client/ClientConfiguration.h>
10+
#include <smithy/interceptor/InterceptorContext.h>
11+
#include <aws/core/http/HttpClient.h>
12+
#include <aws/core/AmazonWebServiceRequest.h>
13+
#include <aws/core/http/HttpTypes.h>
914

1015
using namespace Aws;
1116
using namespace Aws::Http::Standard;
@@ -14,6 +19,14 @@ using namespace Aws::Utils::Crypto;
1419

1520
const char* CHUNKING_TEST_LOG_TAG = "CHUNKING_INTERCEPTOR_TEST";
1621

22+
// Mock implementation of AmazonWebServiceRequest
23+
class MockRequest : public Aws::AmazonWebServiceRequest {
24+
public:
25+
std::shared_ptr<Aws::IOStream> GetBody() const override { return nullptr; }
26+
Aws::Http::HeaderValueCollection GetHeaders() const override { return {}; }
27+
const char* GetServiceRequestName() const override { return "MockRequest"; }
28+
};
29+
1730
class ChunkingInterceptorTest : public Aws::Testing::AwsCppSdkGTestSuite {
1831
protected:
1932
template <typename Fn>
@@ -36,7 +49,7 @@ TEST_F(ChunkingInterceptorTest, ChunkedStreamShouldWork) {
3649
char buffer[100];
3750
std::stringstream output;
3851

39-
// Read in 10-byte chunks like original test
52+
// Read in 10-byte chunks
4053
for (int i = 0; i < 4; i++) {
4154
chunkedStream.read(buffer, 10);
4255
auto bytesRead = chunkedStream.gcount();
@@ -100,4 +113,50 @@ TEST_F(ChunkingInterceptorTest, ShouldWorkOnEmptyStream) {
100113
std::string output(buffer, bytesRead);
101114
EXPECT_EQ("0\r\nx-amz-checksum-crc32:AAAAAA==\r\n\r\n", output);
102115
});
116+
}
117+
118+
// Custom HTTP client (inherits default IsDefaultAwsHttpClient() = false from base class)
119+
class CustomHttpClient : public Aws::Http::HttpClient {
120+
public:
121+
std::shared_ptr<Aws::Http::HttpResponse> MakeRequest(const std::shared_ptr<Aws::Http::HttpRequest>&,
122+
Aws::Utils::RateLimits::RateLimiterInterface*,
123+
Aws::Utils::RateLimits::RateLimiterInterface*) const override {
124+
return nullptr;
125+
}
126+
};
127+
128+
TEST_F(ChunkingInterceptorTest, ShouldNotApplyChunkingForCustomHttpClient) {
129+
// Simulate the GetChunkingConfig behavior from AWSClient.cpp
130+
// When IsDefaultAwsHttpClient() returns false, httpClientChunkedMode is set to CLIENT_IMPLEMENTATION
131+
Aws::Client::ClientConfiguration config;
132+
auto customHttpClient = Aws::MakeShared<CustomHttpClient>(CHUNKING_TEST_LOG_TAG);
133+
134+
// This simulates the logic in GetChunkingConfig function
135+
if (!customHttpClient->IsDefaultAwsHttpClient()) {
136+
config.httpClientChunkedMode = Aws::Client::HttpClientChunkedMode::CLIENT_IMPLEMENTATION;
137+
}
138+
139+
ChunkingInterceptor interceptor(config);
140+
141+
// Create request with checksum (would normally trigger chunking)
142+
auto request = Aws::MakeShared<StandardHttpRequest>(CHUNKING_TEST_LOG_TAG, "test.com", Http::HttpMethod::HTTP_POST);
143+
auto requestHash = Aws::MakeShared<CRC32>(CHUNKING_TEST_LOG_TAG);
144+
request->SetRequestHash("crc32", requestHash);
145+
146+
auto inputStream = Aws::MakeShared<Aws::StringStream>(CHUNKING_TEST_LOG_TAG);
147+
*inputStream << "test data";
148+
request->AddContentBody(inputStream);
149+
150+
// Create interceptor context with a mock request
151+
MockRequest mockRequest;
152+
smithy::interceptor::InterceptorContext context(mockRequest);
153+
context.SetTransmitRequest(request);
154+
155+
// Apply interceptor
156+
auto result = interceptor.ModifyBeforeSigning(context);
157+
158+
// Verify chunking was NOT applied because custom HTTP client uses default IsDefaultAwsHttpClient() = false
159+
EXPECT_EQ(request, result.GetResult());
160+
EXPECT_FALSE(request->HasHeader(Aws::Http::AWS_TRAILER_HEADER));
161+
EXPECT_FALSE(request->HasHeader(Aws::Http::TRANSFER_ENCODING_HEADER));
103162
}

0 commit comments

Comments
 (0)