lidavidm commented on a change in pull request #8724:
URL: https://github.com/apache/arrow/pull/8724#discussion_r530540183



##########
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:
       Could we make this `arrow::Result<std::pair<>>`?

##########
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:
       If the intent is to test that this fails, we can `ASSERT_RAISES(IOError, 
status)` - even if we had an implementation of header auth, we'd want this to 
fail, right?




----------------------------------------------------------------
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]


Reply via email to