1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include "test/core/bad_client/bad_client.h"
20
21 #include <string.h>
22
23 #include <grpc/grpc.h>
24
25 #include "src/core/lib/surface/server.h"
26 #include "test/core/end2end/cq_verifier.h"
27
28 #define PFX_STR \
29 "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
30 "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */
31
verifier(grpc_server * server,grpc_completion_queue * cq,void * registered_method)32 static void verifier(grpc_server* server, grpc_completion_queue* cq,
33 void* registered_method) {
34 while (grpc_server_has_open_connections(server)) {
35 GPR_ASSERT(grpc_completion_queue_next(
36 cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
37 .type == GRPC_QUEUE_TIMEOUT);
38 }
39 }
40
main(int argc,char ** argv)41 int main(int argc, char** argv) {
42 grpc_test_init(argc, argv);
43 grpc_init();
44
45 /* invalid content type */
46 GRPC_RUN_BAD_CLIENT_TEST(
47 verifier, nullptr,
48 PFX_STR
49 "\x00\x00\xc2\x01\x04\x00\x00\x00\x01"
50 "\x10\x05:path\x08/foo/bar"
51 "\x10\x07:scheme\x04http"
52 "\x10\x07:method\x04POST"
53 "\x10\x0a:authority\x09localhost"
54 "\x10\x0c"
55 "content-type\x09text/html"
56 "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
57 "\x10\x02te\x08trailers"
58 "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
59 GRPC_BAD_CLIENT_DISCONNECT);
60
61 /* invalid te */
62 GRPC_RUN_BAD_CLIENT_TEST(
63 verifier, nullptr,
64 PFX_STR
65 "\x00\x00\xcb\x01\x04\x00\x00\x00\x01"
66 "\x10\x05:path\x08/foo/bar"
67 "\x10\x07:scheme\x04http"
68 "\x10\x07:method\x04POST"
69 "\x10\x0a:authority\x09localhost"
70 "\x10\x0c"
71 "content-type\x10"
72 "application/grpc"
73 "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
74 "\x10\x02te\x0a"
75 "frobnicate"
76 "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
77 GRPC_BAD_CLIENT_DISCONNECT);
78
79 /* two path headers */
80 GRPC_RUN_BAD_CLIENT_TEST(
81 verifier, nullptr,
82 PFX_STR
83 "\x00\x00\xd9\x01\x04\x00\x00\x00\x01"
84 "\x10\x05:path\x08/foo/bar"
85 "\x10\x05:path\x08/foo/bah"
86 "\x10\x07:scheme\x04http"
87 "\x10\x07:method\x04POST"
88 "\x10\x0a:authority\x09localhost"
89 "\x10\x0c"
90 "content-type\x10"
91 "application/grpc"
92 "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
93 "\x10\x02te\x08trailers"
94 "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
95 GRPC_BAD_CLIENT_DISCONNECT);
96
97 /* bad accept-encoding algorithm */
98 GRPC_RUN_BAD_CLIENT_TEST(
99 verifier, nullptr,
100 PFX_STR
101 "\x00\x00\xd2\x01\x04\x00\x00\x00\x01"
102 "\x10\x05:path\x08/foo/bar"
103 "\x10\x07:scheme\x04http"
104 "\x10\x07:method\x04POST"
105 "\x10\x0a:authority\x09localhost"
106 "\x10\x0c"
107 "content-type\x10"
108 "application/grpc"
109 "\x10\x14grpc-accept-encoding\x1enobody-knows-the-trouble-i-see"
110 "\x10\x02te\x08trailers"
111 "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
112 GRPC_BAD_CLIENT_DISCONNECT);
113
114 /* bad grpc-encoding algorithm */
115 GRPC_RUN_BAD_CLIENT_TEST(
116 verifier, nullptr,
117 PFX_STR
118 "\x00\x00\xf5\x01\x04\x00\x00\x00\x01"
119 "\x10\x05:path\x08/foo/bar"
120 "\x10\x07:scheme\x04http"
121 "\x10\x07:method\x04POST"
122 "\x10\x0a:authority\x09localhost"
123 "\x10\x0c"
124 "content-type\x10"
125 "application/grpc"
126 "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
127 "\x10\x0dgrpc-encoding\x1cyou-dont-know-how-to-do-this"
128 "\x10\x02te\x08trailers"
129 "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
130 GRPC_BAD_CLIENT_DISCONNECT);
131
132 grpc_shutdown();
133 return 0;
134 }
135