raulcd commented on code in PR #50044:
URL: https://github.com/apache/arrow/pull/50044#discussion_r3413704594
##########
cpp/src/arrow/filesystem/s3fs_test.cc:
##########
@@ -398,6 +398,92 @@ TEST_F(S3OptionsTest, FromAccessKey) {
ASSERT_EQ(options.GetSessionToken(), "token");
}
+TEST_F(S3OptionsTest, FromUriAndOptionsCredentials) {
+ std::string path;
+ S3Options options;
+ FileSystemFactoryOptions kv{
+ {"access_key", std::string("ak")},
+ {"secret_key", std::string("sk")},
+ };
+ ASSERT_OK_AND_ASSIGN(options, S3Options::FromUriAndOptions("s3://", kv,
&path));
+ ASSERT_EQ(options.GetAccessKey(), "ak");
+ ASSERT_EQ(options.GetSecretKey(), "sk");
+ ASSERT_EQ(options.GetSessionToken(), "");
+
+ kv.push_back({"session_token", std::string("tok")});
+ ASSERT_OK_AND_ASSIGN(options, S3Options::FromUriAndOptions("s3://", kv,
&path));
+ ASSERT_EQ(options.GetAccessKey(), "ak");
+ ASSERT_EQ(options.GetSecretKey(), "sk");
+ ASSERT_EQ(options.GetSessionToken(), "tok");
+
+ // Failure scenarios
+ // Pairing is correct
+ ASSERT_THAT(
+ S3Options::FromUriAndOptions("s3://", {{"access_key",
std::string("ak")}}, &path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("must be provided
together")));
+ ASSERT_THAT(
+ S3Options::FromUriAndOptions("s3://", {{"session_token",
std::string("tok")}},
+ &path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("session_token'
requires")));
+ // unknown option key
+ ASSERT_THAT(S3Options::FromUriAndOptions("s3://", {{"bogus",
std::string("x")}}, &path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("Unexpected
option")));
+ // const char* is rejected. Options must be an explicit std::string
+ ASSERT_THAT(S3Options::FromUriAndOptions("s3://", {{"access_key", "42"}},
&path),
+ Raises(StatusCode::Invalid, ::testing::HasSubstr("wrong type")));
+}
+
+TEST_F(S3OptionsTest, FromUriAndOptionsCredentialPrecedence) {
+ std::string path;
+ S3Options options;
+ // options override URI userinfo when not empty
Review Comment:
I thought about options precedence but I think you are right, rejecting is
probably better otherwise people might get unexpected behaviors of supplied
credentials not being used.
--
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]