lyndonb-bq commented on a change in pull request #8724:
URL: https://github.com/apache/arrow/pull/8724#discussion_r530544565
##########
File path: cpp/src/arrow/flight/flight_test.cc
##########
@@ -1010,6 +1140,57 @@ class TestErrorMiddleware : public ::testing::Test {
std::unique_ptr<FlightServerBase> server_;
};
+class TestBasicHeaderAuthMiddleware : public ::testing::Test {
+ public:
+ void SetUp() {
+ header_middleware_ = std::make_shared<HeaderAuthServerMiddlewareFactory>();
+ bearer_middleware_ = std::make_shared<BearerAuthServerMiddlewareFactory>();
+ std::pair<std::string, std::string> bearer = make_pair(
+ kAuthHeader, std::string(kBearerPrefix) + " " +
std::string(kBearerToken));
+ ASSERT_OK(MakeServer<HeaderAuthTestServer>(
+ &server_, &client_,
+ [&](FlightServerOptions* options) {
+ options->auth_handler =
+ std::unique_ptr<ServerAuthHandler>(new NoOpAuthHandler());
+ options->middleware.push_back({"header-auth-server",
header_middleware_});
+ options->middleware.push_back({"bearer-auth-server",
bearer_middleware_});
+ return Status::OK();
+ },
+ [&](FlightClientOptions* options) { return Status::OK(); }));
+ }
+
+ void RunValidClientAuth() {
+ std::pair<std::string, std::string> bearer_token;
+ ASSERT_OK(client_->AuthenticateBasicToken({}, kValidUsername,
kValidPassword,
+ &bearer_token));
+ ASSERT_EQ(bearer_token.first, kAuthHeader);
+ ASSERT_EQ(bearer_token.second, (std::string(kBearerPrefix) +
kBearerToken));
+ std::unique_ptr<FlightListing> listing;
+ FlightCallOptions call_options;
+ call_options.headers.push_back(bearer_token);
+ ASSERT_OK(client_->ListFlights(call_options, {}, &listing));
+ ASSERT_TRUE(bearer_middleware_->GetIsValid());
+ }
+
+ void RunInvalidClientAuth() {
+ std::pair<std::string, std::string> bearer_token;
+ // Note: Status intentionally ignored because it requires C++ server
implementation of
+ // header auth. For now it returns an IOError.
+ arrow::Status status = client_->AuthenticateBasicToken(
Review comment:
Sorry, this was an artifact of my initial test implementation which was
incorrect on the test server, and always caused an error. I forgot to remove it
from the negative test once I fixed it. I will correct this.
##########
File path: cpp/src/arrow/flight/client.cc
##########
@@ -1198,6 +1227,12 @@ Status FlightClient::Authenticate(const
FlightCallOptions& options,
return impl_->Authenticate(options, std::move(auth_handler));
}
+Status FlightClient::AuthenticateBasicToken(
Review comment:
Yep, I will make this change.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]