(t *testing.T, handshakerAddress, serverAddress, boundAccessToken string)
| 408 | } |
| 409 | |
| 410 | func 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 | |
| 458 | func startFakeHandshakerService(t *testing.T, wait *sync.WaitGroup) (stop func(), address string) { |
| 459 | return startFakeHandshakerServiceWithExpectedBoundAccessToken(t, wait, "") |
no test coverage detected