blob: 108b0bd3984e6fa88ec4e6f8eb56299aca57cf9e [file] [log] [blame]
Craig Tiller3c26d092015-06-05 14:48:30 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Craig Tiller3c26d092015-06-05 14:48:30 -070034#include "src/core/surface/server.h"
Craig Tillerf40df232016-03-25 13:38:14 -070035#include "test/core/bad_client/bad_client.h"
Craig Tiller3c26d092015-06-05 14:48:30 -070036
37#define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
Craig Tiller47e541c2015-12-07 08:51:19 -080038#define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00"
Craig Tiller3c26d092015-06-05 14:48:30 -070039
Craig Tiller6cb69172015-12-14 13:35:53 -080040static void verifier(grpc_server *server, grpc_completion_queue *cq,
41 void *registered_method) {
Craig Tiller3c26d092015-06-05 14:48:30 -070042 while (grpc_server_has_open_connections(server)) {
Craig Tillerf40df232016-03-25 13:38:14 -070043 GPR_ASSERT(grpc_completion_queue_next(
44 cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20), NULL)
45 .type == GRPC_QUEUE_TIMEOUT);
Craig Tiller3c26d092015-06-05 14:48:30 -070046 }
47}
48
49int main(int argc, char **argv) {
50 grpc_test_init(argc, argv);
51
52 /* various partial prefixes */
Craig Tiller83b2f252015-06-05 14:50:00 -070053 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00",
54 GRPC_BAD_CLIENT_DISCONNECT);
55 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00",
56 GRPC_BAD_CLIENT_DISCONNECT);
57 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00",
58 GRPC_BAD_CLIENT_DISCONNECT);
59 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x06",
60 GRPC_BAD_CLIENT_DISCONNECT);
61 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x06",
62 GRPC_BAD_CLIENT_DISCONNECT);
63 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x06",
64 GRPC_BAD_CLIENT_DISCONNECT);
65 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x04",
66 GRPC_BAD_CLIENT_DISCONNECT);
67 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x04\x00",
68 GRPC_BAD_CLIENT_DISCONNECT);
69 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x04\x01",
70 GRPC_BAD_CLIENT_DISCONNECT);
71 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x04\xff",
72 GRPC_BAD_CLIENT_DISCONNECT);
73 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x04\x00\x00",
74 GRPC_BAD_CLIENT_DISCONNECT);
75 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x04\x00\x00\x00",
76 GRPC_BAD_CLIENT_DISCONNECT);
77 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00",
78 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tiller3c26d092015-06-05 14:48:30 -070079 /* must not send frames with stream id != 0 */
Craig Tiller83b2f252015-06-05 14:50:00 -070080 GRPC_RUN_BAD_CLIENT_TEST(verifier,
81 PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0);
82 GRPC_RUN_BAD_CLIENT_TEST(verifier,
83 PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0);
Craig Tiller3c26d092015-06-05 14:48:30 -070084 /* settings frame must be a multiple of six bytes long */
Craig Tiller83b2f252015-06-05 14:50:00 -070085 GRPC_RUN_BAD_CLIENT_TEST(verifier,
86 PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0);
87 GRPC_RUN_BAD_CLIENT_TEST(verifier,
88 PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0);
89 GRPC_RUN_BAD_CLIENT_TEST(verifier,
90 PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0);
91 GRPC_RUN_BAD_CLIENT_TEST(verifier,
92 PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0);
93 GRPC_RUN_BAD_CLIENT_TEST(verifier,
94 PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0);
Craig Tiller47e541c2015-12-07 08:51:19 -080095 /* some settings values are illegal */
96 /* max frame size = 0 */
97 GRPC_RUN_BAD_CLIENT_TEST(verifier,
Craig Tillere2c62372015-12-07 16:11:03 -080098 PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00",
99 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tiller9ee2eec2015-12-08 10:28:33 -0800100 GRPC_RUN_BAD_CLIENT_TEST(verifier,
Craig Tiller620e9652015-12-14 12:02:50 -0800101 PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff",
Craig Tiller9ee2eec2015-12-08 10:28:33 -0800102 GRPC_BAD_CLIENT_DISCONNECT);
103 /* update intiial window size */
104 GRPC_RUN_BAD_CLIENT_TEST(verifier,
Craig Tiller620e9652015-12-14 12:02:50 -0800105 PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00",
Craig Tiller9ee2eec2015-12-08 10:28:33 -0800106 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tiller0ca99522015-12-09 16:31:05 -0800107 /* ack with data */
Craig Tiller620e9652015-12-14 12:02:50 -0800108 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
Craig Tiller0ca99522015-12-09 16:31:05 -0800109 "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
Craig Tiller620e9652015-12-14 12:02:50 -0800110 "\x00\x00\x01\x04\x01\x00\x00\x00\x00",
111 0);
Craig Tiller0ca99522015-12-09 16:31:05 -0800112 /* settings frame with invalid flags */
113 GRPC_RUN_BAD_CLIENT_TEST(verifier,
Craig Tiller620e9652015-12-14 12:02:50 -0800114 PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0);
Craig Tiller0ca99522015-12-09 16:31:05 -0800115 /* unknown settings should be ignored */
116 GRPC_RUN_BAD_CLIENT_TEST(verifier,
Craig Tiller620e9652015-12-14 12:02:50 -0800117 PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00",
Craig Tiller0ca99522015-12-09 16:31:05 -0800118 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tiller3c26d092015-06-05 14:48:30 -0700119
120 return 0;
121}