bad_client/tests/large_metadata.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 "absl/strings/str_format.h"
22 #include "absl/strings/str_join.h"
23 
24 #include <grpc/support/alloc.h>
26 
31 
32 // The large-metadata headers that we're adding for this test are not
33 // actually appended to this in a single string, since the string would
34 // be longer than the C99 string literal limit. Instead, we dynamically
35 // construct it by adding the large headers one at a time.
36 
37 /* headers: generated from large_metadata.headers in this directory */
38 #define PFX_TOO_MUCH_METADATA_FROM_CLIENT_REQUEST \
39  "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \
40  "\x00" \
41  "5{\x01\x05\x00\x00\x00\x01" \
42  "\x10\x05:path\x08/foo/bar" \
43  "\x10\x07:scheme\x04http" \
44  "\x10\x07:method\x04POST" \
45  "\x10\x0a:authority\x09localhost" \
46  "\x10\x0c" \
47  "content-type\x10" \
48  "application/grpc" \
49  "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \
50  "\x10\x02te\x08trailers" \
51  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
52 
53 // Each large-metadata header is constructed from these start and end
54 // strings, with a two-digit number in between.
55 #define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR "\x10\x0duser-header"
56 #define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR \
57  "~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
58  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
59 
60 // The size of each large-metadata header string.
61 #define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE \
62  ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR) - 1) + 2 + \
63  (sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR) - 1))
64 
65 // The number of headers we're adding and the total size of the client
66 // payload.
67 #define NUM_HEADERS 46
68 #define TOO_MUCH_METADATA_FROM_CLIENT_REQUEST_SIZE \
69  ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_REQUEST) - 1) + \
70  (NUM_HEADERS * PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE) + 1)
71 
73  void* /*registered_method*/) {
74  while (grpc_core::Server::FromC(server)->HasOpenConnections()) {
78  }
79 }
80 
81 int main(int argc, char** argv) {
82  int i;
83  grpc_init();
85 
86  // Test sending more metadata than the server will accept.
87  std::vector<std::string> headers;
88  for (i = 0; i < NUM_HEADERS; ++i) {
89  headers.push_back(absl::StrFormat(
92  }
93  std::string client_headers = absl::StrJoin(headers, "");
94  char client_payload[TOO_MUCH_METADATA_FROM_CLIENT_REQUEST_SIZE] =
96  memcpy(client_payload + sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_REQUEST) - 1,
97  client_headers.data(), client_headers.size());
100  args[1].client_validator = rst_stream_client_validator;
101  args[1].client_payload = client_payload;
102  args[1].client_payload_length = sizeof(client_payload) - 1;
103 
105 
106  grpc_shutdown();
107  return 0;
108 }
main
int main(int argc, char **argv)
Definition: bad_client/tests/large_metadata.cc:81
generate.env
env
Definition: generate.py:37
absl::StrFormat
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
Definition: abseil-cpp/absl/strings/str_format.h:338
string.h
PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR
#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR
Definition: bad_client/tests/large_metadata.cc:56
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR
#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR
Definition: bad_client/tests/large_metadata.cc:55
string_util.h
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
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
absl::StrJoin
std::string StrJoin(Iterator start, Iterator end, absl::string_view sep, Formatter &&fmt)
Definition: abseil-cpp/absl/strings/str_join.h:239
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
TOO_MUCH_METADATA_FROM_CLIENT_REQUEST_SIZE
#define TOO_MUCH_METADATA_FROM_CLIENT_REQUEST_SIZE
Definition: bad_client/tests/large_metadata.cc:68
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
PFX_TOO_MUCH_METADATA_FROM_CLIENT_REQUEST
#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_REQUEST
Definition: bad_client/tests/large_metadata.cc:38
cq_verifier.h
verifier_fails
static void verifier_fails(grpc_server *server, grpc_completion_queue *cq, void *)
Definition: bad_client/tests/large_metadata.cc:72
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
alloc.h
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
NUM_HEADERS
#define NUM_HEADERS
Definition: bad_client/tests/large_metadata.cc:67
server.h
rst_stream_client_validator
bool rst_stream_client_validator(grpc_slice_buffer *incoming, void *)
Definition: bad_client.cc:286
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
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:14