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

Function DoPerRPCCreds

interop/test_utils.go:377–402  ·  view source on GitHub ↗

DoPerRPCCreds performs a unary RPC with per RPC OAUTH2 token.

(ctx context.Context, tc testgrpc.TestServiceClient, serviceAccountKeyFile, oauthScope string)

Source from the content-addressed store, hash-verified

375
376// DoPerRPCCreds performs a unary RPC with per RPC OAUTH2 token.
377func DoPerRPCCreds(ctx context.Context, tc testgrpc.TestServiceClient, serviceAccountKeyFile, oauthScope string) {
378 jsonKey := getServiceAccountJSONKey(serviceAccountKeyFile)
379 pl := ClientNewPayload(testpb.PayloadType_COMPRESSABLE, largeReqSize)
380 req := &testpb.SimpleRequest{
381 ResponseType: testpb.PayloadType_COMPRESSABLE,
382 ResponseSize: int32(largeRespSize),
383 Payload: pl,
384 FillUsername: true,
385 FillOauthScope: true,
386 }
387 token := GetToken(ctx, serviceAccountKeyFile, oauthScope)
388 kv := map[string]string{"authorization": token.Type() + " " + token.AccessToken}
389 ctx = metadata.NewOutgoingContext(ctx, metadata.MD{"authorization": []string{kv["authorization"]}})
390 reply, err := tc.UnaryCall(ctx, req)
391 if err != nil {
392 logger.Fatal("/TestService/UnaryCall RPC failed: ", err)
393 }
394 user := reply.GetUsername()
395 scope := reply.GetOauthScope()
396 if !strings.Contains(string(jsonKey), user) {
397 logger.Fatalf("Got user name %q which is NOT a substring of %q.", user, jsonKey)
398 }
399 if !strings.Contains(oauthScope, scope) {
400 logger.Fatalf("Got OAuth scope %q which is NOT a substring of %q.", scope, oauthScope)
401 }
402}
403
404// DoGoogleDefaultCredentials performs a unary RPC with google default credentials
405func DoGoogleDefaultCredentials(ctx context.Context, tc testgrpc.TestServiceClient, defaultServiceAccount string) {

Callers 1

mainFunction · 0.92

Calls 10

NewOutgoingContextFunction · 0.92
getServiceAccountJSONKeyFunction · 0.85
ClientNewPayloadFunction · 0.85
GetTokenFunction · 0.85
GetUsernameMethod · 0.80
GetOauthScopeMethod · 0.80
TypeMethod · 0.65
UnaryCallMethod · 0.65
FatalMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected