blob: b84b67a7e58bfb31c8d39960fa3dadc62af0e27e [file] [log] [blame]
Craig Tiller3c26d092015-06-05 14:48:30 -07001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller3c26d092015-06-05 14:48:30 -07004 * 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 Tiller9533d042016-03-25 17:11:06 -070034#include "src/core/lib/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 */
Mark D. Roth8a1d8052016-05-03 10:44:56 -070053 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00",
Craig Tiller83b2f252015-06-05 14:50:00 -070054 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070055 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00",
Craig Tiller83b2f252015-06-05 14:50:00 -070056 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070057 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00",
Craig Tiller83b2f252015-06-05 14:50:00 -070058 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070059 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x06",
Craig Tiller83b2f252015-06-05 14:50:00 -070060 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070061 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x06",
Craig Tiller83b2f252015-06-05 14:50:00 -070062 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070063 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x06",
Craig Tiller83b2f252015-06-05 14:50:00 -070064 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070065 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04",
Craig Tiller83b2f252015-06-05 14:50:00 -070066 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070067 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00",
Craig Tiller83b2f252015-06-05 14:50:00 -070068 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070069 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x01",
Craig Tiller83b2f252015-06-05 14:50:00 -070070 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070071 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\xff",
Craig Tiller83b2f252015-06-05 14:50:00 -070072 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070073 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00\x00",
Craig Tiller83b2f252015-06-05 14:50:00 -070074 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070075 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
76 PFX_STR "\x00\x00\x00\x04\x00\x00\x00",
Craig Tiller83b2f252015-06-05 14:50:00 -070077 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070078 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
79 PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00",
Craig Tiller83b2f252015-06-05 14:50:00 -070080 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tiller3c26d092015-06-05 14:48:30 -070081 /* must not send frames with stream id != 0 */
Mark D. Roth8a1d8052016-05-03 10:44:56 -070082 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller83b2f252015-06-05 14:50:00 -070083 PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070084 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller83b2f252015-06-05 14:50:00 -070085 PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0);
Craig Tiller3c26d092015-06-05 14:48:30 -070086 /* settings frame must be a multiple of six bytes long */
Mark D. Roth8a1d8052016-05-03 10:44:56 -070087 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller83b2f252015-06-05 14:50:00 -070088 PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070089 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller83b2f252015-06-05 14:50:00 -070090 PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070091 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller83b2f252015-06-05 14:50:00 -070092 PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070093 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller83b2f252015-06-05 14:50:00 -070094 PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0);
Mark D. Roth8a1d8052016-05-03 10:44:56 -070095 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller83b2f252015-06-05 14:50:00 -070096 PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0);
Craig Tiller47e541c2015-12-07 08:51:19 -080097 /* some settings values are illegal */
98 /* max frame size = 0 */
Mark D. Roth8a1d8052016-05-03 10:44:56 -070099 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tillere2c62372015-12-07 16:11:03 -0800100 PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00",
101 GRPC_BAD_CLIENT_DISCONNECT);
Mark D. Roth8a1d8052016-05-03 10:44:56 -0700102 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller620e9652015-12-14 12:02:50 -0800103 PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff",
Craig Tiller9ee2eec2015-12-08 10:28:33 -0800104 GRPC_BAD_CLIENT_DISCONNECT);
105 /* update intiial window size */
Mark D. Roth8a1d8052016-05-03 10:44:56 -0700106 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller620e9652015-12-14 12:02:50 -0800107 PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00",
Craig Tiller9ee2eec2015-12-08 10:28:33 -0800108 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tiller0ca99522015-12-09 16:31:05 -0800109 /* ack with data */
Mark D. Roth8a1d8052016-05-03 10:44:56 -0700110 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR
Craig Tiller0ca99522015-12-09 16:31:05 -0800111 "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
Craig Tiller620e9652015-12-14 12:02:50 -0800112 "\x00\x00\x01\x04\x01\x00\x00\x00\x00",
113 0);
Craig Tiller0ca99522015-12-09 16:31:05 -0800114 /* settings frame with invalid flags */
Mark D. Roth8a1d8052016-05-03 10:44:56 -0700115 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller620e9652015-12-14 12:02:50 -0800116 PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0);
Craig Tiller0ca99522015-12-09 16:31:05 -0800117 /* unknown settings should be ignored */
Mark D. Roth8a1d8052016-05-03 10:44:56 -0700118 GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL,
Craig Tiller620e9652015-12-14 12:02:50 -0800119 PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00",
Craig Tiller0ca99522015-12-09 16:31:05 -0800120 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tiller3c26d092015-06-05 14:48:30 -0700121
122 return 0;
123}