(t *testing.T)
| 40 | } |
| 41 | |
| 42 | func 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 | |
| 77 | func ExampleAuthorized() { |
| 78 | // Assume this comes from a hypothetical inter-cluster RPC call. |
nothing calls this directly
no test coverage detected