(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func TestRequestMetadata(t *testing.T) { |
| 30 | a := assertions.New(t) |
| 31 | ctx := test.Context() |
| 32 | |
| 33 | md1 := MD{ |
| 34 | ID: "some-id", |
| 35 | AuthType: "Key", |
| 36 | AuthValue: "foo", |
| 37 | ServiceType: "component", |
| 38 | ServiceVersion: "1.2.3-dev", |
| 39 | NetAddress: "localhost", |
| 40 | Host: "hostfoo", |
| 41 | URI: "fooURI", |
| 42 | } |
| 43 | md2 := FromIncomingContext(ctx) |
| 44 | |
| 45 | { |
| 46 | md, err := md1.GetRequestMetadata(test.Context()) |
| 47 | a.So(err, should.BeNil) |
| 48 | a.So(md, should.Resemble, map[string]string{ |
| 49 | "id": "some-id", |
| 50 | "authorization": "Key foo", |
| 51 | }) |
| 52 | } |
| 53 | |
| 54 | { |
| 55 | md, err := md2.GetRequestMetadata(test.Context()) |
| 56 | a.So(err, should.BeNil) |
| 57 | a.So(md, should.BeEmpty) |
| 58 | } |
| 59 | |
| 60 | { |
| 61 | ctx := metadata.NewIncomingContext(test.Context(), metadata.New(map[string]string{ |
| 62 | "id": "some-id", |
| 63 | "authorization": "Key foo", |
| 64 | "host": "test.local", |
| 65 | })) |
| 66 | callOpt, err := WithForwardedAuth(ctx, true) |
| 67 | a.So(err, should.BeNil) |
| 68 | requestMD, err := callOpt.(grpc.PerRPCCredsCallOption).Creds.GetRequestMetadata(ctx) |
| 69 | a.So(err, should.BeNil) |
| 70 | a.So(requestMD, should.Resemble, map[string]string{ |
| 71 | "id": "some-id", |
| 72 | "authorization": "Key foo", |
| 73 | }) |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | ctx := metadata.NewIncomingContext(test.Context(), metadata.New(map[string]string{ |
| 78 | "id": "some-id", |
| 79 | "host": "test.local", |
| 80 | })) |
| 81 | _, err := WithForwardedAuth(ctx, true) |
| 82 | a.So(errors.IsUnauthenticated(err), should.BeTrue) |
| 83 | } |
| 84 | } |
nothing calls this directly
no test coverage detected