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 "src/core/lib/surface/server.h"
20 #include "test/core/bad_client/bad_client.h"
21
22 #define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
23 #define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00"
24
verifier(grpc_server * server,grpc_completion_queue * cq,void * registered_method)25 static void verifier(grpc_server* server, grpc_completion_queue* cq,
26 void* registered_method) {
27 while (grpc_server_has_open_connections(server)) {
28 GPR_ASSERT(grpc_completion_queue_next(
29 cq, grpc_timeout_milliseconds_to_deadline(20), nullptr)
30 .type == GRPC_QUEUE_TIMEOUT);
31 }
32 }
33
main(int argc,char ** argv)34 int main(int argc, char** argv) {
35 grpc_test_init(argc, argv);
36 grpc_init();
37
38 /* various partial prefixes */
39 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00",
40 GRPC_BAD_CLIENT_DISCONNECT);
41 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00",
42 GRPC_BAD_CLIENT_DISCONNECT);
43 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00",
44 GRPC_BAD_CLIENT_DISCONNECT);
45 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x06",
46 GRPC_BAD_CLIENT_DISCONNECT);
47 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x06",
48 GRPC_BAD_CLIENT_DISCONNECT);
49 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x06",
50 GRPC_BAD_CLIENT_DISCONNECT);
51 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04",
52 GRPC_BAD_CLIENT_DISCONNECT);
53 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04\x00",
54 GRPC_BAD_CLIENT_DISCONNECT);
55 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04\x01",
56 GRPC_BAD_CLIENT_DISCONNECT);
57 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x04\xff",
58 GRPC_BAD_CLIENT_DISCONNECT);
59 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
60 PFX_STR "\x00\x00\x00\x04\x00\x00",
61 GRPC_BAD_CLIENT_DISCONNECT);
62 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
63 PFX_STR "\x00\x00\x00\x04\x00\x00\x00",
64 GRPC_BAD_CLIENT_DISCONNECT);
65 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
66 PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00",
67 GRPC_BAD_CLIENT_DISCONNECT);
68 /* must not send frames with stream id != 0 */
69 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
70 PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0);
71 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
72 PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0);
73 /* settings frame must be a multiple of six bytes long */
74 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
75 PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0);
76 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
77 PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0);
78 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
79 PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0);
80 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
81 PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0);
82 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
83 PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0);
84 /* some settings values are illegal */
85 /* max frame size = 0 */
86 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
87 PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00",
88 GRPC_BAD_CLIENT_DISCONNECT);
89 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
90 PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff",
91 GRPC_BAD_CLIENT_DISCONNECT);
92 /* update intiial window size */
93 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
94 PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00",
95 GRPC_BAD_CLIENT_DISCONNECT);
96 /* ack with data */
97 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
98 PFX_STR
99 "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
100 "\x00\x00\x01\x04\x01\x00\x00\x00\x00",
101 0);
102 /* settings frame with invalid flags */
103 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
104 PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0);
105 /* unknown settings should be ignored */
106 GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr,
107 PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00",
108 GRPC_BAD_CLIENT_DISCONNECT);
109
110 grpc_shutdown();
111 return 0;
112 }
113