From 34a57d0346afe95e11104462c30dc468b0cb0b89 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 23 Oct 2017 15:33:21 -0700 Subject: rename all test core files to cc and a lot of C++ style conversions --- test/core/bad_client/tests/badreq.c | 125 --------- test/core/bad_client/tests/badreq.cc | 125 +++++++++ test/core/bad_client/tests/connection_prefix.c | 60 ----- test/core/bad_client/tests/connection_prefix.cc | 60 +++++ test/core/bad_client/tests/head_of_line_blocking.c | 136 ---------- .../core/bad_client/tests/head_of_line_blocking.cc | 136 ++++++++++ test/core/bad_client/tests/headers.c | 293 --------------------- test/core/bad_client/tests/headers.cc | 293 +++++++++++++++++++++ .../core/bad_client/tests/initial_settings_frame.c | 108 -------- .../bad_client/tests/initial_settings_frame.cc | 108 ++++++++ test/core/bad_client/tests/large_metadata.c | 240 ----------------- test/core/bad_client/tests/large_metadata.cc | 240 +++++++++++++++++ .../bad_client/tests/server_registered_method.c | 124 --------- .../bad_client/tests/server_registered_method.cc | 124 +++++++++ test/core/bad_client/tests/simple_request.c | 166 ------------ test/core/bad_client/tests/simple_request.cc | 166 ++++++++++++ test/core/bad_client/tests/unknown_frame.c | 44 ---- test/core/bad_client/tests/unknown_frame.cc | 44 ++++ test/core/bad_client/tests/window_overflow.c | 98 ------- test/core/bad_client/tests/window_overflow.cc | 98 +++++++ 20 files changed, 1394 insertions(+), 1394 deletions(-) delete mode 100644 test/core/bad_client/tests/badreq.c create mode 100644 test/core/bad_client/tests/badreq.cc delete mode 100644 test/core/bad_client/tests/connection_prefix.c create mode 100644 test/core/bad_client/tests/connection_prefix.cc delete mode 100644 test/core/bad_client/tests/head_of_line_blocking.c create mode 100644 test/core/bad_client/tests/head_of_line_blocking.cc delete mode 100644 test/core/bad_client/tests/headers.c create mode 100644 test/core/bad_client/tests/headers.cc delete mode 100644 test/core/bad_client/tests/initial_settings_frame.c create mode 100644 test/core/bad_client/tests/initial_settings_frame.cc delete mode 100644 test/core/bad_client/tests/large_metadata.c create mode 100644 test/core/bad_client/tests/large_metadata.cc delete mode 100644 test/core/bad_client/tests/server_registered_method.c create mode 100644 test/core/bad_client/tests/server_registered_method.cc delete mode 100644 test/core/bad_client/tests/simple_request.c create mode 100644 test/core/bad_client/tests/simple_request.cc delete mode 100644 test/core/bad_client/tests/unknown_frame.c create mode 100644 test/core/bad_client/tests/unknown_frame.cc delete mode 100644 test/core/bad_client/tests/window_overflow.c create mode 100644 test/core/bad_client/tests/window_overflow.cc (limited to 'test/core/bad_client/tests') diff --git a/test/core/bad_client/tests/badreq.c b/test/core/bad_client/tests/badreq.c deleted file mode 100644 index 7d9a103e43..0000000000 --- a/test/core/bad_client/tests/badreq.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* invalid content type */ - GRPC_RUN_BAD_CLIENT_TEST( - verifier, NULL, PFX_STR - "\x00\x00\xc2\x01\x04\x00\x00\x00\x01" - "\x10\x05:path\x08/foo/bar" - "\x10\x07:scheme\x04http" - "\x10\x07:method\x04POST" - "\x10\x0a:authority\x09localhost" - "\x10\x0c" - "content-type\x09text/html" - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" - "\x10\x02te\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", - GRPC_BAD_CLIENT_DISCONNECT); - - /* invalid te */ - GRPC_RUN_BAD_CLIENT_TEST( - verifier, NULL, PFX_STR - "\x00\x00\xcb\x01\x04\x00\x00\x00\x01" - "\x10\x05:path\x08/foo/bar" - "\x10\x07:scheme\x04http" - "\x10\x07:method\x04POST" - "\x10\x0a:authority\x09localhost" - "\x10\x0c" - "content-type\x10" - "application/grpc" - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" - "\x10\x02te\x0a" - "frobnicate" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", - GRPC_BAD_CLIENT_DISCONNECT); - - /* two path headers */ - GRPC_RUN_BAD_CLIENT_TEST( - verifier, NULL, PFX_STR - "\x00\x00\xd9\x01\x04\x00\x00\x00\x01" - "\x10\x05:path\x08/foo/bar" - "\x10\x05:path\x08/foo/bah" - "\x10\x07:scheme\x04http" - "\x10\x07:method\x04POST" - "\x10\x0a:authority\x09localhost" - "\x10\x0c" - "content-type\x10" - "application/grpc" - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" - "\x10\x02te\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", - GRPC_BAD_CLIENT_DISCONNECT); - - /* bad accept-encoding algorithm */ - GRPC_RUN_BAD_CLIENT_TEST( - verifier, NULL, PFX_STR - "\x00\x00\xd2\x01\x04\x00\x00\x00\x01" - "\x10\x05:path\x08/foo/bar" - "\x10\x07:scheme\x04http" - "\x10\x07:method\x04POST" - "\x10\x0a:authority\x09localhost" - "\x10\x0c" - "content-type\x10" - "application/grpc" - "\x10\x14grpc-accept-encoding\x1enobody-knows-the-trouble-i-see" - "\x10\x02te\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", - GRPC_BAD_CLIENT_DISCONNECT); - - /* bad grpc-encoding algorithm */ - GRPC_RUN_BAD_CLIENT_TEST( - verifier, NULL, PFX_STR - "\x00\x00\xf5\x01\x04\x00\x00\x00\x01" - "\x10\x05:path\x08/foo/bar" - "\x10\x07:scheme\x04http" - "\x10\x07:method\x04POST" - "\x10\x0a:authority\x09localhost" - "\x10\x0c" - "content-type\x10" - "application/grpc" - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" - "\x10\x0dgrpc-encoding\x1cyou-dont-know-how-to-do-this" - "\x10\x02te\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", - GRPC_BAD_CLIENT_DISCONNECT); - - return 0; -} diff --git a/test/core/bad_client/tests/badreq.cc b/test/core/bad_client/tests/badreq.cc new file mode 100644 index 0000000000..7d9a103e43 --- /dev/null +++ b/test/core/bad_client/tests/badreq.cc @@ -0,0 +1,125 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* invalid content type */ + GRPC_RUN_BAD_CLIENT_TEST( + verifier, NULL, PFX_STR + "\x00\x00\xc2\x01\x04\x00\x00\x00\x01" + "\x10\x05:path\x08/foo/bar" + "\x10\x07:scheme\x04http" + "\x10\x07:method\x04POST" + "\x10\x0a:authority\x09localhost" + "\x10\x0c" + "content-type\x09text/html" + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" + "\x10\x02te\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", + GRPC_BAD_CLIENT_DISCONNECT); + + /* invalid te */ + GRPC_RUN_BAD_CLIENT_TEST( + verifier, NULL, PFX_STR + "\x00\x00\xcb\x01\x04\x00\x00\x00\x01" + "\x10\x05:path\x08/foo/bar" + "\x10\x07:scheme\x04http" + "\x10\x07:method\x04POST" + "\x10\x0a:authority\x09localhost" + "\x10\x0c" + "content-type\x10" + "application/grpc" + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" + "\x10\x02te\x0a" + "frobnicate" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", + GRPC_BAD_CLIENT_DISCONNECT); + + /* two path headers */ + GRPC_RUN_BAD_CLIENT_TEST( + verifier, NULL, PFX_STR + "\x00\x00\xd9\x01\x04\x00\x00\x00\x01" + "\x10\x05:path\x08/foo/bar" + "\x10\x05:path\x08/foo/bah" + "\x10\x07:scheme\x04http" + "\x10\x07:method\x04POST" + "\x10\x0a:authority\x09localhost" + "\x10\x0c" + "content-type\x10" + "application/grpc" + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" + "\x10\x02te\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", + GRPC_BAD_CLIENT_DISCONNECT); + + /* bad accept-encoding algorithm */ + GRPC_RUN_BAD_CLIENT_TEST( + verifier, NULL, PFX_STR + "\x00\x00\xd2\x01\x04\x00\x00\x00\x01" + "\x10\x05:path\x08/foo/bar" + "\x10\x07:scheme\x04http" + "\x10\x07:method\x04POST" + "\x10\x0a:authority\x09localhost" + "\x10\x0c" + "content-type\x10" + "application/grpc" + "\x10\x14grpc-accept-encoding\x1enobody-knows-the-trouble-i-see" + "\x10\x02te\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", + GRPC_BAD_CLIENT_DISCONNECT); + + /* bad grpc-encoding algorithm */ + GRPC_RUN_BAD_CLIENT_TEST( + verifier, NULL, PFX_STR + "\x00\x00\xf5\x01\x04\x00\x00\x00\x01" + "\x10\x05:path\x08/foo/bar" + "\x10\x07:scheme\x04http" + "\x10\x07:method\x04POST" + "\x10\x0a:authority\x09localhost" + "\x10\x0c" + "content-type\x10" + "application/grpc" + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" + "\x10\x0dgrpc-encoding\x1cyou-dont-know-how-to-do-this" + "\x10\x02te\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/bad_client/tests/connection_prefix.c b/test/core/bad_client/tests/connection_prefix.c deleted file mode 100644 index 6cc4b72314..0000000000 --- a/test/core/bad_client/tests/connection_prefix.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRIX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI *X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTPX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\rX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\nX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\rX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSMX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\rX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\nX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\n\rX", - 0); - return 0; -} diff --git a/test/core/bad_client/tests/connection_prefix.cc b/test/core/bad_client/tests/connection_prefix.cc new file mode 100644 index 0000000000..6cc4b72314 --- /dev/null +++ b/test/core/bad_client/tests/connection_prefix.cc @@ -0,0 +1,60 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRIX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI *X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTPX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\rX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\nX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\rX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSMX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\rX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\nX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\n\rX", + 0); + return 0; +} diff --git a/test/core/bad_client/tests/head_of_line_blocking.c b/test/core/bad_client/tests/head_of_line_blocking.c deleted file mode 100644 index 04485d501f..0000000000 --- a/test/core/bad_client/tests/head_of_line_blocking.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -static const char prefix[] = - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" - // settings frame - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - // stream 1 headers: generated from server_registered_method.headers in this - // directory - "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" - "\x10\x05:path\x0f/registered/bar" - "\x10\x07:scheme\x04http" - "\x10\x07:method\x04POST" - "\x10\x0a:authority\x09localhost" - "\x10\x0c" - "content-type\x10" - "application/grpc" - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" - "\x10\x02te\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - // data frame for stream 1: advertise a 10000 byte payload (that we won't - // fulfill) - "\x00\x00\x05\x00\x00\x00\x00\x00\x01" - "\x01\x00\x00\x27\x10" - // stream 3 headers: generated from server_registered_method.headers in this - // directory - "\x00\x00\xd0\x01\x04\x00\x00\x00\x03" - "\x10\x05:path\x0f/registered/bar" - "\x10\x07:scheme\x04http" - "\x10\x07:method\x04POST" - "\x10\x0a:authority\x09localhost" - "\x10\x0c" - "content-type\x10" - "application/grpc" - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" - "\x10\x02te\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - // data frame for stream 3: advertise a 10000 byte payload (that we will - // fulfill) - "\x00\x00\x05\x00\x00\x00\x00\x00\x03" - "\x01\x00\x00\x27\x10" - ""; - -static void *tag(intptr_t t) { return (void *)t; } - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - gpr_timespec deadline; - grpc_byte_buffer *payload = NULL; - - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_registered_call(server, registered_method, &s, - &deadline, &request_metadata_recv, - &payload, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(payload != NULL); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_unref(s); - grpc_byte_buffer_destroy(payload); - cq_verifier_destroy(cqv); -} - -char *g_buffer; -size_t g_cap = 0; -size_t g_count = 0; - -static void addbuf(const void *data, size_t len) { - if (g_count + len > g_cap) { - g_cap = GPR_MAX(g_count + len, g_cap * 2); - g_buffer = gpr_realloc(g_buffer, g_cap); - } - memcpy(g_buffer + g_count, data, len); - g_count += len; -} - -int main(int argc, char **argv) { - int i; - grpc_test_init(argc, argv); - -#define NUM_FRAMES 10 -#define FRAME_SIZE 1000 - - addbuf(prefix, sizeof(prefix) - 1); - for (i = 0; i < NUM_FRAMES; i++) { - uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), - (uint8_t)(FRAME_SIZE >> 8), - (uint8_t)FRAME_SIZE, - 0, - 0, - 0, - 0, - 0, - 3}; - uint8_t msg[FRAME_SIZE]; - memset(msg, 'a', sizeof(msg)); - addbuf(hdr, sizeof(hdr)); - addbuf(msg, FRAME_SIZE); - } - grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, 0); - gpr_free(g_buffer); - - return 0; -} diff --git a/test/core/bad_client/tests/head_of_line_blocking.cc b/test/core/bad_client/tests/head_of_line_blocking.cc new file mode 100644 index 0000000000..cb89423907 --- /dev/null +++ b/test/core/bad_client/tests/head_of_line_blocking.cc @@ -0,0 +1,136 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +static const char prefix[] = + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" + // settings frame + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + // stream 1 headers: generated from server_registered_method.headers in this + // directory + "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" + "\x10\x05:path\x0f/registered/bar" + "\x10\x07:scheme\x04http" + "\x10\x07:method\x04POST" + "\x10\x0a:authority\x09localhost" + "\x10\x0c" + "content-type\x10" + "application/grpc" + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" + "\x10\x02te\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + // data frame for stream 1: advertise a 10000 byte payload (that we won't + // fulfill) + "\x00\x00\x05\x00\x00\x00\x00\x00\x01" + "\x01\x00\x00\x27\x10" + // stream 3 headers: generated from server_registered_method.headers in this + // directory + "\x00\x00\xd0\x01\x04\x00\x00\x00\x03" + "\x10\x05:path\x0f/registered/bar" + "\x10\x07:scheme\x04http" + "\x10\x07:method\x04POST" + "\x10\x0a:authority\x09localhost" + "\x10\x0c" + "content-type\x10" + "application/grpc" + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" + "\x10\x02te\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + // data frame for stream 3: advertise a 10000 byte payload (that we will + // fulfill) + "\x00\x00\x05\x00\x00\x00\x00\x00\x03" + "\x01\x00\x00\x27\x10" + ""; + +static void *tag(intptr_t t) { return (void *)t; } + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + gpr_timespec deadline; + grpc_byte_buffer *payload = NULL; + + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_registered_call(server, registered_method, &s, + &deadline, &request_metadata_recv, + &payload, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(payload != NULL); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_unref(s); + grpc_byte_buffer_destroy(payload); + cq_verifier_destroy(cqv); +} + +char *g_buffer; +size_t g_cap = 0; +size_t g_count = 0; + +static void addbuf(const void *data, size_t len) { + if (g_count + len > g_cap) { + g_cap = GPR_MAX(g_count + len, g_cap * 2); + g_buffer = static_cast(gpr_realloc(g_buffer, g_cap)); + } + memcpy(g_buffer + g_count, data, len); + g_count += len; +} + +int main(int argc, char **argv) { + int i; + grpc_test_init(argc, argv); + +#define NUM_FRAMES 10 +#define FRAME_SIZE 1000 + + addbuf(prefix, sizeof(prefix) - 1); + for (i = 0; i < NUM_FRAMES; i++) { + uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), + (uint8_t)(FRAME_SIZE >> 8), + (uint8_t)FRAME_SIZE, + 0, + 0, + 0, + 0, + 0, + 3}; + uint8_t msg[FRAME_SIZE]; + memset(msg, 'a', sizeof(msg)); + addbuf(hdr, sizeof(hdr)); + addbuf(msg, FRAME_SIZE); + } + grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, 0); + gpr_free(g_buffer); + + return 0; +} diff --git a/test/core/bad_client/tests/headers.c b/test/core/bad_client/tests/headers.c deleted file mode 100644 index c704dbbcb6..0000000000 --- a/test/core/bad_client/tests/headers.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* partial http2 header prefixes */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x05", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - - /* test adding prioritization data */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x24\x00\x00\x00\x01" - "\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x02\x01\x24\x00\x00\x00\x01" - "\x00\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - - /* test looking up an invalid index */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x04\x00\x00\x00\x01" - "\xfe", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x7f\x7f\x01" - "a", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x0f\x7f\x01" - "a", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x1f\x7f\x01" - "a", - 0); - /* test nvr, not indexed in static table */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x01\x01" - "a", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x11\x01" - "a", - GRPC_BAD_CLIENT_DISCONNECT); - /* illegal op code */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x04\x00\x00\x00\x01" - "\x80", - 0); - /* parse some long indices */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x02\x01\x04\x00\x00\x00\x01" - "\xff\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\xff\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x06\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x07\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x80\x00", - 0); - /* overflow on byte 4 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x06\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x7f", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x06\x01\x04\x00\x00\x00\x01" - "\xff\xff\xff\xff\xff\x0f", - GRPC_BAD_CLIENT_DISCONNECT); - /* overflow after byte 4 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x80\x02", - 0); - /* end of headers mid-opcode */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x04\x00\x00\x00\x01" - "\x01", - GRPC_BAD_CLIENT_DISCONNECT); - - /* dynamic table size update: set to default */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x3f\xe1\x1f", - GRPC_BAD_CLIENT_DISCONNECT); - /* dynamic table size update: set too large */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x3f\xf1\x1f", - 0); - /* dynamic table size update: set twice */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x20\x3f\xe1\x1f", - GRPC_BAD_CLIENT_DISCONNECT); - /* dynamic table size update: set thrice */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x20\x20\x20", - 0); - - /* non-ending header followed by continuation frame */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x00\x01\x00\x00\x00\x00\x01" - "\x00\x00\x00\x09\x04\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - /* non-ending header followed by non-continuation frame */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x00\x01\x00\x00\x00\x00\x01" - "\x00\x00\x00\x00\x04\x00\x00\x00\x01", - 0); - /* non-ending header followed by a continuation frame for a different stream - */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x00\x01\x04\x00\x00\x00\x01" - "\x00\x00\x00\x01\x00\x00\x00\x00\x03" - "\x00\x00\x00\x09\x04\x00\x00\x00\x01", - 0); - /* opening with a continuation frame */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x09\x04\x00\x00\x00\x01", 0); - /* three header frames */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x00\x01\x04\x00\x00\x00\x01" - "\x00\x00\x00\x01\x04\x00\x00\x00\x01" - "\x00\x00\x00\x01\x04\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - - /* an invalid header found with fuzzing */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x39\x67\xed\x1d\x64", - GRPC_BAD_CLIENT_DISCONNECT); - - /* a badly encoded timeout value */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x19\x01\x04\x00\x00\x00\x01" - "\x10\x0cgrpc-timeout\x0a" - "15 seconds", - GRPC_BAD_CLIENT_DISCONNECT); - /* a badly encoded timeout value: twice (catches caching) */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x19\x01\x04\x00\x00\x00\x01" - "\x10\x0cgrpc-timeout\x0a" - "15 seconds" - "\x00\x00\x19\x01\x04\x00\x00\x00\x03" - "\x10\x0cgrpc-timeout\x0a" - "15 seconds", - GRPC_BAD_CLIENT_DISCONNECT); - - return 0; -} diff --git a/test/core/bad_client/tests/headers.cc b/test/core/bad_client/tests/headers.cc new file mode 100644 index 0000000000..c704dbbcb6 --- /dev/null +++ b/test/core/bad_client/tests/headers.cc @@ -0,0 +1,293 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* partial http2 header prefixes */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x05", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + /* test adding prioritization data */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x24\x00\x00\x00\x01" + "\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x02\x01\x24\x00\x00\x00\x01" + "\x00\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + + /* test looking up an invalid index */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x04\x00\x00\x00\x01" + "\xfe", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x7f\x7f\x01" + "a", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x0f\x7f\x01" + "a", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x1f\x7f\x01" + "a", + 0); + /* test nvr, not indexed in static table */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x01\x01" + "a", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x11\x01" + "a", + GRPC_BAD_CLIENT_DISCONNECT); + /* illegal op code */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x04\x00\x00\x00\x01" + "\x80", + 0); + /* parse some long indices */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x02\x01\x04\x00\x00\x00\x01" + "\xff\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\xff\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x06\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x07\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x80\x00", + 0); + /* overflow on byte 4 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x06\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x7f", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x06\x01\x04\x00\x00\x00\x01" + "\xff\xff\xff\xff\xff\x0f", + GRPC_BAD_CLIENT_DISCONNECT); + /* overflow after byte 4 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x80\x02", + 0); + /* end of headers mid-opcode */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x04\x00\x00\x00\x01" + "\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + /* dynamic table size update: set to default */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x3f\xe1\x1f", + GRPC_BAD_CLIENT_DISCONNECT); + /* dynamic table size update: set too large */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x3f\xf1\x1f", + 0); + /* dynamic table size update: set twice */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x20\x3f\xe1\x1f", + GRPC_BAD_CLIENT_DISCONNECT); + /* dynamic table size update: set thrice */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x20\x20\x20", + 0); + + /* non-ending header followed by continuation frame */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x00\x01\x00\x00\x00\x00\x01" + "\x00\x00\x00\x09\x04\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + /* non-ending header followed by non-continuation frame */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x00\x01\x00\x00\x00\x00\x01" + "\x00\x00\x00\x00\x04\x00\x00\x00\x01", + 0); + /* non-ending header followed by a continuation frame for a different stream + */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x00\x01\x04\x00\x00\x00\x01" + "\x00\x00\x00\x01\x00\x00\x00\x00\x03" + "\x00\x00\x00\x09\x04\x00\x00\x00\x01", + 0); + /* opening with a continuation frame */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x09\x04\x00\x00\x00\x01", 0); + /* three header frames */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x00\x01\x04\x00\x00\x00\x01" + "\x00\x00\x00\x01\x04\x00\x00\x00\x01" + "\x00\x00\x00\x01\x04\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + /* an invalid header found with fuzzing */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x39\x67\xed\x1d\x64", + GRPC_BAD_CLIENT_DISCONNECT); + + /* a badly encoded timeout value */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x19\x01\x04\x00\x00\x00\x01" + "\x10\x0cgrpc-timeout\x0a" + "15 seconds", + GRPC_BAD_CLIENT_DISCONNECT); + /* a badly encoded timeout value: twice (catches caching) */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x19\x01\x04\x00\x00\x00\x01" + "\x10\x0cgrpc-timeout\x0a" + "15 seconds" + "\x00\x00\x19\x01\x04\x00\x00\x00\x03" + "\x10\x0cgrpc-timeout\x0a" + "15 seconds", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/bad_client/tests/initial_settings_frame.c b/test/core/bad_client/tests/initial_settings_frame.c deleted file mode 100644 index 0696ef9383..0000000000 --- a/test/core/bad_client/tests/initial_settings_frame.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -#define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" -#define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* various partial prefixes */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x06", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x06", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x06", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\xff", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - /* must not send frames with stream id != 0 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0); - /* settings frame must be a multiple of six bytes long */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0); - /* some settings values are illegal */ - /* max frame size = 0 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff", - GRPC_BAD_CLIENT_DISCONNECT); - /* update intiial window size */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - /* ack with data */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - "\x00\x00\x01\x04\x01\x00\x00\x00\x00", - 0); - /* settings frame with invalid flags */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0); - /* unknown settings should be ignored */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - - return 0; -} diff --git a/test/core/bad_client/tests/initial_settings_frame.cc b/test/core/bad_client/tests/initial_settings_frame.cc new file mode 100644 index 0000000000..0696ef9383 --- /dev/null +++ b/test/core/bad_client/tests/initial_settings_frame.cc @@ -0,0 +1,108 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +#define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" +#define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* various partial prefixes */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x06", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x06", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x06", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\xff", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + /* must not send frames with stream id != 0 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0); + /* settings frame must be a multiple of six bytes long */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0); + /* some settings values are illegal */ + /* max frame size = 0 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff", + GRPC_BAD_CLIENT_DISCONNECT); + /* update intiial window size */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + /* ack with data */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + "\x00\x00\x01\x04\x01\x00\x00\x00\x00", + 0); + /* settings frame with invalid flags */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0); + /* unknown settings should be ignored */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c deleted file mode 100644 index ca3d234be9..0000000000 --- a/test/core/bad_client/tests/large_metadata.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include -#include -#include "src/core/lib/support/string.h" -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -// The large-metadata headers that we're adding for this test are not -// actually appended to this in a single string, since the string would -// be longer than the C99 string literal limit. Instead, we dynamically -// construct it by adding the large headers one at a time. - -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame */ \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* headers: generated from \ - large_metadata.headers in this \ - directory */ \ - "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ - "\x00" \ - "5{\x01\x05\x00\x00\x00\x01" \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x0a:authority\x09localhost" \ - "\x10\x0c" \ - "content-type\x10" \ - "application/grpc" \ - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -// Each large-metadata header is constructed from these start and end -// strings, with a two-digit number in between. -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR "\x10\x0duser-header" -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR \ - "~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - -// The size of each large-metadata header string. -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE \ - ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR) - 1) + 2 + \ - (sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR) - 1)) - -// The number of headers we're adding and the total size of the client -// payload. -#define NUM_HEADERS 46 -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE \ - ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1) + \ - (NUM_HEADERS * PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE) + 1) - -#define PFX_TOO_MUCH_METADATA_FROM_SERVER_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame: sets \ - MAX_HEADER_LIST_SIZE to 8K */ \ - "\x00\x00\x06\x04\x00\x00\x00\x00\x00\x00\x06\x00\x00\x20\x00" /* headers: \ - generated \ - from \ - simple_request.headers \ - in this \ - directory \ - */ \ - "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ - "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x0a:authority\x09localhost" \ - "\x10\x0c" \ - "content-type\x10" \ - "application/grpc" \ - "\x10\x14grpc-accept-encoding\x15" \ - "deflate,identity,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -static void *tag(intptr_t t) { return (void *)t; } - -static void server_verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - grpc_call_details call_details; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - - grpc_call_details_init(&call_details); - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_details_destroy(&call_details); - grpc_call_unref(s); - cq_verifier_destroy(cqv); -} - -static void server_verifier_sends_too_much_metadata(grpc_server *server, - grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - grpc_call_details call_details; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - - grpc_call_details_init(&call_details); - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); - - const size_t metadata_value_size = 8 * 1024; - grpc_metadata meta; - meta.key = grpc_slice_from_static_string("key"); - meta.value = grpc_slice_malloc(metadata_value_size); - memset(GRPC_SLICE_START_PTR(meta.value), 'a', metadata_value_size); - - grpc_op op; - memset(&op, 0, sizeof(op)); - op.op = GRPC_OP_SEND_INITIAL_METADATA; - op.data.send_initial_metadata.count = 1; - op.data.send_initial_metadata.metadata = &meta; - op.flags = 0; - op.reserved = NULL; - error = grpc_call_start_batch(s, &op, 1, tag(102), NULL); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails. - cq_verify(cqv); - - grpc_slice_unref(meta.value); - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_details_destroy(&call_details); - grpc_call_unref(s); - cq_verifier_destroy(cqv); -} - -static bool client_validator(grpc_slice_buffer *incoming) { - for (size_t i = 0; i < incoming->count; ++i) { - const char *s = (const char *)GRPC_SLICE_START_PTR(incoming->slices[i]); - char *hex = gpr_dump(s, GRPC_SLICE_LENGTH(incoming->slices[i]), - GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "RESPONSE SLICE %" PRIdPTR ": %s", i, hex); - gpr_free(hex); - } - - // Get last frame from incoming slice buffer. - grpc_slice_buffer last_frame_buffer; - grpc_slice_buffer_init(&last_frame_buffer); - grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer); - GPR_ASSERT(last_frame_buffer.count == 1); - grpc_slice last_frame = last_frame_buffer.slices[0]; - - const uint8_t *p = GRPC_SLICE_START_PTR(last_frame); - bool success = - // Length == 4 - *p++ != 0 || *p++ != 0 || *p++ != 4 || - // Frame type (RST_STREAM) - *p++ != 3 || - // Flags - *p++ != 0 || - // Stream ID. - *p++ != 0 || *p++ != 0 || *p++ != 0 || *p++ != 1 || - // Payload (error code) - *p++ == 0 || *p++ == 0 || *p++ == 0 || *p == 0 || *p == 11; - - if (!success) { - gpr_log(GPR_INFO, "client expected RST_STREAM frame, not found"); - } - - grpc_slice_buffer_destroy(&last_frame_buffer); - return success; -} - -int main(int argc, char **argv) { - int i; - - grpc_test_init(argc, argv); - - // Test sending more metadata than the server will accept. - gpr_strvec headers; - gpr_strvec_init(&headers); - for (i = 0; i < NUM_HEADERS; ++i) { - char *str; - gpr_asprintf(&str, "%s%02d%s", - PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR, i, - PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR); - gpr_strvec_add(&headers, str); - } - size_t headers_len; - const char *client_headers = gpr_strvec_flatten(&headers, &headers_len); - gpr_strvec_destroy(&headers); - char client_payload[PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE] = - PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR; - memcpy( - client_payload + sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1, - client_headers, headers_len); - GRPC_RUN_BAD_CLIENT_TEST(server_verifier, client_validator, client_payload, - 0); - gpr_free((void *)client_headers); - - // Test sending more metadata than the client will accept. - GRPC_RUN_BAD_CLIENT_TEST(server_verifier_sends_too_much_metadata, - client_validator, - PFX_TOO_MUCH_METADATA_FROM_SERVER_STR, 0); - - return 0; -} diff --git a/test/core/bad_client/tests/large_metadata.cc b/test/core/bad_client/tests/large_metadata.cc new file mode 100644 index 0000000000..ca3d234be9 --- /dev/null +++ b/test/core/bad_client/tests/large_metadata.cc @@ -0,0 +1,240 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include +#include +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +// The large-metadata headers that we're adding for this test are not +// actually appended to this in a single string, since the string would +// be longer than the C99 string literal limit. Instead, we dynamically +// construct it by adding the large headers one at a time. + +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame */ \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* headers: generated from \ + large_metadata.headers in this \ + directory */ \ + "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ + "\x00" \ + "5{\x01\x05\x00\x00\x00\x01" \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x0a:authority\x09localhost" \ + "\x10\x0c" \ + "content-type\x10" \ + "application/grpc" \ + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +// Each large-metadata header is constructed from these start and end +// strings, with a two-digit number in between. +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR "\x10\x0duser-header" +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR \ + "~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +// The size of each large-metadata header string. +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE \ + ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR) - 1) + 2 + \ + (sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR) - 1)) + +// The number of headers we're adding and the total size of the client +// payload. +#define NUM_HEADERS 46 +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE \ + ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1) + \ + (NUM_HEADERS * PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE) + 1) + +#define PFX_TOO_MUCH_METADATA_FROM_SERVER_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame: sets \ + MAX_HEADER_LIST_SIZE to 8K */ \ + "\x00\x00\x06\x04\x00\x00\x00\x00\x00\x00\x06\x00\x00\x20\x00" /* headers: \ + generated \ + from \ + simple_request.headers \ + in this \ + directory \ + */ \ + "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ + "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x0a:authority\x09localhost" \ + "\x10\x0c" \ + "content-type\x10" \ + "application/grpc" \ + "\x10\x14grpc-accept-encoding\x15" \ + "deflate,identity,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +static void *tag(intptr_t t) { return (void *)t; } + +static void server_verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + grpc_call_details call_details; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + + grpc_call_details_init(&call_details); + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_call(server, &s, &call_details, + &request_metadata_recv, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + grpc_call_unref(s); + cq_verifier_destroy(cqv); +} + +static void server_verifier_sends_too_much_metadata(grpc_server *server, + grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + grpc_call_details call_details; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + + grpc_call_details_init(&call_details); + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_call(server, &s, &call_details, + &request_metadata_recv, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + + const size_t metadata_value_size = 8 * 1024; + grpc_metadata meta; + meta.key = grpc_slice_from_static_string("key"); + meta.value = grpc_slice_malloc(metadata_value_size); + memset(GRPC_SLICE_START_PTR(meta.value), 'a', metadata_value_size); + + grpc_op op; + memset(&op, 0, sizeof(op)); + op.op = GRPC_OP_SEND_INITIAL_METADATA; + op.data.send_initial_metadata.count = 1; + op.data.send_initial_metadata.metadata = &meta; + op.flags = 0; + op.reserved = NULL; + error = grpc_call_start_batch(s, &op, 1, tag(102), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails. + cq_verify(cqv); + + grpc_slice_unref(meta.value); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + grpc_call_unref(s); + cq_verifier_destroy(cqv); +} + +static bool client_validator(grpc_slice_buffer *incoming) { + for (size_t i = 0; i < incoming->count; ++i) { + const char *s = (const char *)GRPC_SLICE_START_PTR(incoming->slices[i]); + char *hex = gpr_dump(s, GRPC_SLICE_LENGTH(incoming->slices[i]), + GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "RESPONSE SLICE %" PRIdPTR ": %s", i, hex); + gpr_free(hex); + } + + // Get last frame from incoming slice buffer. + grpc_slice_buffer last_frame_buffer; + grpc_slice_buffer_init(&last_frame_buffer); + grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer); + GPR_ASSERT(last_frame_buffer.count == 1); + grpc_slice last_frame = last_frame_buffer.slices[0]; + + const uint8_t *p = GRPC_SLICE_START_PTR(last_frame); + bool success = + // Length == 4 + *p++ != 0 || *p++ != 0 || *p++ != 4 || + // Frame type (RST_STREAM) + *p++ != 3 || + // Flags + *p++ != 0 || + // Stream ID. + *p++ != 0 || *p++ != 0 || *p++ != 0 || *p++ != 1 || + // Payload (error code) + *p++ == 0 || *p++ == 0 || *p++ == 0 || *p == 0 || *p == 11; + + if (!success) { + gpr_log(GPR_INFO, "client expected RST_STREAM frame, not found"); + } + + grpc_slice_buffer_destroy(&last_frame_buffer); + return success; +} + +int main(int argc, char **argv) { + int i; + + grpc_test_init(argc, argv); + + // Test sending more metadata than the server will accept. + gpr_strvec headers; + gpr_strvec_init(&headers); + for (i = 0; i < NUM_HEADERS; ++i) { + char *str; + gpr_asprintf(&str, "%s%02d%s", + PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR, i, + PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR); + gpr_strvec_add(&headers, str); + } + size_t headers_len; + const char *client_headers = gpr_strvec_flatten(&headers, &headers_len); + gpr_strvec_destroy(&headers); + char client_payload[PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE] = + PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR; + memcpy( + client_payload + sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1, + client_headers, headers_len); + GRPC_RUN_BAD_CLIENT_TEST(server_verifier, client_validator, client_payload, + 0); + gpr_free((void *)client_headers); + + // Test sending more metadata than the client will accept. + GRPC_RUN_BAD_CLIENT_TEST(server_verifier_sends_too_much_metadata, + client_validator, + PFX_TOO_MUCH_METADATA_FROM_SERVER_STR, 0); + + return 0; +} diff --git a/test/core/bad_client/tests/server_registered_method.c b/test/core/bad_client/tests/server_registered_method.c deleted file mode 100644 index f52350302b..0000000000 --- a/test/core/bad_client/tests/server_registered_method.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" \ - "\x10\x05:path\x0f/registered/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x0a:authority\x09localhost" \ - "\x10\x0c" \ - "content-type\x10" \ - "application/grpc" \ - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -static void *tag(intptr_t t) { return (void *)t; } - -static void verifier_succeeds(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - gpr_timespec deadline; - grpc_byte_buffer *payload = NULL; - - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_registered_call(server, registered_method, &s, - &deadline, &request_metadata_recv, - &payload, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(payload != NULL); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_unref(s); - grpc_byte_buffer_destroy(payload); - cq_verifier_destroy(cqv); -} - -static void verifier_fails(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* body generated with - * tools/codegen/core/gen_server_registered_method_bad_client_test_body.py */ - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, - PFX_STR "\x00\x00\x00\x00\x00\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, - PFX_STR "\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR - "\x00\x00\x02\x00\x00\x00\x00\x00\x01\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR - "\x00\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_succeeds, NULL, - PFX_STR "\x00\x00\x05\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_succeeds, NULL, - PFX_STR "\x00\x00\x06\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x06\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_succeeds, NULL, PFX_STR - "\x00\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00", - 0); - - return 0; -} diff --git a/test/core/bad_client/tests/server_registered_method.cc b/test/core/bad_client/tests/server_registered_method.cc new file mode 100644 index 0000000000..f52350302b --- /dev/null +++ b/test/core/bad_client/tests/server_registered_method.cc @@ -0,0 +1,124 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" \ + "\x10\x05:path\x0f/registered/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x0a:authority\x09localhost" \ + "\x10\x0c" \ + "content-type\x10" \ + "application/grpc" \ + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +static void *tag(intptr_t t) { return (void *)t; } + +static void verifier_succeeds(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + gpr_timespec deadline; + grpc_byte_buffer *payload = NULL; + + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_registered_call(server, registered_method, &s, + &deadline, &request_metadata_recv, + &payload, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(payload != NULL); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_unref(s); + grpc_byte_buffer_destroy(payload); + cq_verifier_destroy(cqv); +} + +static void verifier_fails(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* body generated with + * tools/codegen/core/gen_server_registered_method_bad_client_test_body.py */ + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, + PFX_STR "\x00\x00\x00\x00\x00\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, + PFX_STR "\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR + "\x00\x00\x02\x00\x00\x00\x00\x00\x01\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR + "\x00\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_succeeds, NULL, + PFX_STR "\x00\x00\x05\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_succeeds, NULL, + PFX_STR "\x00\x00\x06\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x06\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_succeeds, NULL, PFX_STR + "\x00\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00", + 0); + + return 0; +} diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c deleted file mode 100644 index a516632819..0000000000 --- a/test/core/bad_client/tests/simple_request.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request.headers in this \ - directory */ \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x0a:authority\x09localhost" \ - "\x10\x0c" \ - "content-type\x10" \ - "application/grpc" \ - "\x10\x14grpc-accept-encoding\x15" \ - "deflate,identity,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -#define PFX_STR_UNUSUAL \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request_unusual.headers \ - in this directory */ \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x04host\x09localhost" \ - "\x10\x0c" \ - "content-type\x1e" \ - "application/grpc+this-is-valid" \ - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \ - "\x10\x0cgrpc-timeout\x03" \ - "10S" \ - "\x10\x0cgrpc-timeout\x02" \ - "5S" - -#define PFX_STR_UNUSUAL2 \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request_unusual2.headers \ - in this directory */ \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x04host\x09localhost" \ - "\x10\x0c" \ - "content-type\x1e" \ - "application/grpc;this-is-valid" \ - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \ - "\x10\x0cgrpc-timeout\x03" \ - "10S" \ - "\x10\x0cgrpc-timeout\x02" \ - "5S" - -static void *tag(intptr_t t) { return (void *)t; } - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - grpc_call_details call_details; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - - grpc_call_details_init(&call_details); - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_details_destroy(&call_details); - grpc_call_unref(s); - cq_verifier_destroy(cqv); -} - -static void failure_verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* basic request: check that things are working */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR, 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL, 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL2, 0); - - /* push an illegal data frame */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x00\x00\x00\x00\x00\x01" - "\x34\x00\x00\x00\x00", - 0); - - /* push a data frame with bad flags */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x00\x02\x00\x00\x00\x01", 0); - /* push a window update with a bad length */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x01\x08\x00\x00\x00\x00\x01", 0); - /* push a window update with bad flags */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x00\x08\x10\x00\x00\x00\x01", 0); - /* push a window update with bad data */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, PFX_STR - "\x00\x00\x04\x08\x00\x00\x00\x00\x01" - "\xff\xff\xff\xff", - 0); - /* push a short goaway */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0); - /* disconnect before sending goaway */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x01\x12\x07\x00\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - /* push a rst_stream with a bad length */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x01\x03\x00\x00\x00\x00\x01", 0); - /* push a rst_stream with bad flags */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0); - - return 0; -} diff --git a/test/core/bad_client/tests/simple_request.cc b/test/core/bad_client/tests/simple_request.cc new file mode 100644 index 0000000000..a516632819 --- /dev/null +++ b/test/core/bad_client/tests/simple_request.cc @@ -0,0 +1,166 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request.headers in this \ + directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x0a:authority\x09localhost" \ + "\x10\x0c" \ + "content-type\x10" \ + "application/grpc" \ + "\x10\x14grpc-accept-encoding\x15" \ + "deflate,identity,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +#define PFX_STR_UNUSUAL \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request_unusual.headers \ + in this directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x04host\x09localhost" \ + "\x10\x0c" \ + "content-type\x1e" \ + "application/grpc+this-is-valid" \ + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \ + "\x10\x0cgrpc-timeout\x03" \ + "10S" \ + "\x10\x0cgrpc-timeout\x02" \ + "5S" + +#define PFX_STR_UNUSUAL2 \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request_unusual2.headers \ + in this directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x04host\x09localhost" \ + "\x10\x0c" \ + "content-type\x1e" \ + "application/grpc;this-is-valid" \ + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \ + "\x10\x0cgrpc-timeout\x03" \ + "10S" \ + "\x10\x0cgrpc-timeout\x02" \ + "5S" + +static void *tag(intptr_t t) { return (void *)t; } + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + grpc_call_details call_details; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + + grpc_call_details_init(&call_details); + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_call(server, &s, &call_details, + &request_metadata_recv, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + grpc_call_unref(s); + cq_verifier_destroy(cqv); +} + +static void failure_verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* basic request: check that things are working */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR, 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL, 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL2, 0); + + /* push an illegal data frame */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x00\x00\x00\x00\x00\x01" + "\x34\x00\x00\x00\x00", + 0); + + /* push a data frame with bad flags */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x00\x02\x00\x00\x00\x01", 0); + /* push a window update with a bad length */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x01\x08\x00\x00\x00\x00\x01", 0); + /* push a window update with bad flags */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x00\x08\x10\x00\x00\x00\x01", 0); + /* push a window update with bad data */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, PFX_STR + "\x00\x00\x04\x08\x00\x00\x00\x00\x01" + "\xff\xff\xff\xff", + 0); + /* push a short goaway */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0); + /* disconnect before sending goaway */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x01\x12\x07\x00\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + /* push a rst_stream with a bad length */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x01\x03\x00\x00\x00\x00\x01", 0); + /* push a rst_stream with bad flags */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0); + + return 0; +} diff --git a/test/core/bad_client/tests/unknown_frame.c b/test/core/bad_client/tests/unknown_frame.c deleted file mode 100644 index 448803d12b..0000000000 --- a/test/core/bad_client/tests/unknown_frame.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* test adding prioritization data */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - - return 0; -} diff --git a/test/core/bad_client/tests/unknown_frame.cc b/test/core/bad_client/tests/unknown_frame.cc new file mode 100644 index 0000000000..448803d12b --- /dev/null +++ b/test/core/bad_client/tests/unknown_frame.cc @@ -0,0 +1,44 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* test adding prioritization data */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/bad_client/tests/window_overflow.c b/test/core/bad_client/tests/window_overflow.c deleted file mode 100644 index e4b5f9711b..0000000000 --- a/test/core/bad_client/tests/window_overflow.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include - -#include "src/core/lib/surface/server.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request.headers in this \ - directory */ \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x0a:authority\x09localhost" \ - "\x10\x0c" \ - "content-type\x10" \ - "application/grpc" \ - "\x10\x14grpc-accept-encoding\x15" \ - "deflate,identity,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -char *g_buffer; -size_t g_cap = 0; -size_t g_count = 0; - -static void addbuf(const void *data, size_t len) { - if (g_count + len > g_cap) { - g_cap = GPR_MAX(g_count + len, g_cap * 2); - g_buffer = gpr_realloc(g_buffer, g_cap); - } - memcpy(g_buffer + g_count, data, len); - g_count += len; -} - -int main(int argc, char **argv) { - int i, j; -#define MAX_FRAME_SIZE 16384 -#define MESSAGES_PER_FRAME (MAX_FRAME_SIZE / 5) -#define FRAME_SIZE (MESSAGES_PER_FRAME * 5) -#define SEND_SIZE (6 * 1024 * 1024) -#define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) - grpc_test_init(argc, argv); - - addbuf(PFX_STR, sizeof(PFX_STR) - 1); - for (i = 0; i < NUM_FRAMES; i++) { - uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), - (uint8_t)(FRAME_SIZE >> 8), - (uint8_t)FRAME_SIZE, - 0, - 0, - 0, - 0, - 0, - 1}; - addbuf(hdr, sizeof(hdr)); - for (j = 0; j < MESSAGES_PER_FRAME; j++) { - uint8_t message[5] = {0, 0, 0, 0, 0}; - addbuf(message, sizeof(message)); - } - } - grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, - GRPC_BAD_CLIENT_LARGE_REQUEST); - gpr_free(g_buffer); - - return 0; -} diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc new file mode 100644 index 0000000000..40552e5345 --- /dev/null +++ b/test/core/bad_client/tests/window_overflow.cc @@ -0,0 +1,98 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include + +#include "src/core/lib/surface/server.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request.headers in this \ + directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x0a:authority\x09localhost" \ + "\x10\x0c" \ + "content-type\x10" \ + "application/grpc" \ + "\x10\x14grpc-accept-encoding\x15" \ + "deflate,identity,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +char *g_buffer; +size_t g_cap = 0; +size_t g_count = 0; + +static void addbuf(const void *data, size_t len) { + if (g_count + len > g_cap) { + g_cap = GPR_MAX(g_count + len, g_cap * 2); + g_buffer = static_cast(gpr_realloc(g_buffer, g_cap)); + } + memcpy(g_buffer + g_count, data, len); + g_count += len; +} + +int main(int argc, char **argv) { + int i, j; +#define MAX_FRAME_SIZE 16384 +#define MESSAGES_PER_FRAME (MAX_FRAME_SIZE / 5) +#define FRAME_SIZE (MESSAGES_PER_FRAME * 5) +#define SEND_SIZE (6 * 1024 * 1024) +#define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) + grpc_test_init(argc, argv); + + addbuf(PFX_STR, sizeof(PFX_STR) - 1); + for (i = 0; i < NUM_FRAMES; i++) { + uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), + (uint8_t)(FRAME_SIZE >> 8), + (uint8_t)FRAME_SIZE, + 0, + 0, + 0, + 0, + 0, + 1}; + addbuf(hdr, sizeof(hdr)); + for (j = 0; j < MESSAGES_PER_FRAME; j++) { + uint8_t message[5] = {0, 0, 0, 0, 0}; + addbuf(message, sizeof(message)); + } + } + grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, + GRPC_BAD_CLIENT_LARGE_REQUEST); + gpr_free(g_buffer); + + return 0; +} -- cgit v1.2.3