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

Function TestVerify

pkg/auth/cluster/cluster_test.go:42–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestVerify(t *testing.T) {
43 a := assertions.New(t)
44
45 keys := [][]byte{
46 {0x00, 0xaa, 0x12},
47 }
48 ctxWithAuthorization := cluster.VerifySource(context.Background(), keys)
49 a.So(cluster.Authorized(ctxWithAuthorization), should.NotBeNil)
50
51 md := metadata.MD{}
52
53 for _, tc := range []struct {
54 key []byte
55 success bool
56 }{
57 {
58 key: keys[0],
59 success: true,
60 },
61 {
62 key: []byte{0x00, 0x00},
63 success: false,
64 },
65 } {
66 md["authorization"] = []string{fmt.Sprintf("%s %X", cluster.AuthType, tc.key)}
67 ctxWithMetadata := metadata.NewIncomingContext(context.Background(), md)
68 ctxWithAuthorization = cluster.VerifySource(ctxWithMetadata, keys)
69 if tc.success {
70 a.So(cluster.Authorized(ctxWithAuthorization), should.BeNil)
71 } else {
72 a.So(cluster.Authorized(ctxWithAuthorization), should.NotBeNil)
73 }
74 }
75}
76
77func ExampleAuthorized() {
78 // Assume this comes from a hypothetical inter-cluster RPC call.

Callers

nothing calls this directly

Calls 3

VerifySourceFunction · 0.92
AuthorizedFunction · 0.92
NewMethod · 0.65

Tested by

no test coverage detected