MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestMD

Function TestMD

pkg/rpcmetadata/metadata_test.go:27–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestMD(t *testing.T) {
28 a := assertions.New(t)
29
30 md1 := MD{
31 ID: "some-id",
32 AuthType: "Key",
33 AuthValue: "foo",
34 ServiceType: "component",
35 ServiceVersion: "1.2.3-dev",
36 NetAddress: "localhost",
37 Host: "hostfoo",
38 URI: "fooURI",
39 XForwardedFor: "remote-ip",
40 }
41
42 ctx := md1.ToOutgoingContext(test.Context())
43 md, _ := metadata.FromOutgoingContext(ctx)
44 ctx = metadata.NewIncomingContext(ctx, md)
45
46 md2 := FromIncomingContext(ctx)
47 a.So(md2.ID, should.Equal, md1.ID)
48 a.So(md2.AuthType, should.BeEmpty) // should be set by gRPC, not here
49 a.So(md2.AuthValue, should.BeEmpty) // should be set by gRPC, not here
50 a.So(md2.ServiceType, should.Equal, md1.ServiceType)
51 a.So(md2.ServiceVersion, should.Equal, md1.ServiceVersion)
52 a.So(md2.NetAddress, should.Equal, md1.NetAddress)
53 a.So(md2.Host, should.Equal, md1.Host)
54 a.So(md2.URI, should.Equal, md1.URI)
55 a.So(md2.XForwardedFor, should.Equal, md1.XForwardedFor)
56
57 a.So(md1.RequireTransportSecurity(), should.BeTrue)
58 a.So(md2.RequireTransportSecurity(), should.BeFalse)
59
60 {
61 ctx := metadata.NewIncomingContext(test.Context(), metadata.Pairs("authorization", "Key foo"))
62 md3 := FromIncomingContext(ctx)
63 a.So(md3.AuthType, should.Equal, "Key")
64 a.So(md3.AuthValue, should.Equal, "foo")
65 }
66}

Callers

nothing calls this directly

Calls 5

ToOutgoingContextMethod · 0.95
ContextFunction · 0.92
FromIncomingContextFunction · 0.85
NewMethod · 0.65

Tested by

no test coverage detected