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

Function authorityChecker

test/authority_test.go:46–62  ·  view source on GitHub ↗
(ctx context.Context, expectedAuthority string)

Source from the content-addressed store, hash-verified

44)
45
46func authorityChecker(ctx context.Context, expectedAuthority string) (*testpb.Empty, error) {
47 md, ok := metadata.FromIncomingContext(ctx)
48 if !ok {
49 return nil, status.Error(codes.InvalidArgument, "failed to parse metadata")
50 }
51 auths, ok := md[":authority"]
52 if !ok {
53 return nil, status.Error(codes.InvalidArgument, "no authority header")
54 }
55 if len(auths) != 1 {
56 return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("no authority header, auths = %v", auths))
57 }
58 if auths[0] != expectedAuthority {
59 return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("invalid authority header %v, expected %v", auths[0], expectedAuthority))
60 }
61 return &testpb.Empty{}, nil
62}
63
64func runUnixTest(t *testing.T, address, target, expectedAuthority string, dialer func(context.Context, string) (net.Conn, error)) {
65 if !strings.HasPrefix(target, "unix-abstract:") {

Callers 3

runUnixTestFunction · 0.70

Calls 2

FromIncomingContextFunction · 0.92
ErrorFunction · 0.92

Tested by

no test coverage detected