MCPcopy
hub / github.com/grpc/grpc-go / TestInvalidMetadata

Method TestInvalidMetadata

test/metadata_test.go:39–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37)
38
39func (s) TestInvalidMetadata(t *testing.T) {
40 grpctest.ExpectErrorN("stream: failed to validate md when setting trailer", 5)
41
42 tests := []struct {
43 name string
44 md metadata.MD
45 appendMD []string
46 want error
47 recv error
48 }{
49 {
50 name: "invalid key",
51 md: map[string][]string{string(rune(0x19)): {"testVal"}},
52 want: status.Error(codes.Internal, "header key \"\\x19\" contains illegal characters not in [0-9a-z-_.]"),
53 recv: status.Error(codes.Internal, "invalid header field"),
54 },
55 {
56 name: "invalid value",
57 md: map[string][]string{"test": {string(rune(0x19))}},
58 want: status.Error(codes.Internal, "header key \"test\" contains value with non-printable ASCII characters"),
59 recv: status.Error(codes.Internal, "invalid header field"),
60 },
61 {
62 name: "invalid appended value",
63 md: map[string][]string{"test": {"test"}},
64 appendMD: []string{"/", "value"},
65 want: status.Error(codes.Internal, "header key \"/\" contains illegal characters not in [0-9a-z-_.]"),
66 recv: status.Error(codes.Internal, "invalid header field"),
67 },
68 {
69 name: "empty appended key",
70 md: map[string][]string{"test": {"test"}},
71 appendMD: []string{"", "value"},
72 want: status.Error(codes.Internal, "there is an empty key in the header"),
73 recv: status.Error(codes.Internal, "invalid header field"),
74 },
75 {
76 name: "empty key",
77 md: map[string][]string{"": {"test"}},
78 want: status.Error(codes.Internal, "there is an empty key in the header"),
79 recv: status.Error(codes.Internal, "invalid header field"),
80 },
81 {
82 name: "-bin key with arbitrary value",
83 md: map[string][]string{"test-bin": {string(rune(0x19))}},
84 want: nil,
85 recv: io.EOF,
86 },
87 {
88 name: "valid key and value",
89 md: map[string][]string{"test": {"value"}},
90 want: nil,
91 recv: io.EOF,
92 },
93 }
94
95 testNum := 0
96 ss := &stubserver.StubServer{

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
ExpectErrorNFunction · 0.92
ErrorFunction · 0.92
JoinFunction · 0.92
PairsFunction · 0.92
NewOutgoingContextFunction · 0.92
AppendToOutgoingContextFunction · 0.92
CodeFunction · 0.92
RecvMethod · 0.65
SetHeaderMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected