Skip to content

Commit e96f521

Browse files
alts: Extract AuthInfo after handshake in ALTS e2e test. (#6931)
* alts: Extract AuthInfo after handshake in ALTS e2e test. * Add comment, per review request.
1 parent 987df13 commit e96f521

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

credentials/alts/alts_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"google.golang.org/grpc/internal/testutils"
4141
testgrpc "google.golang.org/grpc/interop/grpc_testing"
4242
testpb "google.golang.org/grpc/interop/grpc_testing"
43+
"google.golang.org/grpc/peer"
4344
"google.golang.org/grpc/status"
4445
)
4546

@@ -392,9 +393,10 @@ func establishAltsConnection(t *testing.T, handshakerAddress, serverAddress stri
392393
ctx, cancel := context.WithTimeout(context.Background(), defaultTestLongTimeout)
393394
defer cancel()
394395
c := testgrpc.NewTestServiceClient(conn)
396+
var peer peer.Peer
395397
success := false
396398
for ; ctx.Err() == nil; <-time.After(defaultTestShortTimeout) {
397-
_, err = c.UnaryCall(ctx, &testpb.SimpleRequest{})
399+
_, err = c.UnaryCall(ctx, &testpb.SimpleRequest{}, grpc.Peer(&peer))
398400
if err == nil {
399401
success = true
400402
break
@@ -409,6 +411,20 @@ func establishAltsConnection(t *testing.T, handshakerAddress, serverAddress stri
409411
if !success {
410412
t.Fatalf("c.UnaryCall() timed out after %v", defaultTestShortTimeout)
411413
}
414+
415+
// Check that peer.AuthInfo was populated with an ALTS AuthInfo
416+
// instance. As a sanity check, also verify that the AuthType() and
417+
// ApplicationProtocol() have the expected values.
418+
if got, want := peer.AuthInfo.AuthType(), "alts"; got != want {
419+
t.Errorf("authInfo.AuthType() = %s, want = %s", got, want)
420+
}
421+
authInfo, err := AuthInfoFromPeer(&peer)
422+
if err != nil {
423+
t.Errorf("AuthInfoFromPeer failed: %v", err)
424+
}
425+
if got, want := authInfo.ApplicationProtocol(), "grpc"; got != want {
426+
t.Errorf("authInfo.ApplicationProtocol() = %s, want = %s", got, want)
427+
}
412428
}
413429

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

0 commit comments

Comments
 (0)