Copilot commented on code in PR #50205:
URL: https://github.com/apache/arrow/pull/50205#discussion_r3428027032
##########
cpp/src/arrow/filesystem/s3fs_test.cc:
##########
@@ -481,6 +481,35 @@ TEST_F(S3FileSystemRegionTest, EnvironmentVariable) {
}
#endif
+////////////////////////////////////////////////////////////////////////////
+// S3FileSystem make URI test
+
+class S3FileSystemMakeUri : public AwsTestMixin {};
+
+TEST_F(S3FileSystemMakeUri, MakeUriWithCredentials) {
+ S3Options options;
+ options.ConfigureAccessKey("minio", "miniopass");
+ options.region = "us-east-1";
+ ASSERT_OK_AND_ASSIGN(auto fs, S3FileSystem::Make(options));
+ ASSERT_OK_AND_ASSIGN(auto uri,
fs->MakeUri("/bucket/somedir/subdir/subfile"));
+ EXPECT_EQ(uri,
+ "s3://minio:miniopass@bucket/somedir/subdir/subfile"
+ "?region=us-east-1&scheme=https&endpoint_override="
+ "&allow_bucket_creation=0&allow_bucket_deletion=0");
+}
Review Comment:
Add a regression assertion for credentials requiring escaping (e.g. secret
containing '/'). Without it, `MakeUri` can silently generate a URI that cannot
be parsed back correctly.
##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -3052,13 +3052,21 @@ Result<std::string> S3FileSystem::MakeUri(std::string
path) const {
if (path.length() <= 1 || path[0] != '/') {
return Status::Invalid("MakeUri requires an absolute, non-root path, got
", path);
}
- ARROW_ASSIGN_OR_RAISE(auto uri, util::UriFromAbsolutePath(path));
+ ARROW_ASSIGN_OR_RAISE(auto uri_from_path, util::UriFromAbsolutePath(path));
+ constexpr std::string_view kFileScheme = "file://";
+ std::string_view uri_view(uri_from_path);
+ if (uri_view.starts_with(kFileScheme)) {
+ uri_view.remove_prefix(kFileScheme.size());
+ }
+ if (uri_view.starts_with("/")) {
+ // Remove leading slash if present
+ uri_view.remove_prefix(1);
+ }
+ std::string uri = "s3://";
if (!options().GetAccessKey().empty()) {
- uri = "s3://" + options().GetAccessKey() + ":" + options().GetSecretKey()
+ "@" +
- uri.substr("file:///"s.size());
- } else {
- uri = "s3" + uri.substr("file"s.size());
+ uri += options().GetAccessKey() + ":" + options().GetSecretKey() + "@";
}
Review Comment:
`MakeUri` embeds access/secret in the URI userinfo without percent-encoding.
Real AWS secret access keys commonly contain '/', which is not valid in the
userinfo component and will break round-tripping through `S3Options::FromUri`
(it unescapes username/password). Encode both parts before concatenating.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]