-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-20981: [Flight][Integration] Generic gRPC Test Runner and Server #44115
Draft
joellubi
wants to merge
12
commits into
apache:main
Choose a base branch
from
joellubi:gh-20981
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb6b3cd
initial add integration server/client
joellubi 600f929
add auth scenario + more cleanup
joellubi 13d0e04
change module name
joellubi ed43b3e
remove arrow dependency
joellubi 83da9f8
cleanup server client conn watcher
joellubi 8f7ee93
add to github actions
joellubi 66fa84d
add license header
joellubi 97bcb36
fix auth scenario
joellubi 098602c
initial add flight_sql scenario and gen flatbuffers
joellubi c6d76da
add support for field metadata and ValidateStatementExecution cases
joellubi 5b136f6
clean up composed types
joellubi 7d08b60
complete flight_sql scenario
joellubi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cases | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/apache/arrow/dev/flight-integration/flight" | ||
"github.com/apache/arrow/dev/flight-integration/scenario" | ||
"github.com/apache/arrow/dev/flight-integration/tester" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/metadata" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func init() { | ||
var ( | ||
username = "arrow" | ||
password = "flight" | ||
authHeader = "auth-token-bin" | ||
token = username | ||
) | ||
|
||
scenario.Register( | ||
scenario.Scenario{ | ||
Name: "auth:basic_proto", | ||
Steps: []scenario.ScenarioStep{ | ||
{ | ||
Name: "unauthenticated_action", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I like this idea of separating out the subcases |
||
ServerHandler: scenario.Handler{DoAction: func(a *flight.Action, fs flight.FlightService_DoActionServer) error { | ||
md, ok := metadata.FromIncomingContext(fs.Context()) | ||
if ok && len(md.Get(authHeader)) > 0 { | ||
return fmt.Errorf("expected not to find auth header for unauthenticated action") | ||
} | ||
|
||
return status.Error(codes.Unauthenticated, "no token") | ||
}}, | ||
}, | ||
{ | ||
Name: "auth_handshake", | ||
ServerHandler: scenario.Handler{Handshake: func(fs flight.FlightService_HandshakeServer) error { | ||
in, err := fs.Recv() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var incoming flight.BasicAuth | ||
if err = proto.Unmarshal(in.Payload, &incoming); err != nil { | ||
return err | ||
} | ||
|
||
if incoming.Username != username { | ||
return fmt.Errorf("incorrect username for auth: expected: %s, got: %s", username, incoming.Username) | ||
} | ||
|
||
if incoming.Password != password { | ||
return fmt.Errorf("incorrect password for auth: expected: %s, got: %s", password, incoming.Password) | ||
} | ||
|
||
return fs.Send(&flight.HandshakeResponse{Payload: []byte(token)}) | ||
}}, | ||
}, | ||
{ | ||
Name: "authenticated_action", | ||
ServerHandler: scenario.Handler{DoAction: func(a *flight.Action, fs flight.FlightService_DoActionServer) error { | ||
md, ok := metadata.FromIncomingContext(fs.Context()) | ||
if !ok { | ||
return fmt.Errorf("auth metadata not present") | ||
} | ||
|
||
vals := md.Get(authHeader) | ||
if len(vals) != 1 { | ||
return fmt.Errorf("expected 1 token value for header \"%s\" but found %d: %s", authHeader, len(vals), vals) | ||
} | ||
|
||
if vals[0] != token { | ||
return fmt.Errorf("invalid token: expected %s, got %s", token, vals[0]) | ||
} | ||
|
||
return fs.Send(&flight.Result{Body: []byte(token)}) | ||
}}, | ||
}, | ||
}, | ||
RunClient: func(ctx context.Context, client flight.FlightServiceClient, t *tester.Tester) { | ||
actionStream, err := client.DoAction(ctx, &flight.Action{}) | ||
t.Require().NoError(err) | ||
|
||
_, err = actionStream.Recv() | ||
st, ok := status.FromError(err) | ||
t.Require().True(ok, "failed to extract grpc status from stream error") | ||
t.Assert().Equalf(codes.Unauthenticated, st.Code(), "expected stream error: %s, got: %s", codes.Unauthenticated, st.Code()) | ||
|
||
handshakeStream, err := client.Handshake(ctx) | ||
t.Require().NoError(err) | ||
|
||
b, err := proto.Marshal(&flight.BasicAuth{Username: username, Password: password}) | ||
t.Require().NoError(err) | ||
|
||
t.Require().NoError(handshakeStream.Send(&flight.HandshakeRequest{Payload: b})) | ||
|
||
in, err := handshakeStream.Recv() | ||
t.Require().NoError(err) | ||
|
||
_, err = handshakeStream.Recv() | ||
t.Require().ErrorIs(err, io.EOF, "handshake result stream had too many entries") | ||
t.Require().NoError(handshakeStream.CloseSend()) | ||
|
||
ctx = metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{authHeader: string(in.Payload)})) | ||
actionStream, err = client.DoAction(ctx, &flight.Action{}) | ||
t.Require().NoError(err) | ||
|
||
res, err := actionStream.Recv() | ||
t.Require().NoError(err) | ||
|
||
t.Assert().Equal([]byte(token), res.Body) | ||
|
||
_, err = actionStream.Recv() | ||
t.Require().ErrorIs(err, io.EOF, "action result stream had too many entries") | ||
t.Require().NoError(actionStream.CloseSend()) | ||
|
||
}, | ||
}, | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a valid filename? xD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I originally had this as
auth_basic_proto.go
just in case. Then I decided to take a look into the naming rules and was surprised to learn that Go only has requirements for the first character of a filename (source).