fake_transport_security_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 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 
20 
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <string.h>
24 
25 #include <grpc/grpc.h>
26 #include <grpc/support/alloc.h>
27 #include <grpc/support/log.h>
28 
33 
34 typedef struct fake_tsi_test_fixture {
37 
39  fixture->client_handshaker =
40  tsi_create_fake_handshaker(true /* is_client. */);
41  fixture->server_handshaker =
42  tsi_create_fake_handshaker(false /* is_client. */);
43 }
44 
46  GPR_ASSERT(result != nullptr);
47  tsi_peer peer;
49  const tsi_peer_property* property =
51  GPR_ASSERT(property != nullptr);
52  GPR_ASSERT(memcmp(property->value.data, TSI_FAKE_CERTIFICATE_TYPE,
53  property->value.length) == 0);
54  property =
56  GPR_ASSERT(property != nullptr);
57  GPR_ASSERT(memcmp(property->value.data, TSI_FAKE_SECURITY_LEVEL,
58  property->value.length) == 0);
59  tsi_peer_destruct(&peer);
60 }
61 
63  validate_handshaker_peers(fixture->client_result);
64  validate_handshaker_peers(fixture->server_result);
65 }
66 
68 
69 static const struct tsi_test_fixture_vtable vtable = {
72 
74  fake_tsi_test_fixture* fake_fixture =
75  static_cast<fake_tsi_test_fixture*>(gpr_zalloc(sizeof(*fake_fixture)));
76  tsi_test_fixture_init(&fake_fixture->base);
77  fake_fixture->base.vtable = &vtable;
78  return &fake_fixture->base;
79 }
80 
83  fixture->handshake_buffer_size = TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE;
86 }
87 
90  fixture->handshake_buffer_size = TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE;
93 }
94 
99 }
100 
102  unsigned int* bit_array = static_cast<unsigned int*>(
103  gpr_zalloc(sizeof(unsigned int) * TSI_TEST_NUM_OF_ARGUMENTS));
104  const unsigned int mask = 1U << (TSI_TEST_NUM_OF_ARGUMENTS - 1);
105  for (unsigned int val = 0; val < TSI_TEST_NUM_OF_COMBINATIONS; val++) {
106  unsigned int v = val;
107  for (unsigned int ind = 0; ind < TSI_TEST_NUM_OF_ARGUMENTS; ind++) {
108  bit_array[ind] = (v & mask) ? 1 : 0;
109  v <<= 1;
110  }
112  fake_tsi_test_fixture* fake_fixture =
113  reinterpret_cast<fake_tsi_test_fixture*>(fixture);
116  bit_array[0], bit_array[1], bit_array[2], bit_array[3], bit_array[4],
117  bit_array[5], bit_array[6]);
118  tsi_test_do_round_trip(&fake_fixture->base);
120  }
121  gpr_free(bit_array);
122 }
123 
125  const size_t odd_sizes[] = {1025, 2051, 4103, 8207, 16409};
126  const size_t size = sizeof(odd_sizes) / sizeof(size_t);
127  for (size_t ind1 = 0; ind1 < size; ind1++) {
128  for (size_t ind2 = 0; ind2 < size; ind2++) {
129  for (size_t ind3 = 0; ind3 < size; ind3++) {
130  for (size_t ind4 = 0; ind4 < size; ind4++) {
131  for (size_t ind5 = 0; ind5 < size; ind5++) {
133  fake_tsi_test_fixture* fake_fixture =
134  reinterpret_cast<fake_tsi_test_fixture*>(fixture);
136  fake_fixture->base.config, odd_sizes[ind1], odd_sizes[ind2],
137  odd_sizes[ind3], odd_sizes[ind4], odd_sizes[ind5]);
138  tsi_test_do_round_trip(&fake_fixture->base);
140  }
141  }
142  }
143  }
144  }
145 }
146 
147 int main(int argc, char** argv) {
148  grpc::testing::TestEnvironment env(&argc, argv);
149  grpc_init();
155  grpc_shutdown();
156  return 0;
157 }
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
log.h
generate.env
env
Definition: generate.py:37
tsi_test_frame_protector_config_set_buffer_size
void tsi_test_frame_protector_config_set_buffer_size(tsi_test_frame_protector_config *config, size_t read_buffer_allocated_size, size_t message_buffer_allocated_size, size_t protected_buffer_size, size_t client_max_output_protected_frame_size, size_t server_max_output_protected_frame_size)
Definition: transport_security_test_lib.cc:560
TSI_TEST_NUM_OF_ARGUMENTS
#define TSI_TEST_NUM_OF_ARGUMENTS
Definition: transport_security_test_lib.h:38
tsi_test_fixture_vtable
Definition: transport_security_test_lib.h:67
fake_tsi_test_do_handshake_tiny_handshake_buffer
void fake_tsi_test_do_handshake_tiny_handshake_buffer()
Definition: fake_transport_security_test.cc:81
TSI_FAKE_SECURITY_LEVEL
#define TSI_FAKE_SECURITY_LEVEL
Definition: fake_transport_security.h:30
TSI_SECURITY_LEVEL_PEER_PROPERTY
#define TSI_SECURITY_LEVEL_PEER_PROPERTY
Definition: transport_security_interface.h:226
string.h
ind
Definition: bloaty/third_party/zlib/examples/gun.c:81
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
tsi_test_frame_protector_config_destroy
void tsi_test_frame_protector_config_destroy(tsi_test_frame_protector_config *config)
Definition: transport_security_test_lib.cc:575
fake_tsi_test_do_round_trip_odd_buffer_size
void fake_tsi_test_do_round_trip_odd_buffer_size()
Definition: fake_transport_security_test.cc:124
tsi_test_fixture_init
void tsi_test_fixture_init(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:607
tsi_test_fixture_destroy
void tsi_test_fixture_destroy(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:620
fake_tsi_test_fixture::base
tsi_test_fixture base
Definition: fake_transport_security_test.cc:35
transport_security_test_lib.h
tsi_create_fake_handshaker
tsi_handshaker * tsi_create_fake_handshaker(int is_client)
Definition: fake_transport_security.cc:778
fake_tsi_test_fixture
Definition: fake_transport_security_test.cc:34
gpr_zalloc
GPRAPI void * gpr_zalloc(size_t size)
Definition: alloc.cc:40
TSI_FAKE_CERTIFICATE_TYPE
#define TSI_FAKE_CERTIFICATE_TYPE
Definition: fake_transport_security.h:28
TSI_OK
@ TSI_OK
Definition: transport_security_interface.h:32
TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE
#define TSI_TEST_SMALL_HANDSHAKE_BUFFER_SIZE
Definition: transport_security_test_lib.h:27
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
fixture
static const char fixture[]
Definition: test-fs-copyfile.c:36
tsi_test_do_round_trip
void tsi_test_do_round_trip(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:459
fake_tsi_test_do_handshake_small_handshake_buffer
void fake_tsi_test_do_handshake_small_handshake_buffer()
Definition: fake_transport_security_test.cc:88
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
fake_tsi_test_fixture_create
static tsi_test_fixture * fake_tsi_test_fixture_create()
Definition: fake_transport_security_test.cc:73
grpc.h
security_connector.h
fake_tsi_test_do_handshake
void fake_tsi_test_do_handshake()
Definition: fake_transport_security_test.cc:95
tsi_test_fixture::config
tsi_test_frame_protector_config * config
Definition: transport_security_test_lib.h:89
tsi_test_frame_protector_config_create
tsi_test_frame_protector_config * tsi_test_frame_protector_config_create(bool use_default_read_buffer_allocated_size, bool use_default_message_buffer_allocated_size, bool use_default_protected_buffer_size, bool use_default_client_message, bool use_default_server_message, bool use_default_client_max_output_protected_frame_size, bool use_default_server_max_output_protected_frame_size)
Definition: transport_security_test_lib.cc:503
fake_tsi_test_fixture
struct fake_tsi_test_fixture fake_tsi_test_fixture
tsi_peer_get_property_by_name
const tsi_peer_property * tsi_peer_get_property_by_name(const tsi_peer *peer, const char *name)
Definition: transport_security.cc:369
tsi_test_fixture::vtable
const tsi_test_fixture_vtable * vtable
Definition: transport_security_test_lib.h:74
fake_test_check_handshaker_peers
static void fake_test_check_handshaker_peers(tsi_test_fixture *fixture)
Definition: fake_transport_security_test.cc:62
tsi_test_do_handshake
void tsi_test_do_handshake(tsi_test_fixture *fixture)
Definition: transport_security_test_lib.cc:386
main
int main(int argc, char **argv)
Definition: fake_transport_security_test.cc:147
tsi_handshaker_result_extract_peer
tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result *self, tsi_peer *peer)
Definition: transport_security.cc:244
TSI_TEST_NUM_OF_COMBINATIONS
#define TSI_TEST_NUM_OF_COMBINATIONS
Definition: transport_security_test_lib.h:39
tsi_peer_property
Definition: transport_security_interface.h:230
test_config.h
TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE
#define TSI_TEST_TINY_HANDSHAKE_BUFFER_SIZE
Definition: transport_security_test_lib.h:26
tsi_peer
Definition: transport_security_interface.h:238
transport_security.h
fake_test_destruct
static void fake_test_destruct(tsi_test_fixture *fixture)
Definition: fake_transport_security_test.cc:67
validate_handshaker_peers
static void validate_handshaker_peers(tsi_handshaker_result *result)
Definition: fake_transport_security_test.cc:45
alloc.h
tsi_test_fixture
Definition: transport_security_test_lib.h:73
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
tsi_handshaker_result
Definition: transport_security.h:121
fake_test_setup_handshakers
static void fake_test_setup_handshakers(tsi_test_fixture *fixture)
Definition: fake_transport_security_test.cc:38
fake_tsi_test_do_round_trip_for_all_configs
void fake_tsi_test_do_round_trip_for_all_configs()
Definition: fake_transport_security_test.cc:101
TSI_CERTIFICATE_TYPE_PEER_PROPERTY
#define TSI_CERTIFICATE_TYPE_PEER_PROPERTY
Definition: transport_security_interface.h:223
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
fake_transport_security.h
tsi_peer_destruct
void tsi_peer_destruct(tsi_peer *self)
Definition: transport_security.cc:320
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
vtable
static const struct tsi_test_fixture_vtable vtable
Definition: fake_transport_security_test.cc:69


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:22