bad_streaming_id.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2019 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <string>
20 
21 #include <gtest/gtest.h>
22 
24 
27 
28 #define HEADER_FRAME_ID_1 \
29  "\x00\x00\xc9\x01\x05\x00\x00\x00\x01" /* headers: generated from \
30  simple_request.headers in this \
31  directory */ \
32  "\x10\x05:path\x08/foo/bar" \
33  "\x10\x07:scheme\x04http" \
34  "\x10\x07:method\x04POST" \
35  "\x10\x0a:authority\x09localhost" \
36  "\x10\x0c" \
37  "content-type\x10" \
38  "application/grpc" \
39  "\x10\x14grpc-accept-encoding\x15" \
40  "deflate,identity,gzip" \
41  "\x10\x02te\x08trailers" \
42  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
43 
44 #define HEADER_FRAME_ID_2 \
45  "\x00\x00\xc9\x01\x05\x00\x00\x00\x02" /* headers: generated from \
46  simple_request.headers in this \
47  directory */ \
48  "\x10\x05:path\x08/foo/bar" \
49  "\x10\x07:scheme\x04http" \
50  "\x10\x07:method\x04POST" \
51  "\x10\x0a:authority\x09localhost" \
52  "\x10\x0c" \
53  "content-type\x10" \
54  "application/grpc" \
55  "\x10\x14grpc-accept-encoding\x15" \
56  "deflate,identity,gzip" \
57  "\x10\x02te\x08trailers" \
58  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
59 
60 #define HEADER_FRAME_ID_3 \
61  "\x00\x00\xc9\x01\x05\x00\x00\x00\x03" /* headers: generated from \
62  simple_request.headers in this \
63  directory */ \
64  "\x10\x05:path\x08/foo/bar" \
65  "\x10\x07:scheme\x04http" \
66  "\x10\x07:method\x04POST" \
67  "\x10\x0a:authority\x09localhost" \
68  "\x10\x0c" \
69  "content-type\x10" \
70  "application/grpc" \
71  "\x10\x14grpc-accept-encoding\x15" \
72  "deflate,identity,gzip" \
73  "\x10\x02te\x08trailers" \
74  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
75 
76 namespace {
77 
79  void* /*registered_method*/) {
80  while (grpc_core::Server::FromC(server)->HasOpenConnections()) {
84  }
85 }
86 
87 TEST(BadStreamingId, RegularHeader) {
90  args[1].client_validator = nullptr;
91  args[1].client_payload = HEADER_FRAME_ID_1;
92  args[1].client_payload_length = sizeof(HEADER_FRAME_ID_1) - 1;
94 }
95 
96 TEST(BadStreamingId, NonClientStreamId) {
99  // send a header frame with non-client stream id 2
100  args[1].client_validator = nullptr;
101  args[1].client_payload = HEADER_FRAME_ID_2;
102  args[1].client_payload_length = sizeof(HEADER_FRAME_ID_2) - 1;
104 }
105 
106 TEST(BadStreamingId, ClosedStreamId) {
109  // send a header frame with stream id 1
110  args[1].client_validator = nullptr;
111  args[1].client_payload = HEADER_FRAME_ID_1;
112  args[1].client_payload_length = sizeof(HEADER_FRAME_ID_1) - 1;
113  // send a header frame with stream id 3
114  args[2].client_validator = nullptr;
115  args[2].client_payload = HEADER_FRAME_ID_3;
116  args[2].client_payload_length = sizeof(HEADER_FRAME_ID_3) - 1;
117  // send a header frame with closed stream id 1 again
118  args[3].client_validator = nullptr;
119  args[3].client_payload = HEADER_FRAME_ID_1;
120  args[3].client_payload_length = sizeof(HEADER_FRAME_ID_1) - 1;
122 }
123 
124 } // namespace
125 
126 int main(int argc, char** argv) {
127  grpc::testing::TestEnvironment env(&argc, argv);
128  ::testing::InitGoogleTest(&argc, argv);
129  grpc_init();
130  int retval = RUN_ALL_TESTS();
131  grpc_shutdown();
132  return retval;
133 }
generate.env
env
Definition: generate.py:37
HEADER_FRAME_ID_3
#define HEADER_FRAME_ID_3
Definition: bad_streaming_id.cc:56
verifier
static void verifier(grpc_server *server, grpc_completion_queue *cq, void *)
Definition: badreq.cc:31
string_util.h
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
TEST
#define TEST(name, init_size,...)
Definition: arena_test.cc:75
grpc_timeout_milliseconds_to_deadline
gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms)
Definition: test/core/util/test_config.cc:89
grpc_completion_queue
Definition: completion_queue.cc:347
HEADER_FRAME_ID_2
#define HEADER_FRAME_ID_2
Definition: bad_streaming_id.cc:42
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
HEADER_FRAME_ID_1
#define HEADER_FRAME_ID_1
Definition: bad_streaming_id.cc:28
GRPC_BAD_CLIENT_DISCONNECT
#define GRPC_BAD_CLIENT_DISCONNECT
Definition: bad_client.h:48
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
server
Definition: examples/python/async_streaming/server.py:1
grpc_run_bad_client_test
void grpc_run_bad_client_test(grpc_bad_client_server_side_validator server_validator, grpc_bad_client_arg args[], int num_args, uint32_t flags)
Definition: bad_client.cc:193
grpc_bad_client_arg
Definition: bad_client.h:40
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_completion_queue_next
GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, gpr_timespec deadline, void *reserved)
Definition: completion_queue.cc:1133
server.h
main
int main(int argc, char **argv)
Definition: bad_streaming_id.cc:120
connection_preface_arg
grpc_bad_client_arg connection_preface_arg
Definition: bad_client.cc:282
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_core::CppImplOf< Server, grpc_server >::FromC
static Server * FromC(grpc_server *c_type)
Definition: cpp_impl_of.h:30
GRPC_QUEUE_TIMEOUT
@ GRPC_QUEUE_TIMEOUT
Definition: grpc_types.h:556
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
bad_client.h
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:45