MCPcopy
hub / github.com/grpc/grpc-go / establishAltsConnectionWithBoundAccessToken

Function establishAltsConnectionWithBoundAccessToken

credentials/alts/alts_test.go:410–456  ·  view source on GitHub ↗
(t *testing.T, handshakerAddress, serverAddress, boundAccessToken string)

Source from the content-addressed store, hash-verified

408}
409
410func establishAltsConnectionWithBoundAccessToken(t *testing.T, handshakerAddress, serverAddress, boundAccessToken string) {
411 clientCreds := NewClientCreds(&ClientOptions{HandshakerServiceAddress: handshakerAddress})
412 if boundAccessToken != "" {
413 altsCreds := clientCreds.(*altsTC)
414 altsCreds.boundAccessToken = boundAccessToken
415 }
416 conn, err := grpc.NewClient(serverAddress, grpc.WithTransportCredentials(clientCreds))
417 if err != nil {
418 t.Fatalf("grpc.NewClient(%v) failed: %v", serverAddress, err)
419 }
420 defer conn.Close()
421 ctx, cancel := context.WithTimeout(context.Background(), defaultTestLongTimeout)
422 defer cancel()
423 c := testgrpc.NewTestServiceClient(conn)
424 var peer peer.Peer
425 success := false
426 for ; ctx.Err() == nil; <-time.After(defaultTestShortTimeout) {
427 _, err = c.UnaryCall(ctx, &testpb.SimpleRequest{}, grpc.Peer(&peer))
428 if err == nil {
429 success = true
430 break
431 }
432 if code := status.Code(err); code == codes.Unavailable || code == codes.DeadlineExceeded {
433 // The server is not ready yet or there were too many concurrent handshakes.
434 // Try again.
435 continue
436 }
437 t.Fatalf("c.UnaryCall() failed: %v", err)
438 }
439 if !success {
440 t.Fatalf("c.UnaryCall() timed out after %v", defaultTestShortTimeout)
441 }
442
443 // Check that peer.AuthInfo was populated with an ALTS AuthInfo
444 // instance. As a sanity check, also verify that the AuthType() and
445 // ApplicationProtocol() have the expected values.
446 if got, want := peer.AuthInfo.AuthType(), "alts"; got != want {
447 t.Errorf("authInfo.AuthType() = %s, want = %s", got, want)
448 }
449 authInfo, err := AuthInfoFromPeer(&peer)
450 if err != nil {
451 t.Errorf("AuthInfoFromPeer failed: %v", err)
452 }
453 if got, want := authInfo.ApplicationProtocol(), "grpc"; got != want {
454 t.Errorf("authInfo.ApplicationProtocol() = %s, want = %s", got, want)
455 }
456}
457
458func startFakeHandshakerService(t *testing.T, wait *sync.WaitGroup) (stop func(), address string) {
459 return startFakeHandshakerServiceWithExpectedBoundAccessToken(t, wait, "")

Callers 2

establishAltsConnectionFunction · 0.85

Calls 13

UnaryCallMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
PeerFunction · 0.92
CodeFunction · 0.92
AuthInfoFromPeerFunction · 0.85
ErrMethod · 0.80
NewClientCredsFunction · 0.70
FatalfMethod · 0.65
CloseMethod · 0.65
AuthTypeMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected