Skip to content

Commit

Permalink
alts: Extract AuthInfo after handshake in ALTS e2e test. (#6931)
Browse files Browse the repository at this point in the history
* alts: Extract AuthInfo after handshake in ALTS e2e test.

* Add comment, per review request.
  • Loading branch information
matthewstevenson88 authored Jan 22, 2024
1 parent 987df13 commit e96f521
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion credentials/alts/alts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"google.golang.org/grpc/internal/testutils"
testgrpc "google.golang.org/grpc/interop/grpc_testing"
testpb "google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
)

Expand Down Expand Up @@ -392,9 +393,10 @@ func establishAltsConnection(t *testing.T, handshakerAddress, serverAddress stri
ctx, cancel := context.WithTimeout(context.Background(), defaultTestLongTimeout)
defer cancel()
c := testgrpc.NewTestServiceClient(conn)
var peer peer.Peer
success := false
for ; ctx.Err() == nil; <-time.After(defaultTestShortTimeout) {
_, err = c.UnaryCall(ctx, &testpb.SimpleRequest{})
_, err = c.UnaryCall(ctx, &testpb.SimpleRequest{}, grpc.Peer(&peer))
if err == nil {
success = true
break
Expand All @@ -409,6 +411,20 @@ func establishAltsConnection(t *testing.T, handshakerAddress, serverAddress stri
if !success {
t.Fatalf("c.UnaryCall() timed out after %v", defaultTestShortTimeout)
}

// Check that peer.AuthInfo was populated with an ALTS AuthInfo
// instance. As a sanity check, also verify that the AuthType() and
// ApplicationProtocol() have the expected values.
if got, want := peer.AuthInfo.AuthType(), "alts"; got != want {
t.Errorf("authInfo.AuthType() = %s, want = %s", got, want)
}
authInfo, err := AuthInfoFromPeer(&peer)
if err != nil {
t.Errorf("AuthInfoFromPeer failed: %v", err)
}
if got, want := authInfo.ApplicationProtocol(), "grpc"; got != want {
t.Errorf("authInfo.ApplicationProtocol() = %s, want = %s", got, want)
}
}

func startFakeHandshakerService(t *testing.T, wait *sync.WaitGroup) (stop func(), address string) {
Expand Down

0 comments on commit e96f521

Please sign in to comment.