Skip to content

Commit b915d3b

Browse files
authored
fix/when s_preservePathSeparators enabled (#3619)
1 parent e107790 commit b915d3b

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

src/aws-cpp-sdk-core/include/aws/core/http/URI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace Aws
153153
{
154154
m_pathSegments.push_back(segment);
155155
}
156-
m_pathHasTrailingSlash = (m_pathSegments.empty() || !s_preservePathSeparators) && (!segments.empty() && segments.back() == '/');
156+
m_pathHasTrailingSlash = !segments.empty() && segments.back() == '/';
157157
}
158158

159159
/**

tests/aws-cpp-sdk-s3-unit-tests/S3UnitTests.cpp

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,53 @@ TEST_F(S3UnitTest, S3UriPathPreservationOn) {
224224
//Turn on path preservation
225225
Aws::Http::SetPreservePathSeparators(true);
226226

227-
auto putObjectRequest = PutObjectRequest()
228-
.WithBucket("velvetunderground")
229-
.WithKey("////stephanie////says////////////that////////she//wants///////to/know.txt");
227+
struct TestCase {
228+
const char* bucket;
229+
const char* key;
230+
const char* expectedUri;
231+
};
230232

231-
std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>(ALLOCATION_TAG,
232-
"What country shall I say is calling From across the world?",
233-
std::ios_base::in | std::ios_base::binary);
233+
TestCase testCases[] = {
234+
{
235+
"velvetunderground",
236+
"////stephanie////says////////////that////////she//wants///////to/know.txt",
237+
"https://velvetunderground.s3.us-east-1.amazonaws.com/////stephanie////says////////////that////////she//wants///////to/know.txt"
238+
},
239+
{
240+
"velvetunderground",
241+
"////stephanie////says////////////that////////she//wants///////to/know.txt/",
242+
"https://velvetunderground.s3.us-east-1.amazonaws.com/////stephanie////says////////////that////////she//wants///////to/know.txt/"
243+
},
244+
{
245+
"velvetunderground",
246+
"////stephanie////says////////////that////////she//wants///////to/know.txt//",
247+
"https://velvetunderground.s3.us-east-1.amazonaws.com/////stephanie////says////////////that////////she//wants///////to/know.txt//"
248+
}
249+
};
234250

235-
putObjectRequest.SetBody(body);
251+
for (const auto& testCase : testCases) {
252+
auto putObjectRequest = PutObjectRequest()
253+
.WithBucket(testCase.bucket)
254+
.WithKey(testCase.key);
236255

237-
//We have to mock requset because it is used to create the return body, it actually isnt used.
238-
auto mockRequest = Aws::MakeShared<Standard::StandardHttpRequest>(ALLOCATION_TAG, "mockuri", HttpMethod::HTTP_GET);
239-
mockRequest->SetResponseStreamFactory([]() -> IOStream* {
240-
return Aws::New<StringStream>(ALLOCATION_TAG, "response-string", std::ios_base::in | std::ios_base::binary);
241-
});
242-
auto mockResponse = Aws::MakeShared<Standard::StandardHttpResponse>(ALLOCATION_TAG, mockRequest);
243-
mockResponse->SetResponseCode(HttpResponseCode::OK);
244-
_mockHttpClient->AddResponseToReturn(mockResponse);
256+
std::shared_ptr<IOStream> body = Aws::MakeShared<StringStream>(ALLOCATION_TAG,
257+
"test content", std::ios_base::in | std::ios_base::binary);
258+
putObjectRequest.SetBody(body);
245259

246-
const auto response = _s3Client->PutObject(putObjectRequest);
247-
AWS_EXPECT_SUCCESS(response);
260+
auto mockRequest = Aws::MakeShared<Standard::StandardHttpRequest>(ALLOCATION_TAG, "mockuri", HttpMethod::HTTP_GET);
261+
mockRequest->SetResponseStreamFactory([]() -> IOStream* {
262+
return Aws::New<StringStream>(ALLOCATION_TAG, "response-string", std::ios_base::in | std::ios_base::binary);
263+
});
264+
auto mockResponse = Aws::MakeShared<Standard::StandardHttpResponse>(ALLOCATION_TAG, mockRequest);
265+
mockResponse->SetResponseCode(HttpResponseCode::OK);
266+
_mockHttpClient->AddResponseToReturn(mockResponse);
248267

249-
const auto seenRequest = _mockHttpClient->GetMostRecentHttpRequest();
250-
EXPECT_EQ("https://velvetunderground.s3.us-east-1.amazonaws.com/////stephanie////says////////////that////////she//wants///////to/know.txt", seenRequest.GetUri().GetURIString());
268+
const auto response = _s3Client->PutObject(putObjectRequest);
269+
AWS_EXPECT_SUCCESS(response);
270+
271+
const auto seenRequest = _mockHttpClient->GetMostRecentHttpRequest();
272+
EXPECT_EQ(testCase.expectedUri, seenRequest.GetUri().GetURIString());
273+
}
251274
}
252275

253276
TEST_F(S3UnitTest, S3EmbeddedErrorTest) {

tools/scripts/run_integration_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def main():
4444
"aws-cpp-sdk-dynamodb-integration-tests",
4545
"aws-cpp-sdk-sqs-integration-tests",
4646
"aws-cpp-sdk-sqs-unit-tests",
47+
"aws-cpp-sdk-sns-integration-tests",
4748
"aws-cpp-sdk-s3-integration-tests",
4849
"aws-cpp-sdk-s3-unit-tests",
4950
"aws-cpp-sdk-s3-crt-integration-tests",

0 commit comments

Comments
 (0)