From e96f521f478253ceb7d06c0282775e86223b5225 Mon Sep 17 00:00:00 2001 From: Matthew Stevenson <52979934+matthewstevenson88@users.noreply.github.com> Date: Mon, 22 Jan 2024 08:09:32 -0800 Subject: [PATCH] alts: Extract AuthInfo after handshake in ALTS e2e test. (#6931) * alts: Extract AuthInfo after handshake in ALTS e2e test. * Add comment, per review request. --- credentials/alts/alts_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/credentials/alts/alts_test.go b/credentials/alts/alts_test.go index 573e3b025a7c..1d7de91a7c1a 100644 --- a/credentials/alts/alts_test.go +++ b/credentials/alts/alts_test.go @@ -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" ) @@ -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 @@ -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) {