avantgardnerio commented on code in PR #2211: URL: https://github.com/apache/arrow-rs/pull/2211#discussion_r933381161
########## arrow-flight/examples/flight_sql_server.rs: ########## @@ -41,6 +43,52 @@ pub struct FlightSqlServiceImpl {} #[tonic::async_trait] impl FlightSqlService for FlightSqlServiceImpl { type FlightService = FlightSqlServiceImpl; + + async fn do_handshake( + &self, + request: Request<Streaming<HandshakeRequest>>, + ) -> Result< + Response<Pin<Box<dyn Stream<Item = Result<HandshakeResponse, Status>> + Send>>>, + Status, + > { + let basic = "Basic "; + let authorization = request + .metadata() + .get("authorization") + .ok_or(Status::invalid_argument("authorization field not present"))? + .to_str() + .map_err(|_| Status::invalid_argument("authorization not parsable"))?; + if !authorization.starts_with(basic) { + Err(Status::invalid_argument(format!( + "Auth type not implemented: {}", + authorization + )))?; + } + let base64 = &authorization[basic.len()..]; + let bytes = base64::decode(base64) + .map_err(|_| Status::invalid_argument("authorization not parsable"))?; + let str = String::from_utf8(bytes) + .map_err(|_| Status::invalid_argument("authorization not parsable"))?; + let parts: Vec<_> = str.split(":").collect(); + if parts.len() != 2 { + Err(Status::invalid_argument(format!( + "Invalid authorization header" + )))?; + } + let user = parts[0]; + let pass = parts[1]; + if user != "admin" || pass != "password" { + Err(Status::unauthenticated("Invalid credentials!"))? + } + let result = HandshakeResponse { + protocol_version: 0, + payload: "random_uuid_token".as_bytes().to_vec(), + }; + let result = Ok(result); + let output = futures::stream::iter(vec![result]); + return Ok(Response::new(Box::pin(output))); + } + Review Comment: Sorry, I didn't mean to imply integration tests were the only way. I think they become exponentially impossible to maintain as code coverage increases - so unit tests are also required. I was just (and still am) hoping to start with a FlighSql-rs test then add unit tests in addition to that. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org