MCPcopy
hub / github.com/ory/keto / authInterceptor

Function authInterceptor

cmd/status/root_test.go:101–116  ·  view source on GitHub ↗
(header, validValue string)

Source from the content-addressed store, hash-verified

99}
100
101func authInterceptor(header, validValue string) func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
102 return func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
103 md, ok := metadata.FromIncomingContext(ctx)
104 if !ok {
105 return nil, errors.New("not authorized, no metadata")
106 }
107 vals := md.Get(header)
108 if len(vals) != 1 {
109 return nil, errors.New("not authorized, no header values")
110 }
111 if vals[0] != validValue {
112 return nil, errors.New("not authorized, incorrect value")
113 }
114 return handler(ctx, req)
115 }
116}
117
118func TestAuthorizedRequest(t *testing.T) {
119 ts := client.NewTestServer(

Callers 2

TestAuthorizedRequestFunction · 0.85
TestAuthorityRequestFunction · 0.85

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected