bad_client/tests/simple_request.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <string.h>
20 
21 #include <grpc/grpc.h>
22 
26 
27 #define PFX_STR \
28  "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
29  "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \
30  "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \
31  simple_request.headers in this \
32  directory */ \
33  "\x10\x05:path\x08/foo/bar" \
34  "\x10\x07:scheme\x04http" \
35  "\x10\x07:method\x04POST" \
36  "\x10\x0a:authority\x09localhost" \
37  "\x10\x0c" \
38  "content-type\x10" \
39  "application/grpc" \
40  "\x10\x14grpc-accept-encoding\x15" \
41  "deflate,identity,gzip" \
42  "\x10\x02te\x08trailers" \
43  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
44 
45 #define PFX_STR_UNUSUAL \
46  "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
47  "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \
48  "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \
49  simple_request_unusual.headers \
50  in this directory */ \
51  "\x10\x05:path\x08/foo/bar" \
52  "\x10\x07:scheme\x04http" \
53  "\x10\x07:method\x04POST" \
54  "\x10\x04host\x09localhost" \
55  "\x10\x0c" \
56  "content-type\x1e" \
57  "application/grpc+this-is-valid" \
58  "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \
59  "\x10\x02te\x08trailers" \
60  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \
61  "\x10\x0cgrpc-timeout\x03" \
62  "10S" \
63  "\x10\x0cgrpc-timeout\x02" \
64  "5S"
65 
66 #define PFX_STR_UNUSUAL2 \
67  "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
68  "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \
69  "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \
70  simple_request_unusual2.headers \
71  in this directory */ \
72  "\x10\x05:path\x08/foo/bar" \
73  "\x10\x07:scheme\x04http" \
74  "\x10\x07:method\x04POST" \
75  "\x10\x04host\x09localhost" \
76  "\x10\x0c" \
77  "content-type\x1e" \
78  "application/grpc;this-is-valid" \
79  "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \
80  "\x10\x02te\x08trailers" \
81  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \
82  "\x10\x0cgrpc-timeout\x03" \
83  "10S" \
84  "\x10\x0cgrpc-timeout\x02" \
85  "5S"
86 
87 static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
88 
90  void* /*registered_method*/) {
92  grpc_call* s;
96 
99 
101  &request_metadata_recv, cq, cq, tag(101));
103  CQ_EXPECT_COMPLETION(cqv, tag(101), 1);
104  cq_verify(cqv);
105 
106  GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost"));
108 
111  grpc_call_unref(s);
112  cq_verifier_destroy(cqv);
113 }
114 
116  void* /*registered_method*/) {
117  while (grpc_core::Server::FromC(server)->HasOpenConnections()) {
121  }
122 }
123 
124 int main(int argc, char** argv) {
125  grpc::testing::TestEnvironment env(&argc, argv);
126  grpc_init();
127 
128  /* basic request: check that things are working */
132 
133  /* push an illegal data frame */
135  PFX_STR
136  "\x00\x00\x05\x00\x00\x00\x00\x00\x01"
137  "\x34\x00\x00\x00\x00",
138  0);
139 
140  /* push a data frame with bad flags */
142  PFX_STR "\x00\x00\x00\x00\x02\x00\x00\x00\x01", 0);
143  /* push a window update with a bad length */
145  PFX_STR "\x00\x00\x01\x08\x00\x00\x00\x00\x01", 0);
146  /* push a window update with bad flags */
148  PFX_STR "\x00\x00\x00\x08\x10\x00\x00\x00\x01", 0);
149  /* push a window update with bad data (0 is not legal window size increment)
150  */
152  PFX_STR
153  "\x00\x00\x04\x08\x00\x00\x00\x00\x01"
154  "\x00\x00\x00\x00",
155  0);
156  /* push a short goaway */
158  PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0);
159  /* disconnect before sending goaway */
161  PFX_STR "\x00\x01\x12\x07\x00\x00\x00\x00\x00",
163  /* push a rst_stream with a bad length */
165  PFX_STR "\x00\x00\x01\x03\x00\x00\x00\x00\x01", 0);
166  /* push a rst_stream with bad flags */
168  PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0);
169 
170  grpc_shutdown();
171  return 0;
172 }
grpc_call_error
grpc_call_error
Definition: grpc_types.h:464
grpc_call_details_destroy
GRPCAPI void grpc_call_details_destroy(grpc_call_details *details)
Definition: call_details.cc:36
grpc_call_details_init
GRPCAPI void grpc_call_details_init(grpc_call_details *details)
Definition: call_details.cc:30
PFX_STR_UNUSUAL2
#define PFX_STR_UNUSUAL2
Definition: bad_client/tests/simple_request.cc:62
generate.env
env
Definition: generate.py:37
grpc_metadata_array
Definition: grpc_types.h:579
grpc_call_details
Definition: grpc_types.h:585
string.h
error
grpc_error_handle error
Definition: retry_filter.cc:499
main
int main(int argc, char **argv)
Definition: bad_client/tests/simple_request.cc:118
GRPC_CALL_OK
@ GRPC_CALL_OK
Definition: grpc_types.h:466
absl::FormatConversionChar::s
@ s
grpc_call_details::method
grpc_slice method
Definition: grpc_types.h:586
PFX_STR_UNUSUAL
#define PFX_STR_UNUSUAL
Definition: bad_client/tests/simple_request.cc:43
grpc_metadata_array_destroy
GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array)
Definition: metadata_array.cc:35
grpc_server_request_call
GRPCAPI grpc_call_error grpc_server_request_call(grpc_server *server, grpc_call **call, grpc_call_details *details, grpc_metadata_array *request_metadata, grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag_new)
Definition: src/core/lib/surface/server.cc:1526
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_call_unref
GRPCAPI void grpc_call_unref(grpc_call *call)
Definition: call.cc:1770
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
cq_verifier_destroy
void cq_verifier_destroy(cq_verifier *v)
Definition: cq_verifier.cc:92
grpc.h
grpc_call
struct grpc_call grpc_call
Definition: grpc_types.h:70
cq_verifier_create
cq_verifier * cq_verifier_create(grpc_completion_queue *cq)
Definition: cq_verifier.cc:86
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
cq_verifier
Definition: cq_verifier.cc:76
request_metadata_recv
static grpc_metadata_array request_metadata_recv
Definition: test/core/fling/server.cc:48
tag
static void * tag(intptr_t t)
Definition: bad_client/tests/simple_request.cc:81
CQ_EXPECT_COMPLETION
#define CQ_EXPECT_COMPLETION(v, tag, success)
Definition: cq_verifier.h:58
GRPC_BAD_CLIENT_DISCONNECT
#define GRPC_BAD_CLIENT_DISCONNECT
Definition: bad_client.h:48
cq_verifier.h
grpc_call_details::host
grpc_slice host
Definition: grpc_types.h:587
server
Definition: examples/python/async_streaming/server.py:1
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
cq_verify
void cq_verify(cq_verifier *v, int timeout_sec)
Definition: cq_verifier.cc:268
server.h
GRPC_RUN_BAD_CLIENT_TEST
#define GRPC_RUN_BAD_CLIENT_TEST(server_validator, client_validator, payload, flags)
Definition: bad_client.h:71
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
PFX_STR
#define PFX_STR
Definition: bad_client/tests/simple_request.cc:27
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_slice_str_cmp
GPRAPI int grpc_slice_str_cmp(grpc_slice a, const char *b)
Definition: slice/slice.cc:426
verifier
static void verifier(grpc_server *server, grpc_completion_queue *cq, void *)
Definition: bad_client/tests/simple_request.cc:83
GRPC_QUEUE_TIMEOUT
@ GRPC_QUEUE_TIMEOUT
Definition: grpc_types.h:556
failure_verifier
static void failure_verifier(grpc_server *server, grpc_completion_queue *cq, void *)
Definition: bad_client/tests/simple_request.cc:109
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
call_details
static grpc_call_details call_details
Definition: test/core/fling/server.cc:47
grpc_metadata_array_init
GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array)
Definition: metadata_array.cc:30


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:12