Debian Codegraph @

crt/aws-c-http/tests/test_connection_manager.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/testing/aws_test_harness.h>
7
8 #include <aws/common/array_list.h>
9 #include <aws/common/clock.h>
10 #include <aws/common/condition_variable.h>
11 #include <aws/common/environment.h>
12 #include <aws/common/logging.h>
13 #include <aws/common/mutex.h>
14 #include <aws/common/string.h>
15 #include <aws/common/thread.h>
16 #include <aws/common/uuid.h>
17 #include <aws/http/connection.h>
18 #include <aws/http/connection_manager.h>
19 #include <aws/http/private/connection_manager_system_vtable.h>
20 #include <aws/http/proxy.h>
21 #include <aws/http/server.h>
22 #include <aws/io/channel_bootstrap.h>
23 #include <aws/io/event_loop.h>
24 #include <aws/io/socket.h>
25 #include <aws/io/tls_channel_handler.h>
26
27 #ifdef _MSC_VER
28 # pragma warning(disable : 4232) /* function pointer to dll symbol */
29 #endif
30
31 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_env_var, "HTTP_PROXY");
32 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_env_var_low, "http_proxy");
33 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var, "HTTPS_PROXY");
34 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var_low, "https_proxy");
35
36 enum new_connection_result_type {
37 AWS_NCRT_SUCCESS,
38 AWS_NCRT_ERROR_VIA_CALLBACK,
39 AWS_NCRT_ERROR_FROM_CREATE,
40 };
41
42 struct mock_connection {
43 enum new_connection_result_type result;
44 bool is_closed_on_release;
45 };
46
47 struct cm_tester_options {
48 struct aws_allocator *allocator;
49 struct aws_http_connection_manager_system_vtable *mock_table;
50 struct aws_http_proxy_options *proxy_options;
51 bool use_proxy_env;
52 bool use_tls;
53 struct aws_tls_connection_options *env_configured_tls;
54 size_t max_connections;
55 uint64_t max_connection_idle_in_ms;
56 uint64_t connection_acquisition_timeout_ms;
57 uint64_t max_pending_connection_acquisitions;
58
59 uint64_t starting_mock_time;
60 bool http2;
61 struct aws_http2_setting *initial_settings_array;
62 size_t num_initial_settings;
63 bool self_lib_init;
64 const struct aws_byte_cursor *verify_network_interface_names_array;
65 size_t num_network_interface_names;
66 };
67
68 struct cm_tester {
69 struct aws_allocator *allocator;
70 struct aws_event_loop_group *event_loop_group;
71 struct aws_host_resolver *host_resolver;
72
73 struct aws_client_bootstrap *client_bootstrap;
74
75 struct aws_http_connection_manager *connection_manager;
76
77 struct aws_tls_ctx *tls_ctx;
78 struct aws_tls_ctx_options tls_ctx_options;
79 struct aws_tls_connection_options tls_connection_options;
80 struct aws_http_proxy_options *verify_proxy_options;
81 const struct aws_byte_cursor *verify_network_interface_names_array;
82 size_t num_network_interface_names;
83
84 struct aws_mutex lock;
85 struct aws_condition_variable signal;
86
87 struct aws_array_list connections;
88 /* aws_array_list<uint32> of error codes */
89 struct aws_array_list connection_errors_list;
90 size_t connection_errors;
91 size_t connection_releases;
92
93 size_t wait_for_connection_count;
94 bool is_shutdown_complete;
95
96 struct aws_http_connection_manager_system_vtable *mock_table;
97
98 struct aws_atomic_var next_connection_id;
99 struct aws_array_list mock_connections;
100 aws_http_on_client_connection_shutdown_fn *release_connection_fn;
101
102 struct aws_mutex mock_time_lock;
103 uint64_t mock_time;
104
105 struct proxy_env_var_settings proxy_ev_settings;
106 bool proxy_request_complete;
107 bool proxy_request_successful;
108 bool self_lib_init;
109 };
110
111 static struct cm_tester s_tester;
112
113 static int s_tester_get_mock_time(uint64_t *current_time) {
114 aws_mutex_lock(&s_tester.mock_time_lock);
115 *current_time = s_tester.mock_time;
116 aws_mutex_unlock(&s_tester.mock_time_lock);
117
118 return AWS_OP_SUCCESS;
119 }
120
121 static void s_tester_set_mock_time(uint64_t current_time) {
122 aws_mutex_lock(&s_tester.mock_time_lock);
123 s_tester.mock_time = current_time;
124 aws_mutex_unlock(&s_tester.mock_time_lock);
125 }
126
127 static void s_cm_tester_on_cm_shutdown_complete(void *user_data) {
128 struct cm_tester *tester = user_data;
129 AWS_FATAL_ASSERT(tester == &s_tester);
130
131 aws_mutex_lock(&tester->lock);
132 tester->is_shutdown_complete = true;
133 aws_condition_variable_notify_one(&tester->signal);
134 aws_mutex_unlock(&tester->lock);
135 }
136
137 static int s_cm_tester_init(struct cm_tester_options *options) {
138 struct cm_tester *tester = &s_tester;
139
140 AWS_ZERO_STRUCT(*tester);
141 tester->self_lib_init = options->self_lib_init;
142 if (!tester->self_lib_init) {
143 aws_http_library_init(options->allocator);
144 }
145 tester->allocator = options->allocator;
146
147 ASSERT_SUCCESS(aws_mutex_init(&tester->lock));
148 ASSERT_SUCCESS(aws_condition_variable_init(&tester->signal));
149
150 ASSERT_SUCCESS(
151 aws_array_list_init_dynamic(&tester->connections, tester->allocator, 10, sizeof(struct aws_http_connection *)));
152
153 ASSERT_SUCCESS(
154 aws_array_list_init_dynamic(&tester->connection_errors_list, tester->allocator, 10, sizeof(uint32_t)));
155
156 aws_mutex_init(&tester->mock_time_lock);
157 s_tester_set_mock_time(options->starting_mock_time);
158
159 aws_io_clock_fn *clock_fn = &aws_high_res_clock_get_ticks;
160 if (options->mock_table) {
161 clock_fn = options->mock_table->aws_high_res_clock_get_ticks;
162 }
163
164 struct aws_event_loop_group_options elg_options = {
165 .loop_count = 1,
166 .clock_override = clock_fn,
167 };
168 tester->event_loop_group = aws_event_loop_group_new(tester->allocator, &elg_options);
169
170 struct aws_host_resolver_default_options resolver_options = {
171 .el_group = tester->event_loop_group,
172 .max_entries = 8,
173 };
174
175 tester->host_resolver = aws_host_resolver_new_default(tester->allocator, &resolver_options);
176 struct aws_client_bootstrap_options bootstrap_options = {
177 .event_loop_group = tester->event_loop_group,
178 .host_resolver = tester->host_resolver,
179 };
180 tester->client_bootstrap = aws_client_bootstrap_new(tester->allocator, &bootstrap_options);
181 ASSERT_NOT_NULL(tester->client_bootstrap);
182
183 struct aws_socket_options socket_options = {
184 .type = AWS_SOCKET_STREAM,
185 .domain = AWS_SOCKET_IPV4,
186 .connect_timeout_ms = (uint32_t)aws_timestamp_convert(10, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_MILLIS, NULL),
187 };
188
189 aws_tls_ctx_options_init_default_client(&tester->tls_ctx_options, options->allocator);
190 aws_tls_ctx_options_set_verify_peer(&tester->tls_ctx_options, false);
191 if (options->http2) {
192 ASSERT_SUCCESS(aws_tls_ctx_options_set_alpn_list(&tester->tls_ctx_options, "h2"));
193 }
194
195 tester->tls_ctx = aws_tls_client_ctx_new(options->allocator, &tester->tls_ctx_options);
196 ASSERT_NOT_NULL(tester->tls_ctx);
197
198 struct aws_byte_cursor server_name = aws_byte_cursor_from_c_str("www.google.com");
199
200 aws_tls_connection_options_init_from_ctx(&tester->tls_connection_options, tester->tls_ctx);
201
202 aws_tls_connection_options_set_server_name(&tester->tls_connection_options, options->allocator, &server_name);
203
204 tester->verify_proxy_options = options->proxy_options;
205 tester->proxy_ev_settings.env_var_type = options->use_proxy_env ? AWS_HPEV_ENABLE : AWS_HPEV_DISABLE;
206 struct aws_tls_connection_options default_tls_connection_options;
207 AWS_ZERO_STRUCT(default_tls_connection_options);
208 if (options->env_configured_tls) {
209 ASSERT_SUCCESS(aws_tls_connection_options_copy(&default_tls_connection_options, options->env_configured_tls));
210 tester->proxy_ev_settings.tls_options = &default_tls_connection_options;
211 }
212
213 struct aws_http_connection_manager_options cm_options = {
214 .bootstrap = tester->client_bootstrap,
215 .initial_window_size = SIZE_MAX,
216 .socket_options = &socket_options,
217 .tls_connection_options = options->use_tls ? &tester->tls_connection_options : NULL,
218 .proxy_options = options->proxy_options,
219 .proxy_ev_settings = &tester->proxy_ev_settings,
220 .host = server_name,
221 .port = options->use_tls ? 443 : 80,
222 .max_connections = options->max_connections,
223 .shutdown_complete_user_data = tester,
224 .shutdown_complete_callback = s_cm_tester_on_cm_shutdown_complete,
225 .max_connection_idle_in_milliseconds = options->max_connection_idle_in_ms,
226 .connection_acquisition_timeout_ms = options->connection_acquisition_timeout_ms,
227 .max_pending_connection_acquisitions = options->max_pending_connection_acquisitions,
228 .http2_prior_knowledge = !options->use_tls && options->http2,
229 .initial_settings_array = options->initial_settings_array,
230 .num_initial_settings = options->num_initial_settings,
231 .network_interface_names_array = options->verify_network_interface_names_array,
232 .num_network_interface_names = options->num_network_interface_names,
233 };
234
235 if (options->mock_table) {
236 g_aws_http_connection_manager_default_system_vtable_ptr = options->mock_table;
237 }
238
239 tester->connection_manager = aws_http_connection_manager_new(tester->allocator, &cm_options);
240 ASSERT_NOT_NULL(tester->connection_manager);
241 aws_tls_connection_options_clean_up(&default_tls_connection_options);
242
243 if (options->mock_table) {
244 aws_http_connection_manager_set_system_vtable(tester->connection_manager, options->mock_table);
245 }
246
247 tester->mock_table = options->mock_table;
248 tester->verify_network_interface_names_array = options->verify_network_interface_names_array;
249 tester->num_network_interface_names = options->num_network_interface_names;
250
251 aws_atomic_store_int(&tester->next_connection_id, 0);
252
253 ASSERT_SUCCESS(aws_array_list_init_dynamic(
254 &tester->mock_connections, tester->allocator, 10, sizeof(struct mock_connection *)));
255
256 return AWS_OP_SUCCESS;
257 }
258
259 static void s_add_mock_connections(size_t count, enum new_connection_result_type result, bool closed_on_release) {
260 struct cm_tester *tester = &s_tester;
261
262 for (size_t i = 0; i < count; ++i) {
263 struct mock_connection *mock = aws_mem_acquire(tester->allocator, sizeof(struct mock_connection));
264 AWS_ZERO_STRUCT(*mock);
265
266 mock->result = result;
267 mock->is_closed_on_release = closed_on_release;
268
269 aws_array_list_push_back(&tester->mock_connections, &mock);
270 }
271 }
272
273 static int s_release_connections(size_t count, bool close_first) {
274
275 struct cm_tester *tester = &s_tester;
276
277 struct aws_array_list to_release;
278 AWS_ZERO_STRUCT(to_release);
279
280 ASSERT_SUCCESS(aws_mutex_lock(&tester->lock));
281
282 size_t release_count = aws_array_list_length(&tester->connections);
283 if (release_count > count) {
284 release_count = count;
285 }
286
287 if (release_count == 0) {
288 goto release;
289 }
290
291 if (aws_array_list_init_dynamic(
292 &to_release, tester->allocator, release_count, sizeof(struct aws_http_connection *))) {
293 goto release;
294 }
295
296 for (size_t i = 0; i < release_count; ++i) {
297 struct aws_http_connection *connection = NULL;
298 if (aws_array_list_back(&tester->connections, &connection)) {
299 continue;
300 }
301
302 aws_array_list_pop_back(&tester->connections);
303
304 aws_array_list_push_back(&to_release, &connection);
305 }
306
307 release:
308
309 ASSERT_SUCCESS(aws_mutex_unlock(&tester->lock));
310
311 if (aws_array_list_is_valid(&to_release)) {
312 for (size_t i = 0; i < aws_array_list_length(&to_release); ++i) {
313 struct aws_http_connection *connection = NULL;
314 if (aws_array_list_get_at(&to_release, &connection, i)) {
315 continue;
316 }
317
318 if (close_first) {
319 if (tester->mock_table) {
320 tester->mock_table->aws_http_connection_close(connection);
321 } else {
322 aws_http_connection_close(connection);
323 }
324 }
325
326 aws_http_connection_manager_release_connection(tester->connection_manager, connection);
327
328 ASSERT_SUCCESS(aws_mutex_lock(&tester->lock));
329 ++tester->connection_releases;
330 aws_condition_variable_notify_one(&tester->signal);
331 ASSERT_SUCCESS(aws_mutex_unlock(&tester->lock));
332 }
333
334 aws_array_list_clean_up(&to_release);
335 } else {
336 ASSERT_UINT_EQUALS(0, release_count);
337 }
338
339 return AWS_OP_SUCCESS;
340 }
341
342 static void s_on_acquire_connection(struct aws_http_connection *connection, int error_code, void *user_data) {
343 (void)error_code;
344 (void)user_data;
345
346 struct cm_tester *tester = &s_tester;
347
348 AWS_FATAL_ASSERT(aws_mutex_lock(&tester->lock) == AWS_OP_SUCCESS);
349
350 if (connection == NULL) {
351 aws_array_list_push_back(&tester->connection_errors_list, &error_code);
352 ++tester->connection_errors;
353 } else {
354 aws_array_list_push_back(&tester->connections, &connection);
355 }
356
357 aws_condition_variable_notify_one(&tester->signal);
358
359 AWS_FATAL_ASSERT(aws_mutex_unlock(&tester->lock) == AWS_OP_SUCCESS);
360 }
361
362 static void s_acquire_connections(size_t count) {
363 struct cm_tester *tester = &s_tester;
364
365 for (size_t i = 0; i < count; ++i) {
366 aws_http_connection_manager_acquire_connection(tester->connection_manager, s_on_acquire_connection, tester);
367 }
368 }
369
370 static bool s_is_connection_reply_count_at_least(void *context) {
371 (void)context;
372
373 struct cm_tester *tester = &s_tester;
374
375 return tester->wait_for_connection_count <=
376 aws_array_list_length(&tester->connections) + tester->connection_errors + tester->connection_releases;
377 }
378
379 static int s_wait_on_connection_reply_count(size_t count) {
380 struct cm_tester *tester = &s_tester;
381
382 ASSERT_SUCCESS(aws_mutex_lock(&tester->lock));
383
384 tester->wait_for_connection_count = count;
385 int signal_error =
386 aws_condition_variable_wait_pred(&tester->signal, &tester->lock, s_is_connection_reply_count_at_least, tester);
387
388 ASSERT_SUCCESS(aws_mutex_unlock(&tester->lock));
389 return signal_error;
390 }
391
392 static bool s_is_shutdown_complete(void *context) {
393 (void)context;
394
395 struct cm_tester *tester = &s_tester;
396
397 return tester->is_shutdown_complete;
398 }
399
400 static int s_wait_on_shutdown_complete(void) {
401 struct cm_tester *tester = &s_tester;
402
403 ASSERT_SUCCESS(aws_mutex_lock(&tester->lock));
404
405 int signal_error = aws_condition_variable_wait_pred(&tester->signal, &tester->lock, s_is_shutdown_complete, tester);
406
407 ASSERT_SUCCESS(aws_mutex_unlock(&tester->lock));
408 return signal_error;
409 }
410
411 static int s_cm_tester_clean_up(void) {
412 struct cm_tester *tester = &s_tester;
413
414 ASSERT_SUCCESS(s_release_connections(aws_array_list_length(&tester->connections), false));
415
416 aws_array_list_clean_up(&tester->connections);
417 aws_array_list_clean_up(&tester->connection_errors_list);
418
419 for (size_t i = 0; i < aws_array_list_length(&tester->mock_connections); ++i) {
420 struct mock_connection *mock = NULL;
421
422 if (aws_array_list_get_at(&tester->mock_connections, &mock, i)) {
423 continue;
424 }
425
426 aws_mem_release(tester->allocator, mock);
427 }
428 aws_array_list_clean_up(&tester->mock_connections);
429
430 aws_http_connection_manager_release(tester->connection_manager);
431
432 s_wait_on_shutdown_complete();
433
434 aws_client_bootstrap_release(tester->client_bootstrap);
435
436 aws_host_resolver_release(tester->host_resolver);
437 aws_event_loop_group_release(tester->event_loop_group);
438
439 aws_tls_ctx_options_clean_up(&tester->tls_ctx_options);
440 aws_tls_connection_options_clean_up(&tester->tls_connection_options);
441 aws_tls_ctx_release(tester->tls_ctx);
442
443 if (!tester->self_lib_init) {
444 aws_http_library_clean_up();
445 }
446 aws_mutex_clean_up(&tester->lock);
447 aws_condition_variable_clean_up(&tester->signal);
448
449 aws_mutex_clean_up(&tester->mock_time_lock);
450
451 return AWS_OP_SUCCESS;
452 }
453
454 static int s_test_connection_manager_setup_shutdown(struct aws_allocator *allocator, void *ctx) {
455 (void)ctx;
456
457 struct cm_tester_options options = {
458 .allocator = allocator,
459 .max_connections = 5,
460 };
461
462 ASSERT_SUCCESS(s_cm_tester_init(&options));
463
464 ASSERT_SUCCESS(s_cm_tester_clean_up());
465
466 return AWS_OP_SUCCESS;
467 }
468 AWS_TEST_CASE(connection_manager_setup_shutdown, s_test_connection_manager_setup_shutdown);
469
470 static int s_test_connection_manager_single_connection(struct aws_allocator *allocator, void *ctx) {
471 (void)ctx;
472
473 struct cm_tester_options options = {
474 .allocator = allocator,
475 .max_connections = 5,
476 };
477
478 ASSERT_SUCCESS(s_cm_tester_init(&options));
479
480 s_acquire_connections(1);
481
482 ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
483
484 ASSERT_SUCCESS(s_release_connections(1, false));
485 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
486
487 ASSERT_SUCCESS(s_cm_tester_clean_up());
488
489 return AWS_OP_SUCCESS;
490 }
491 AWS_TEST_CASE(connection_manager_single_connection, s_test_connection_manager_single_connection);
492
493 static int s_test_connection_manager_proxy_envrionment_empty_string(struct aws_allocator *allocator, void *ctx) {
494 (void)ctx;
495 /* Set proxy related envrionment variables to empty string and make sure we just skip proxy */
496 struct aws_string *empty = aws_string_new_from_c_str(allocator, "");
497 ASSERT_SUCCESS(aws_set_environment_value(s_http_proxy_env_var, empty));
498 ASSERT_SUCCESS(aws_set_environment_value(s_http_proxy_env_var_low, empty));
499 ASSERT_SUCCESS(aws_set_environment_value(s_https_proxy_env_var, empty));
500 ASSERT_SUCCESS(aws_set_environment_value(s_https_proxy_env_var_low, empty));
501
502 struct cm_tester_options options = {
503 .allocator = allocator,
504 .max_connections = 5,
505 .use_proxy_env = true,
506 };
507
508 ASSERT_SUCCESS(s_cm_tester_init(&options));
509
510 s_acquire_connections(1);
511
512 ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
513
514 ASSERT_SUCCESS(s_release_connections(1, false));
515 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
516
517 ASSERT_SUCCESS(s_cm_tester_clean_up());
518 aws_string_destroy(empty);
519
520 return AWS_OP_SUCCESS;
521 }
522 AWS_TEST_CASE(
523 connection_manager_proxy_envrionment_empty_string,
524 s_test_connection_manager_proxy_envrionment_empty_string);
525
526 static int s_test_connection_manager_single_http2_connection(struct aws_allocator *allocator, void *ctx) {
527 (void)ctx;
528
529 struct cm_tester_options options = {
530 .allocator = allocator,
531 .max_connections = 5,
532 .http2 = true,
533 .use_tls = true,
534 };
535
536 ASSERT_SUCCESS(s_cm_tester_init(&options));
537
538 s_acquire_connections(1);
539
540 ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
541
542 ASSERT_SUCCESS(s_release_connections(1, false));
543
544 ASSERT_SUCCESS(s_cm_tester_clean_up());
545
546 return AWS_OP_SUCCESS;
547 }
548 AWS_TEST_CASE(connection_manager_single_http2_connection, s_test_connection_manager_single_http2_connection);
549
550 static int s_test_connection_manager_single_http2_connection_failed(struct aws_allocator *allocator, void *ctx) {
551 (void)ctx;
552 /* google don't support prior_knowledge, so, this will fail to create the connection. Check we are good when acquire
553 * failed. */
554 struct cm_tester_options options = {
555 .allocator = allocator,
556 .max_connections = 5,
557 .http2 = true,
558 };
559
560 ASSERT_SUCCESS(s_cm_tester_init(&options));
561
562 s_acquire_connections(1);
563
564 ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
565
566 ASSERT_SUCCESS(s_release_connections(1, false));
567 ASSERT_UINT_EQUALS(1, s_tester.connection_errors);
568
569 ASSERT_SUCCESS(s_cm_tester_clean_up());
570
571 return AWS_OP_SUCCESS;
572 }
573 AWS_TEST_CASE(
574 connection_manager_single_http2_connection_failed,
575 s_test_connection_manager_single_http2_connection_failed);
576
577 static int s_test_connection_manager_single_http2_connection_with_settings(struct aws_allocator *allocator, void *ctx) {
578 (void)ctx;
579 struct aws_http2_setting settings_array[] = {
580 {.id = AWS_HTTP2_SETTINGS_ENABLE_PUSH, .value = 0},
581 };
582 struct cm_tester_options options = {
583 .allocator = allocator,
584 .max_connections = 5,
585 .http2 = true,
586 .use_tls = true,
587 .initial_settings_array = settings_array,
588 .num_initial_settings = AWS_ARRAY_SIZE(settings_array),
589 };
590
591 ASSERT_SUCCESS(s_cm_tester_init(&options));
592
593 s_acquire_connections(1);
594
595 ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
596
597 ASSERT_SUCCESS(s_release_connections(1, false));
598 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
599
600 ASSERT_SUCCESS(s_cm_tester_clean_up());
601
602 return AWS_OP_SUCCESS;
603 }
604 AWS_TEST_CASE(
605 connection_manager_single_http2_connection_with_settings,
606 s_test_connection_manager_single_http2_connection_with_settings);
607
608 static int s_test_connection_manager_many_connections(struct aws_allocator *allocator, void *ctx) {
609 (void)ctx;
610
611 struct cm_tester_options options = {
612 .allocator = allocator,
613 .max_connections = 20,
614 };
615
616 ASSERT_SUCCESS(s_cm_tester_init(&options));
617
618 s_acquire_connections(20);
619
620 ASSERT_SUCCESS(s_wait_on_connection_reply_count(20));
621
622 ASSERT_SUCCESS(s_release_connections(20, false));
623 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
624
625 ASSERT_SUCCESS(s_cm_tester_clean_up());
626
627 return AWS_OP_SUCCESS;
628 }
629 AWS_TEST_CASE(connection_manager_many_connections, s_test_connection_manager_many_connections);
630
631 static int s_test_connection_manager_many_http2_connections(struct aws_allocator *allocator, void *ctx) {
632 (void)ctx;
633
634 struct cm_tester_options options = {
635 .allocator = allocator,
636 .max_connections = 20,
637 .http2 = true,
638 .use_tls = true,
639 };
640
641 ASSERT_SUCCESS(s_cm_tester_init(&options));
642
643 s_acquire_connections(20);
644
645 ASSERT_SUCCESS(s_wait_on_connection_reply_count(20));
646
647 ASSERT_SUCCESS(s_release_connections(20, false));
648 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
649
650 ASSERT_SUCCESS(s_cm_tester_clean_up());
651
652 return AWS_OP_SUCCESS;
653 }
654 AWS_TEST_CASE(connection_manager_many_http2_connections, s_test_connection_manager_many_http2_connections);
655
656 static int s_test_connection_manager_acquire_release(struct aws_allocator *allocator, void *ctx) {
657 (void)ctx;
658
659 struct cm_tester_options options = {
660 .allocator = allocator,
661 .max_connections = 4,
662 };
663
664 ASSERT_SUCCESS(s_cm_tester_init(&options));
665
666 s_acquire_connections(20);
667
668 ASSERT_SUCCESS(s_wait_on_connection_reply_count(4));
669
670 for (size_t i = 4; i < 20; ++i) {
671 ASSERT_SUCCESS(s_release_connections(1, false));
672
673 ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
674 }
675 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
676
677 ASSERT_SUCCESS(s_cm_tester_clean_up());
678
679 return AWS_OP_SUCCESS;
680 }
681 AWS_TEST_CASE(connection_manager_acquire_release, s_test_connection_manager_acquire_release);
682
683 static int s_test_connection_manager_close_and_release(struct aws_allocator *allocator, void *ctx) {
684 (void)ctx;
685
686 struct cm_tester_options options = {
687 .allocator = allocator,
688 .max_connections = 4,
689 };
690
691 ASSERT_SUCCESS(s_cm_tester_init(&options));
692
693 s_acquire_connections(20);
694
695 ASSERT_SUCCESS(s_wait_on_connection_reply_count(4));
696
697 for (size_t i = 4; i < 20; ++i) {
698 ASSERT_SUCCESS(s_release_connections(1, i % 1 == 0));
699
700 ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
701 }
702 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
703
704 ASSERT_SUCCESS(s_cm_tester_clean_up());
705
706 return AWS_OP_SUCCESS;
707 }
708 AWS_TEST_CASE(connection_manager_close_and_release, s_test_connection_manager_close_and_release);
709
710 static int s_test_connection_manager_acquire_release_mix(struct aws_allocator *allocator, void *ctx) {
711 (void)ctx;
712
713 struct cm_tester_options options = {
714 .allocator = allocator,
715 .max_connections = 5,
716 };
717
718 ASSERT_SUCCESS(s_cm_tester_init(&options));
719
720 for (size_t i = 0; i < 10; ++i) {
721 s_acquire_connections(2);
722
723 ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
724
725 ASSERT_SUCCESS(s_release_connections(1, i % 1 == 0));
726 }
727
728 ASSERT_SUCCESS(s_wait_on_connection_reply_count(15));
729
730 for (size_t i = 15; i < 20; ++i) {
731 ASSERT_SUCCESS(s_release_connections(1, i % 1 == 0));
732
733 ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
734 }
735 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
736
737 ASSERT_SUCCESS(s_cm_tester_clean_up());
738
739 return AWS_OP_SUCCESS;
740 }
741 AWS_TEST_CASE(connection_manager_acquire_release_mix, s_test_connection_manager_acquire_release_mix);
742
743 static int s_test_connection_manager_max_pending_acquisitions(struct aws_allocator *allocator, void *ctx) {
744 (void)ctx;
745
746 size_t num_connections = 2;
747 size_t max_pending_connection_acquisitions = 2;
748 size_t num_connections_pending_error = 4;
749 struct cm_tester_options options = {
750 .allocator = allocator,
751 .max_connections = num_connections,
752 .max_pending_connection_acquisitions = max_pending_connection_acquisitions,
753 };
754
755 ASSERT_SUCCESS(s_cm_tester_init(&options));
756
757 s_acquire_connections(num_connections + max_pending_connection_acquisitions + num_connections_pending_error);
758
759 ASSERT_SUCCESS(s_wait_on_connection_reply_count(num_connections + num_connections_pending_error));
760 ASSERT_UINT_EQUALS(num_connections_pending_error, s_tester.connection_errors);
761 for (size_t i = 0; i < num_connections_pending_error; i++) {
762 uint32_t error_code;
763 aws_array_list_get_at(&s_tester.connection_errors_list, &error_code, i);
764 ASSERT_UINT_EQUALS(AWS_ERROR_HTTP_CONNECTION_MANAGER_MAX_PENDING_ACQUISITIONS_EXCEEDED, error_code);
765 }
766
767 ASSERT_SUCCESS(s_release_connections(num_connections, false));
768 ASSERT_SUCCESS(s_wait_on_connection_reply_count(
769 num_connections + max_pending_connection_acquisitions + num_connections_pending_error));
770 ASSERT_SUCCESS(s_release_connections(max_pending_connection_acquisitions, false));
771
772 ASSERT_SUCCESS(s_cm_tester_clean_up());
773
774 return AWS_OP_SUCCESS;
775 }
776 AWS_TEST_CASE(connection_manager_max_pending_acquisitions, s_test_connection_manager_max_pending_acquisitions);
777
778 static int s_test_connection_manager_max_pending_acquisitions_with_vended_connections(
779 struct aws_allocator *allocator,
780 void *ctx) {
781 (void)ctx;
782
783 size_t num_connections = 2;
784 size_t max_pending_connection_acquisitions = 2;
785 size_t num_connections_pending_error = 4;
786 struct cm_tester_options options = {
787 .allocator = allocator,
788 .max_connections = num_connections,
789 .max_pending_connection_acquisitions = max_pending_connection_acquisitions,
790 };
791
792 ASSERT_SUCCESS(s_cm_tester_init(&options));
793
794 // fill the connection pool
795 s_acquire_connections(num_connections);
796 ASSERT_SUCCESS(s_wait_on_connection_reply_count(num_connections));
797
798 // try to acquire over max_pending_connection_acquisitions
799 s_acquire_connections(max_pending_connection_acquisitions + num_connections_pending_error);
800 ASSERT_SUCCESS(s_wait_on_connection_reply_count(num_connections + num_connections_pending_error));
801
802 ASSERT_UINT_EQUALS(num_connections_pending_error, s_tester.connection_errors);
803 for (size_t i = 0; i < num_connections_pending_error; i++) {
804 uint32_t error_code;
805 aws_array_list_get_at(&s_tester.connection_errors_list, &error_code, i);
806 ASSERT_UINT_EQUALS(AWS_ERROR_HTTP_CONNECTION_MANAGER_MAX_PENDING_ACQUISITIONS_EXCEEDED, error_code);
807 }
808
809 ASSERT_SUCCESS(s_release_connections(num_connections, false));
810 ASSERT_SUCCESS(s_wait_on_connection_reply_count(
811 num_connections + max_pending_connection_acquisitions + num_connections_pending_error));
812 ASSERT_SUCCESS(s_release_connections(max_pending_connection_acquisitions, false));
813
814 ASSERT_SUCCESS(s_cm_tester_clean_up());
815
816 return AWS_OP_SUCCESS;
817 }
818 AWS_TEST_CASE(
819 connection_manager_max_pending_acquisitions_with_vended_connections,
820 s_test_connection_manager_max_pending_acquisitions_with_vended_connections);
821
822 static int s_aws_http_connection_manager_create_connection_validate(
823 const struct aws_http_client_connection_options *options) {
824 struct cm_tester *tester = &s_tester;
825
826 if (tester->num_network_interface_names) {
827 struct aws_byte_cursor interface_name =
828 tester->verify_network_interface_names_array
829 [aws_atomic_load_int(&tester->next_connection_id) % tester->num_network_interface_names];
830 ASSERT_TRUE(aws_byte_cursor_eq_c_str(&interface_name, options->socket_options->network_interface_name));
831 }
832
833 ASSERT_SUCCESS(aws_mutex_lock(&tester->lock));
834 tester->release_connection_fn = options->on_shutdown;
835 ASSERT_SUCCESS(aws_mutex_unlock(&tester->lock));
836
837 /* Verify that any proxy options have been propagated to the connection attempt */
838 if (tester->verify_proxy_options) {
839 ASSERT_BIN_ARRAYS_EQUALS(
840 tester->verify_proxy_options->host.ptr,
841 tester->verify_proxy_options->host.len,
842 options->proxy_options->host.ptr,
843 options->proxy_options->host.len);
844 ASSERT_TRUE(options->proxy_options->port == tester->verify_proxy_options->port);
845 ASSERT_UINT_EQUALS(options->proxy_options->connection_type, tester->verify_proxy_options->connection_type);
846 }
847
848 return AWS_OP_SUCCESS;
849 }
850 static int s_aws_http_connection_manager_create_connection_sync_mock(
851 const struct aws_http_client_connection_options *options) {
852 s_aws_http_connection_manager_create_connection_validate(options);
853 struct cm_tester *tester = &s_tester;
854
855 struct mock_connection *connection = NULL;
856 size_t next_connection_id = aws_atomic_fetch_add(&tester->next_connection_id, 1);
857
858 if (next_connection_id < aws_array_list_length(&tester->mock_connections)) {
859 aws_array_list_get_at(&tester->mock_connections, &connection, next_connection_id);
860 }
861
862 if (connection) {
863 if (connection->result == AWS_NCRT_SUCCESS) {
864 options->on_setup((struct aws_http_connection *)connection, AWS_ERROR_SUCCESS, options->user_data);
865 } else if (connection->result == AWS_NCRT_ERROR_VIA_CALLBACK) {
866 options->on_setup(NULL, AWS_ERROR_HTTP_UNKNOWN, options->user_data);
867 }
868
869 if (connection->result != AWS_NCRT_ERROR_FROM_CREATE) {
870 return AWS_OP_SUCCESS;
871 }
872 }
873
874 return aws_raise_error(AWS_ERROR_HTTP_UNKNOWN);
875 }
876
877 struct connect_task_args {
878 void *user_data;
879 struct mock_connection *connection;
880 aws_http_on_client_connection_setup_fn *on_setup;
881 };
882
883 static void s_aws_http_connection_manager_connect_task(
884 struct aws_task *task,
885 void *user_data,
886 enum aws_task_status status) {
887 (void)status;
888 struct cm_tester *tester = &s_tester;
889
890 struct connect_task_args *task_args = user_data;
891 struct mock_connection *connection = task_args->connection;
892 if (connection) {
893 if (connection->result == AWS_NCRT_SUCCESS) {
894 task_args->on_setup((struct aws_http_connection *)connection, AWS_ERROR_SUCCESS, task_args->user_data);
895 } else if (connection->result == AWS_NCRT_ERROR_VIA_CALLBACK) {
896 task_args->on_setup(NULL, AWS_ERROR_HTTP_UNKNOWN, task_args->user_data);
897 } else {
898 AWS_FATAL_ASSERT(0 && "Unexpected connection->result");
899 }
900 }
901
902 aws_mem_release(tester->allocator, task);
903 aws_mem_release(tester->allocator, task_args);
904 }
905
906 static int s_aws_http_connection_manager_connect_async_mock(const struct aws_http_client_connection_options *options) {
907 s_aws_http_connection_manager_create_connection_validate(options);
908 struct cm_tester *tester = &s_tester;
909
910 struct mock_connection *connection = NULL;
911 size_t next_connection_id = aws_atomic_fetch_add(&tester->next_connection_id, 1);
912 if (next_connection_id < aws_array_list_length(&tester->mock_connections)) {
913 aws_array_list_get_at(&tester->mock_connections, &connection, next_connection_id);
914 }
915
916 if (connection->result == AWS_NCRT_ERROR_FROM_CREATE) {
917 return aws_raise_error(AWS_ERROR_HTTP_UNKNOWN);
918 }
919
920 struct aws_task *task = aws_mem_calloc(options->allocator, 1, sizeof(struct aws_task));
921 struct connect_task_args *task_args = aws_mem_calloc(options->allocator, 1, sizeof(struct connect_task_args));
922 task_args->connection = connection;
923 task_args->user_data = options->user_data;
924 task_args->on_setup = options->on_setup;
925 aws_task_init(task, s_aws_http_connection_manager_connect_task, task_args, "create_connection_task");
926
927 struct aws_event_loop *event_loop = aws_event_loop_group_get_next_loop(tester->event_loop_group);
928 uint64_t now;
929 ASSERT_SUCCESS(aws_event_loop_current_clock_time(event_loop, &now));
930 aws_event_loop_schedule_task_future(event_loop, task, now + 1000000000);
931 return AWS_OP_SUCCESS;
932 }
933
934 static void s_aws_http_connection_manager_release_connection_sync_mock(struct aws_http_connection *connection) {
935 (void)connection;
936
937 struct cm_tester *tester = &s_tester;
938
939 tester->release_connection_fn(connection, AWS_ERROR_SUCCESS, tester->connection_manager);
940 }
941
942 static void s_aws_http_connection_manager_close_connection_sync_mock(struct aws_http_connection *connection) {
943 (void)connection;
944 }
945
946 static bool s_aws_http_connection_manager_is_connection_available_sync_mock(
947 const struct aws_http_connection *connection) {
948 (void)connection;
949
950 struct mock_connection *proxy = (struct mock_connection *)(void *)connection;
951
952 return !proxy->is_closed_on_release;
953 }
954
955 static bool s_aws_http_connection_manager_is_callers_thread_sync_mock(struct aws_channel *channel) {
956 (void)channel;
957
958 return true;
959 }
960
961 static struct aws_channel *s_aws_http_connection_manager_connection_get_channel_sync_mock(
962 struct aws_http_connection *connection) {
963 (void)connection;
964
965 return (struct aws_channel *)1;
966 }
967
968 static enum aws_http_version s_aws_http_connection_manager_connection_get_version_sync_mock(
969 const struct aws_http_connection *connection) {
970 (void)connection;
971
972 return AWS_HTTP_VERSION_1_1;
973 }
974
975 static struct aws_http_connection_manager_system_vtable s_synchronous_mocks = {
976 .aws_http_client_connect = s_aws_http_connection_manager_create_connection_sync_mock,
977 .aws_http_connection_release = s_aws_http_connection_manager_release_connection_sync_mock,
978 .aws_http_connection_close = s_aws_http_connection_manager_close_connection_sync_mock,
979 .aws_http_connection_new_requests_allowed = s_aws_http_connection_manager_is_connection_available_sync_mock,
980 .aws_high_res_clock_get_ticks = aws_high_res_clock_get_ticks,
981 .aws_http_connection_get_channel = s_aws_http_connection_manager_connection_get_channel_sync_mock,
982 .aws_channel_thread_is_callers_thread = s_aws_http_connection_manager_is_callers_thread_sync_mock,
983 .aws_http_connection_get_version = s_aws_http_connection_manager_connection_get_version_sync_mock,
984 };
985
986 static struct aws_http_connection_manager_system_vtable s_async_connect_mock = {
987 .aws_http_client_connect = s_aws_http_connection_manager_connect_async_mock,
988 .aws_http_connection_release = s_aws_http_connection_manager_release_connection_sync_mock,
989 .aws_http_connection_close = s_aws_http_connection_manager_close_connection_sync_mock,
990 .aws_http_connection_new_requests_allowed = s_aws_http_connection_manager_is_connection_available_sync_mock,
991 .aws_high_res_clock_get_ticks = aws_high_res_clock_get_ticks,
992 .aws_http_connection_get_channel = s_aws_http_connection_manager_connection_get_channel_sync_mock,
993 .aws_channel_thread_is_callers_thread = s_aws_http_connection_manager_is_callers_thread_sync_mock,
994 .aws_http_connection_get_version = s_aws_http_connection_manager_connection_get_version_sync_mock,
995 };
996
997 static int s_test_connection_manager_with_network_interface_list(struct aws_allocator *allocator, void *ctx) {
998 (void)ctx;
999 struct aws_byte_cursor *interface_names_array = aws_mem_calloc(allocator, 3, sizeof(struct aws_byte_cursor));
1000 interface_names_array[0] = aws_byte_cursor_from_c_str("ens32");
1001 interface_names_array[1] = aws_byte_cursor_from_c_str("ens64");
1002 interface_names_array[2] = aws_byte_cursor_from_c_str("ens96");
1003
1004 struct cm_tester_options options = {
1005 .allocator = allocator,
1006 .max_connections = 20,
1007 .mock_table = &s_synchronous_mocks,
1008 .verify_network_interface_names_array = interface_names_array,
1009 };
1010
1011 ASSERT_SUCCESS(s_cm_tester_init(&options));
1012 size_t num_connections = 6;
1013 for (size_t i = 0; i < num_connections; ++i) {
1014 s_add_mock_connections(1, AWS_NCRT_SUCCESS, i % 1 == 0);
1015 }
1016 s_acquire_connections(num_connections);
1017
1018 ASSERT_SUCCESS(s_wait_on_connection_reply_count(num_connections));
1019 ASSERT_SUCCESS(s_release_connections(num_connections, false));
1020 ASSERT_UINT_EQUALS(0, s_tester.connection_errors);
1021
1022 ASSERT_SUCCESS(s_cm_tester_clean_up());
1023 aws_mem_release(allocator, interface_names_array);
1024 return AWS_OP_SUCCESS;
1025 }
1026 AWS_TEST_CASE(connection_manager_with_network_interface_list, s_test_connection_manager_with_network_interface_list);
1027
1028 static int s_test_connection_manager_acquire_release_mix_synchronous(struct aws_allocator *allocator, void *ctx) {
1029 (void)ctx;
1030
1031 struct cm_tester_options options = {
1032 .allocator = allocator,
1033 .max_connections = 5,
1034 .mock_table = &s_synchronous_mocks,
1035 };
1036
1037 ASSERT_SUCCESS(s_cm_tester_init(&options));
1038
1039 for (size_t i = 0; i < 20; ++i) {
1040 s_add_mock_connections(1, AWS_NCRT_SUCCESS, i % 1 == 0);
1041 }
1042
1043 for (size_t i = 0; i < 10; ++i) {
1044 s_acquire_connections(2);
1045
1046 ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
1047
1048 ASSERT_SUCCESS(s_release_connections(1, false));
1049 }
1050
1051 for (size_t i = 15; i < 20; ++i) {
1052 ASSERT_SUCCESS(s_release_connections(1, false));
1053
1054 ASSERT_SUCCESS(s_wait_on_connection_reply_count(i + 1));
1055 }
1056
1057 ASSERT_TRUE(s_tester.connection_errors == 0);
1058
1059 ASSERT_SUCCESS(s_cm_tester_clean_up());
1060
1061 return AWS_OP_SUCCESS;
1062 }
1063 AWS_TEST_CASE(
1064 connection_manager_acquire_release_mix_synchronous,
1065 s_test_connection_manager_acquire_release_mix_synchronous);
1066
1067 static int s_test_connection_manager_acquisition_timeout(struct aws_allocator *allocator, void *ctx) {
1068 (void)ctx;
1069
1070 size_t num_connections = 2;
1071 size_t num_pending_connections = 3;
1072 struct cm_tester_options options = {
1073 .allocator = allocator,
1074 .max_connections = num_connections,
1075 .mock_table = &s_synchronous_mocks,
1076 .connection_acquisition_timeout_ms = 1000,
1077 .starting_mock_time = 0,
1078 };
1079
1080 ASSERT_SUCCESS(s_cm_tester_init(&options));
1081
1082 s_add_mock_connections(num_connections, AWS_NCRT_SUCCESS, true);
1083 s_acquire_connections(num_connections + num_pending_connections);
1084
1085 /* advance fake time enough to cause the acquire connections to timeout, also sleep for real to give the cull task
1086 * a chance to run in the real event loop
1087 */
1088 uint64_t one_sec_in_nanos = aws_timestamp_convert(1, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL);
1089 s_tester_set_mock_time(2 * one_sec_in_nanos);
1090 aws_thread_current_sleep(2 * one_sec_in_nanos);
1091
1092 ASSERT_SUCCESS(s_wait_on_connection_reply_count(num_connections + num_pending_connections));
1093 ASSERT_UINT_EQUALS(num_pending_connections, s_tester.connection_errors);
1094 for (size_t i = 0; i < num_pending_connections; i++) {
1095 uint32_t error_code;
1096 aws_array_list_get_at(&s_tester.connection_errors_list, &error_code, i);
1097 ASSERT_UINT_EQUALS(AWS_ERROR_HTTP_CONNECTION_MANAGER_ACQUISITION_TIMEOUT, error_code);
1098 }
1099 ASSERT_SUCCESS(s_release_connections(num_connections, false));
1100
1101 ASSERT_SUCCESS(s_cm_tester_clean_up());
1102
1103 return AWS_OP_SUCCESS;
1104 }
1105 AWS_TEST_CASE(connection_manager_acquisition_timeout, s_test_connection_manager_acquisition_timeout);
1106
1107 static int s_test_connection_manager_connect_callback_failure(struct aws_allocator *allocator, void *ctx) {
1108 (void)ctx;
1109
1110 struct cm_tester_options options = {
1111 .allocator = allocator,
1112 .max_connections = 5,
1113 .mock_table = &s_synchronous_mocks,
1114 };
1115
1116 ASSERT_SUCCESS(s_cm_tester_init(&options));
1117
1118 s_add_mock_connections(5, AWS_NCRT_ERROR_VIA_CALLBACK, false);
1119
1120 s_acquire_connections(5);
1121
1122 ASSERT_SUCCESS(s_wait_on_connection_reply_count(5));
1123
1124 ASSERT_TRUE(s_tester.connection_errors == 5);
1125
1126 ASSERT_SUCCESS(s_cm_tester_clean_up());
1127
1128 return AWS_OP_SUCCESS;
1129 }
1130 AWS_TEST_CASE(connection_manager_connect_callback_failure, s_test_connection_manager_connect_callback_failure);
1131
1132 static int s_test_connection_manager_connect_callback_async_failure(struct aws_allocator *allocator, void *ctx) {
1133 (void)ctx;
1134 int error_connections = 5;
1135 int success_connections = 5;
1136 struct cm_tester_options options = {
1137 .allocator = allocator,
1138 .max_connections = error_connections,
1139 .mock_table = &s_async_connect_mock,
1140 };
1141
1142 ASSERT_SUCCESS(s_cm_tester_init(&options));
1143
1144 s_add_mock_connections(error_connections, AWS_NCRT_ERROR_VIA_CALLBACK, false);
1145 s_add_mock_connections(success_connections, AWS_NCRT_SUCCESS, true);
1146
1147 s_acquire_connections(error_connections + success_connections);
1148
1149 ASSERT_SUCCESS(s_wait_on_connection_reply_count(error_connections + success_connections));
1150
1151 ASSERT_UINT_EQUALS(s_tester.connection_errors, error_connections);
1152 ASSERT_SUCCESS(s_release_connections(success_connections, false));
1153
1154 ASSERT_SUCCESS(s_cm_tester_clean_up());
1155
1156 return AWS_OP_SUCCESS;
1157 }
1158 AWS_TEST_CASE(
1159 test_connection_manager_connect_callback_async_failure,
1160 s_test_connection_manager_connect_callback_async_failure);
1161
1162 static int s_test_connection_manager_connect_callback_async_with_immediate_failure(
1163 struct aws_allocator *allocator,
1164 void *ctx) {
1165 (void)ctx;
1166 int error_connections = 5;
1167 int success_connections = 5;
1168 struct cm_tester_options options = {
1169 .allocator = allocator,
1170 .max_connections = error_connections + success_connections,
1171 .mock_table = &s_async_connect_mock,
1172 };
1173
1174 ASSERT_SUCCESS(s_cm_tester_init(&options));
1175
1176 s_add_mock_connections(success_connections, AWS_NCRT_SUCCESS, true);
1177 s_add_mock_connections(error_connections, AWS_NCRT_ERROR_VIA_CALLBACK, false);
1178
1179 s_acquire_connections(error_connections + success_connections);
1180
1181 ASSERT_SUCCESS(s_wait_on_connection_reply_count(error_connections + success_connections));
1182
1183 ASSERT_UINT_EQUALS(s_tester.connection_errors, error_connections);
1184 ASSERT_SUCCESS(s_release_connections(success_connections, false));
1185
1186 ASSERT_SUCCESS(s_cm_tester_clean_up());
1187
1188 return AWS_OP_SUCCESS;
1189 }
1190 AWS_TEST_CASE(
1191 test_connection_manager_connect_callback_async_with_immediate_failure,
1192 s_test_connection_manager_connect_callback_async_with_immediate_failure);
1193
1194 static int s_test_connection_manager_connect_immediate_failure(struct aws_allocator *allocator, void *ctx) {
1195 (void)ctx;
1196
1197 struct cm_tester_options options = {
1198 .allocator = allocator,
1199 .max_connections = 5,
1200 .mock_table = &s_synchronous_mocks,
1201 };
1202
1203 ASSERT_SUCCESS(s_cm_tester_init(&options));
1204
1205 s_add_mock_connections(5, AWS_NCRT_ERROR_FROM_CREATE, false);
1206
1207 s_acquire_connections(5);
1208
1209 ASSERT_SUCCESS(s_wait_on_connection_reply_count(5));
1210
1211 ASSERT_TRUE(s_tester.connection_errors == 5);
1212
1213 ASSERT_SUCCESS(s_cm_tester_clean_up());
1214
1215 return AWS_OP_SUCCESS;
1216 }
1217 AWS_TEST_CASE(connection_manager_connect_immediate_failure, s_test_connection_manager_connect_immediate_failure);
1218
1219 static int s_test_connection_manager_proxy_setup_shutdown(struct aws_allocator *allocator, void *ctx) {
1220 (void)ctx;
1221
1222 struct aws_http_proxy_options proxy_options = {
1223 .host = aws_byte_cursor_from_c_str("127.0.0.1"),
1224 .port = 3280,
1225 };
1226
1227 struct cm_tester_options options = {
1228 .allocator = allocator,
1229 .max_connections = 1,
1230 .mock_table = &s_synchronous_mocks,
1231 .proxy_options = &proxy_options,
1232 };
1233
1234 ASSERT_SUCCESS(s_cm_tester_init(&options));
1235
1236 ASSERT_SUCCESS(s_cm_tester_clean_up());
1237
1238 return AWS_OP_SUCCESS;
1239 }
1240 AWS_TEST_CASE(connection_manager_proxy_setup_shutdown, s_test_connection_manager_proxy_setup_shutdown);
1241
1242 static struct aws_http_connection_manager_system_vtable s_idle_mocks = {
1243 .aws_http_client_connect = s_aws_http_connection_manager_create_connection_sync_mock,
1244 .aws_http_connection_release = s_aws_http_connection_manager_release_connection_sync_mock,
1245 .aws_http_connection_close = s_aws_http_connection_manager_close_connection_sync_mock,
1246 .aws_http_connection_new_requests_allowed = s_aws_http_connection_manager_is_connection_available_sync_mock,
1247 .aws_high_res_clock_get_ticks = s_tester_get_mock_time,
1248 .aws_http_connection_get_channel = s_aws_http_connection_manager_connection_get_channel_sync_mock,
1249 .aws_channel_thread_is_callers_thread = s_aws_http_connection_manager_is_callers_thread_sync_mock,
1250 .aws_http_connection_get_version = s_aws_http_connection_manager_connection_get_version_sync_mock,
1251 };
1252
1253 static int s_register_acquired_connections(struct aws_array_list *seen_connections) {
1254 aws_mutex_lock(&s_tester.lock);
1255
1256 size_t acquired_count = aws_array_list_length(&s_tester.connections);
1257 for (size_t i = 0; i < acquired_count; ++i) {
1258 struct aws_http_connection *connection = NULL;
1259 aws_array_list_get_at(&s_tester.connections, &connection, i);
1260 aws_array_list_push_back(seen_connections, &connection);
1261 }
1262
1263 aws_mutex_unlock(&s_tester.lock);
1264
1265 return AWS_OP_SUCCESS;
1266 }
1267
1268 static size_t s_get_acquired_connections_seen_count(struct aws_array_list *seen_connections) {
1269 size_t actual_seen_count = 0;
1270 aws_mutex_lock(&s_tester.lock);
1271
1272 size_t seen_count = aws_array_list_length(seen_connections);
1273 size_t acquired_count = aws_array_list_length(&s_tester.connections);
1274 for (size_t i = 0; i < acquired_count; ++i) {
1275 struct aws_http_connection *acquired_connection = NULL;
1276 aws_array_list_get_at(&s_tester.connections, &acquired_connection, i);
1277
1278 for (size_t j = 0; j < seen_count; ++j) {
1279 struct aws_http_connection *seen_connection = NULL;
1280 aws_array_list_get_at(seen_connections, &seen_connection, j);
1281
1282 if (seen_connection == acquired_connection) {
1283 actual_seen_count++;
1284 }
1285 }
1286 }
1287
1288 aws_mutex_unlock(&s_tester.lock);
1289
1290 return actual_seen_count;
1291 }
1292
1293 static int s_test_connection_manager_idle_culling_single(struct aws_allocator *allocator, void *ctx) {
1294 (void)ctx;
1295
1296 struct aws_array_list seen_connections;
1297 AWS_ZERO_STRUCT(seen_connections);
1298 ASSERT_SUCCESS(aws_array_list_init_dynamic(&seen_connections, allocator, 10, sizeof(struct aws_http_connection *)));
1299
1300 uint64_t now = 0;
1301
1302 struct cm_tester_options options = {
1303 .allocator = allocator,
1304 .max_connections = 1,
1305 .mock_table = &s_idle_mocks,
1306 .max_connection_idle_in_ms = 1000,
1307 .starting_mock_time = now,
1308 };
1309
1310 ASSERT_SUCCESS(s_cm_tester_init(&options));
1311
1312 /* add enough fake connections to cover all the acquires */
1313 s_add_mock_connections(2, AWS_NCRT_SUCCESS, false);
1314
1315 /* acquire some connections */
1316 s_acquire_connections(1);
1317
1318 ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
1319
1320 /* remember what connections we acquired */
1321 s_register_acquired_connections(&seen_connections);
1322
1323 /* release the connections */
1324 s_release_connections(1, false);
1325
1326 /* advance fake time enough to cause the connections to be culled, also sleep for real to give the cull task
1327 * a chance to run in the real event loop
1328 */
1329 uint64_t one_sec_in_nanos = aws_timestamp_convert(1, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL);
1330 s_tester_set_mock_time(now + one_sec_in_nanos);
1331 aws_thread_current_sleep(2 * one_sec_in_nanos);
1332
1333 /* acquire some connections */
1334 s_acquire_connections(1);
1335 ASSERT_SUCCESS(s_wait_on_connection_reply_count(2));
1336
1337 /* make sure the connections acquired were not ones that we expected to cull */
1338 ASSERT_INT_EQUALS(s_get_acquired_connections_seen_count(&seen_connections), 0);
1339
1340 /* release everything and clean up */
1341 s_release_connections(1, false);
1342
1343 ASSERT_SUCCESS(s_cm_tester_clean_up());
1344
1345 aws_array_list_clean_up(&seen_connections);
1346
1347 return AWS_OP_SUCCESS;
1348 }
1349 AWS_TEST_CASE(connection_manager_idle_culling_single, s_test_connection_manager_idle_culling_single);
1350
1351 static int s_test_connection_manager_idle_culling_many(struct aws_allocator *allocator, void *ctx) {
1352 (void)ctx;
1353
1354 struct aws_array_list seen_connections;
1355 AWS_ZERO_STRUCT(seen_connections);
1356 ASSERT_SUCCESS(aws_array_list_init_dynamic(&seen_connections, allocator, 10, sizeof(struct aws_http_connection *)));
1357
1358 uint64_t now = 0;
1359
1360 struct cm_tester_options options = {
1361 .allocator = allocator,
1362 .max_connections = 5,
1363 .mock_table = &s_idle_mocks,
1364 .max_connection_idle_in_ms = 1000,
1365 .starting_mock_time = now,
1366 };
1367
1368 ASSERT_SUCCESS(s_cm_tester_init(&options));
1369
1370 /* add enough fake connections to cover all the acquires */
1371 s_add_mock_connections(10, AWS_NCRT_SUCCESS, false);
1372
1373 /* acquire some connections */
1374 s_acquire_connections(5);
1375
1376 ASSERT_SUCCESS(s_wait_on_connection_reply_count(5));
1377
1378 /* remember what connections we acquired */
1379 s_register_acquired_connections(&seen_connections);
1380
1381 /* release the connections */
1382 s_release_connections(5, false);
1383
1384 /* advance fake time enough to cause the connections to be culled, also sleep for real to give the cull task
1385 * a chance to run in the real event loop
1386 */
1387 uint64_t one_sec_in_nanos = aws_timestamp_convert(1, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL);
1388 s_tester_set_mock_time(now + one_sec_in_nanos);
1389 aws_thread_current_sleep(2 * one_sec_in_nanos);
1390
1391 /* acquire some connections */
1392 s_acquire_connections(5);
1393 ASSERT_SUCCESS(s_wait_on_connection_reply_count(10));
1394
1395 /* make sure the connections acquired were not ones that we expected to cull */
1396 ASSERT_INT_EQUALS(s_get_acquired_connections_seen_count(&seen_connections), 0);
1397
1398 /* release everything and clean up */
1399 s_release_connections(5, false);
1400
1401 ASSERT_SUCCESS(s_cm_tester_clean_up());
1402
1403 aws_array_list_clean_up(&seen_connections);
1404
1405 return AWS_OP_SUCCESS;
1406 }
1407 AWS_TEST_CASE(connection_manager_idle_culling_many, s_test_connection_manager_idle_culling_many);
1408
1409 static int s_test_connection_manager_idle_culling_mixture(struct aws_allocator *allocator, void *ctx) {
1410 (void)ctx;
1411
1412 struct aws_array_list seen_connections;
1413 AWS_ZERO_STRUCT(seen_connections);
1414 ASSERT_SUCCESS(aws_array_list_init_dynamic(&seen_connections, allocator, 10, sizeof(struct aws_http_connection *)));
1415
1416 uint64_t now = 0;
1417
1418 struct cm_tester_options options = {
1419 .allocator = allocator,
1420 .max_connections = 10,
1421 .mock_table = &s_idle_mocks,
1422 .max_connection_idle_in_ms = 1000,
1423 .starting_mock_time = now,
1424 };
1425
1426 ASSERT_SUCCESS(s_cm_tester_init(&options));
1427
1428 /* add enough fake connections to cover all the acquires */
1429 s_add_mock_connections(15, AWS_NCRT_SUCCESS, false);
1430
1431 /* acquire some connections */
1432 s_acquire_connections(10);
1433
1434 ASSERT_SUCCESS(s_wait_on_connection_reply_count(10));
1435
1436 /* remember what connections we acquired */
1437 s_register_acquired_connections(&seen_connections);
1438
1439 /*
1440 * release the connections
1441 * Previous tests created situations where the entire block of idle connections end up getting culled. We also
1442 * want to create a situation where just some of the connections get culled.
1443 */
1444 s_release_connections(5, false);
1445 s_tester_set_mock_time(now + 1);
1446 s_release_connections(5, false);
1447 s_tester_set_mock_time(now);
1448 uint64_t one_sec_in_nanos = aws_timestamp_convert(1, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL);
1449
1450 /*
1451 * advance fake time enough to cause half of the connections to be culled, also sleep for real to give the cull task
1452 * a chance to run in the real event loop.
1453 */
1454 s_tester_set_mock_time(now + one_sec_in_nanos);
1455 aws_thread_current_sleep(2 * one_sec_in_nanos);
1456
1457 /* acquire some connections */
1458 s_acquire_connections(10);
1459 ASSERT_SUCCESS(s_wait_on_connection_reply_count(20));
1460
1461 /* make sure the connections acquired are half old and half new */
1462 ASSERT_INT_EQUALS(s_get_acquired_connections_seen_count(&seen_connections), 5);
1463
1464 /* release everything and clean up */
1465 s_release_connections(10, false);
1466
1467 ASSERT_SUCCESS(s_cm_tester_clean_up());
1468
1469 aws_array_list_clean_up(&seen_connections);
1470
1471 return AWS_OP_SUCCESS;
1472 }
1473 AWS_TEST_CASE(connection_manager_idle_culling_mixture, s_test_connection_manager_idle_culling_mixture);
1474
1475 /**
1476 * Once upon time, if the culling test is running while the connection manager is shutting, the refcount will be messed
1477 * up (back from zero to one and trigger the destroy to happen twice)
1478 */
1479 static int s_test_connection_manager_idle_culling_refcount(struct aws_allocator *allocator, void *ctx) {
1480 (void)ctx;
1481
1482 aws_http_library_init(allocator);
1483 for (size_t i = 0; i < 10; i++) {
1484 /* To reproduce that more stable, repeat it 10 times. */
1485 struct cm_tester_options options = {
1486 .allocator = allocator,
1487 .max_connections = 10,
1488 .max_connection_idle_in_ms = 10,
1489 .self_lib_init = true,
1490 };
1491
1492 ASSERT_SUCCESS(s_cm_tester_init(&options));
1493
1494 uint64_t ten_ms_in_nanos = aws_timestamp_convert(10, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL);
1495
1496 /* Don't ask me how I got the number. :) */
1497 aws_thread_current_sleep(ten_ms_in_nanos - 10000);
1498
1499 ASSERT_SUCCESS(s_cm_tester_clean_up());
1500 }
1501 aws_http_library_clean_up();
1502 return AWS_OP_SUCCESS;
1503 }
1504
1505 AWS_TEST_CASE(connection_manager_idle_culling_refcount, s_test_connection_manager_idle_culling_refcount);
1506
1507 /**
1508 * Proxy integration tests. Maybe we should move this to another file. But let's do it later. Someday.
1509 * AWS_TEST_HTTP_PROXY_HOST - host address of the proxy to use for tests that make open connections to the proxy
1510 * AWS_TEST_HTTP_PROXY_PORT - port to use for tests that make open connections to the proxy
1511 * AWS_TEST_HTTP_PROXY_URL - whole URL to use for tests that make open connections to the proxy
1512 * AWS_TEST_HTTPS_PROXY_HOST - host address of the proxy to use for tests that make tls-protected connections to the
1513 * proxy
1514 * AWS_TEST_HTTPS_PROXY_PORT - port to use for tests that make tls-protected connections to the proxy
1515 * AWS_TEST_HTTPS_PROXY_URL - whole URL to use for tests that make tls-protected connections to the proxy
1516 * AWS_TEST_HTTP_PROXY_BASIC_HOST - host address of the proxy to use for tests that make open connections to the proxy
1517 * with basic authentication
1518 * AWS_TEST_HTTP_PROXY_BASIC_PORT - port to use for tests that make open connections to the proxy with basic
1519 * authentication
1520 * AWS_TEST_HTTP_PROXY_BASIC_URL - whole URL to use for tests that make open connections to the proxy with basic
1521 * authentication
1522 * AWS_TEST_BASIC_AUTH_USERNAME - username to use when using basic authentication to the proxy
1523 * AWS_TEST_BASIC_AUTH_PASSWORD - password to use when using basic authentication to the proxy
1524 *
1525 * AWS_TEST_TLS_CERT_PATH - file path to certificate used to initialize the tls context of the mqtt connection
1526 * AWS_TEST_TLS_KEY_PATH - file path to the key used to initialize the tls context of the mqtt connection
1527 * AWS_TEST_TLS_ROOT_CERT_PATH - file path to the root CA used to initialize the tls context of the mqtt connection
1528 */
1529
1530 struct proxy_integration_configurations {
1531 struct aws_string *http_proxy_host;
1532 struct aws_string *http_proxy_port;
1533 struct aws_string *http_proxy_url;
1534 struct aws_string *https_proxy_host;
1535 struct aws_string *https_proxy_port;
1536 struct aws_string *https_proxy_url;
1537 struct aws_string *http_proxy_basic_host;
1538 struct aws_string *http_proxy_basic_port;
1539 struct aws_string *http_proxy_basic_url;
1540 struct aws_string *basic_auth_username;
1541 struct aws_string *basic_auth_password;
1542 struct aws_string *tls_cert_path;
1543 struct aws_string *tls_key_path;
1544 struct aws_string *tls_root_cert_path;
1545 struct aws_string *https_proxy_host_h2;
1546 struct aws_string *https_proxy_port_h2;
1547 struct aws_string *https_proxy_url_h2;
1548 };
1549
1550 enum proxy_test_type {
1551 FORWARDING = 0,
1552 TUNNELING_HTTP = 1,
1553 TUNNELING_HTTPS = 2,
1554 TUNNELING_DOUBLE_TLS = 3,
1555 LEGACY_HTTP = 4,
1556 LEGACY_HTTPS = 5,
1557 };
1558
1559 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_host_env_var, "AWS_TEST_HTTP_PROXY_HOST");
1560 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_port_env_var, "AWS_TEST_HTTP_PROXY_PORT");
1561 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_url_env_var, "AWS_TEST_HTTP_PROXY_URL");
1562 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_host_env_var, "AWS_TEST_HTTPS_PROXY_HOST");
1563 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_port_env_var, "AWS_TEST_HTTPS_PROXY_PORT");
1564 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_url_env_var, "AWS_TEST_HTTPS_PROXY_URL");
1565 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_basic_host_env_var, "AWS_TEST_HTTP_PROXY_BASIC_HOST");
1566 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_basic_port_env_var, "AWS_TEST_HTTP_PROXY_BASIC_PORT");
1567 AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_basic_url_env_var, "AWS_TEST_HTTP_PROXY_BASIC_URL");
1568 AWS_STATIC_STRING_FROM_LITERAL(s_basic_auth_username_env_var, "AWS_TEST_BASIC_AUTH_USERNAME");
1569 AWS_STATIC_STRING_FROM_LITERAL(s_basic_auth_password_env_var, "AWS_TEST_BASIC_AUTH_PASSWORD");
1570 AWS_STATIC_STRING_FROM_LITERAL(s_tls_cert_path_env_var, "AWS_TEST_TLS_CERT_PATH");
1571 AWS_STATIC_STRING_FROM_LITERAL(s_tls_key_path_env_var, "AWS_TEST_TLS_KEY_PATH");
1572 AWS_STATIC_STRING_FROM_LITERAL(s_tls_root_cert_path_env_var, "AWS_TEST_TLS_ROOT_CERT_PATH");
1573 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_host_h2_env_var, "AWS_TEST_HTTPS_H2_PROXY_HOST");
1574 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_port_h2_env_var, "AWS_TEST_HTTPS_H2_PROXY_PORT");
1575 AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_url_h2_env_var, "AWS_TEST_HTTPS_H2_PROXY_URL");
1576
1577 static int s_get_proxy_environment_configurations(
1578 struct aws_allocator *allocator,
1579 struct proxy_integration_configurations *configs) {
1580 /* get the envrionment configurations, and fail if any one is not set */
1581 if (aws_get_environment_value(allocator, s_http_proxy_host_env_var, &configs->http_proxy_host) ||
1582 configs->http_proxy_host == NULL) {
1583 return AWS_OP_ERR;
1584 }
1585 if (aws_get_environment_value(allocator, s_http_proxy_port_env_var, &configs->http_proxy_port) ||
1586 configs->http_proxy_port == NULL) {
1587 return AWS_OP_ERR;
1588 }
1589 if (aws_get_environment_value(allocator, s_http_proxy_url_env_var, &configs->http_proxy_url) ||
1590 configs->http_proxy_url == NULL) {
1591 return AWS_OP_ERR;
1592 }
1593 if (aws_get_environment_value(allocator, s_https_proxy_host_env_var, &configs->https_proxy_host) ||
1594 configs->https_proxy_host == NULL) {
1595 return AWS_OP_ERR;
1596 }
1597 if (aws_get_environment_value(allocator, s_https_proxy_port_env_var, &configs->https_proxy_port) ||
1598 configs->https_proxy_port == NULL) {
1599 return AWS_OP_ERR;
1600 }
1601 if (aws_get_environment_value(allocator, s_https_proxy_url_env_var, &configs->https_proxy_url) ||
1602 configs->https_proxy_url == NULL) {
1603 return AWS_OP_ERR;
1604 }
1605 if (aws_get_environment_value(allocator, s_http_proxy_basic_host_env_var, &configs->http_proxy_basic_host) ||
1606 configs->http_proxy_basic_host == NULL) {
1607 return AWS_OP_ERR;
1608 }
1609 if (aws_get_environment_value(allocator, s_http_proxy_basic_port_env_var, &configs->http_proxy_basic_port) ||
1610 configs->http_proxy_basic_port == NULL) {
1611 return AWS_OP_ERR;
1612 }
1613 if (aws_get_environment_value(allocator, s_http_proxy_basic_url_env_var, &configs->http_proxy_basic_url) ||
1614 configs->http_proxy_basic_url == NULL) {
1615 return AWS_OP_ERR;
1616 }
1617 if (aws_get_environment_value(allocator, s_basic_auth_username_env_var, &configs->basic_auth_username) ||
1618 configs->basic_auth_username == NULL) {
1619 return AWS_OP_ERR;
1620 }
1621 if (aws_get_environment_value(allocator, s_basic_auth_password_env_var, &configs->basic_auth_password) ||
1622 configs->basic_auth_password == NULL) {
1623 return AWS_OP_ERR;
1624 }
1625 if (aws_get_environment_value(allocator, s_tls_cert_path_env_var, &configs->tls_cert_path) ||
1626 configs->tls_cert_path == NULL) {
1627 return AWS_OP_ERR;
1628 }
1629 if (aws_get_environment_value(allocator, s_tls_key_path_env_var, &configs->tls_key_path) ||
1630 configs->tls_key_path == NULL) {
1631 return AWS_OP_ERR;
1632 }
1633 if (aws_get_environment_value(allocator, s_tls_root_cert_path_env_var, &configs->tls_root_cert_path) ||
1634 configs->tls_root_cert_path == NULL) {
1635 return AWS_OP_ERR;
1636 }
1637 if (aws_get_environment_value(allocator, s_https_proxy_host_h2_env_var, &configs->https_proxy_host_h2) ||
1638 configs->https_proxy_host_h2 == NULL) {
1639 return AWS_OP_ERR;
1640 }
1641 if (aws_get_environment_value(allocator, s_https_proxy_port_h2_env_var, &configs->https_proxy_port_h2) ||
1642 configs->https_proxy_port_h2 == NULL) {
1643 return AWS_OP_ERR;
1644 }
1645 if (aws_get_environment_value(allocator, s_https_proxy_url_h2_env_var, &configs->https_proxy_url_h2) ||
1646 configs->https_proxy_url_h2 == NULL) {
1647 return AWS_OP_ERR;
1648 }
1649 return AWS_OP_SUCCESS;
1650 }
1651
1652 static void s_proxy_environment_configurations_clean_up(struct proxy_integration_configurations *configs) {
1653 aws_string_destroy(configs->http_proxy_host);
1654 aws_string_destroy(configs->http_proxy_port);
1655 aws_string_destroy(configs->http_proxy_url);
1656 aws_string_destroy(configs->https_proxy_host);
1657 aws_string_destroy(configs->https_proxy_port);
1658 aws_string_destroy(configs->https_proxy_url);
1659 aws_string_destroy(configs->http_proxy_basic_host);
1660 aws_string_destroy(configs->http_proxy_basic_port);
1661 aws_string_destroy(configs->http_proxy_basic_url);
1662 aws_string_destroy(configs->basic_auth_username);
1663 aws_string_destroy(configs->basic_auth_password);
1664 aws_string_destroy(configs->tls_cert_path);
1665 aws_string_destroy(configs->tls_key_path);
1666 aws_string_destroy(configs->tls_root_cert_path);
1667 aws_string_destroy(configs->https_proxy_host_h2);
1668 aws_string_destroy(configs->https_proxy_port_h2);
1669 aws_string_destroy(configs->https_proxy_url_h2);
1670 }
1671
1672 static int s_response_status_code = 0;
1673 static bool s_is_proxy_request_complete(void *context) {
1674 (void)context;
1675
1676 struct cm_tester *tester = &s_tester;
1677
1678 return tester->proxy_request_complete;
1679 }
1680
1681 static int s_wait_on_proxy_request_complete(void) {
1682 struct cm_tester *tester = &s_tester;
1683
1684 ASSERT_SUCCESS(aws_mutex_lock(&tester->lock));
1685
1686 int signal_error =
1687 aws_condition_variable_wait_pred(&tester->signal, &tester->lock, s_is_proxy_request_complete, tester);
1688
1689 ASSERT_SUCCESS(aws_mutex_unlock(&tester->lock));
1690 return signal_error;
1691 }
1692
1693 static int s_aws_http_on_incoming_header_block_done_proxy_test(
1694 struct aws_http_stream *stream,
1695 enum aws_http_header_block header_block,
1696 void *user_data) {
1697 (void)header_block;
1698 (void)user_data;
1699
1700 struct cm_tester *tester = &s_tester;
1701 if (aws_http_stream_get_incoming_response_status(stream, &s_response_status_code) == AWS_OP_SUCCESS) {
1702 aws_mutex_lock(&tester->lock);
1703 tester->proxy_request_successful = s_response_status_code / 100 == 2;
1704 aws_mutex_unlock(&tester->lock);
1705 }
1706
1707 return AWS_OP_SUCCESS;
1708 }
1709
1710 static void s_aws_http_on_stream_complete_proxy_test(struct aws_http_stream *stream, int error_code, void *user_data) {
1711 (void)stream;
1712 (void)error_code;
1713 (void)user_data;
1714
1715 struct cm_tester *tester = &s_tester;
1716
1717 aws_mutex_lock(&tester->lock);
1718 tester->proxy_request_complete = true;
1719 aws_condition_variable_notify_one(&tester->signal);
1720 aws_mutex_unlock(&tester->lock);
1721 }
1722
1723 static struct aws_byte_cursor s_get_proxy_host_for_test(
1724 struct proxy_integration_configurations *configs,
1725 enum proxy_test_type proxy_test_type,
1726 enum aws_http_proxy_authentication_type auth_type,
1727 bool h2) {
1728 struct aws_string *host_string;
1729 if (h2) {
1730 host_string = configs->https_proxy_host;
1731 } else if (auth_type == AWS_HPAT_BASIC) {
1732 host_string = configs->http_proxy_basic_host;
1733 } else if (proxy_test_type == TUNNELING_DOUBLE_TLS) {
1734 host_string = configs->https_proxy_host;
1735 } else {
1736 host_string = configs->http_proxy_host;
1737 }
1738 return aws_byte_cursor_from_string(host_string);
1739 }
1740
1741 static uint32_t s_get_proxy_port_for_test(
1742 struct proxy_integration_configurations *configs,
1743 enum proxy_test_type proxy_test_type,
1744 enum aws_http_proxy_authentication_type auth_type,
1745 bool h2) {
1746 struct aws_string *port_string;
1747 if (h2) {
1748 port_string = configs->https_proxy_port_h2;
1749 } else if (auth_type == AWS_HPAT_BASIC) {
1750 port_string = configs->http_proxy_basic_port;
1751 } else if (proxy_test_type == TUNNELING_DOUBLE_TLS) {
1752 port_string = configs->https_proxy_port;
1753 } else {
1754 port_string = configs->http_proxy_port;
1755 }
1756 return (uint32_t)atoi(aws_string_c_str(port_string));
1757 }
1758 static struct aws_string *s_get_proxy_url_for_test(
1759 struct proxy_integration_configurations *configs,
1760 enum proxy_test_type proxy_test_type,
1761 enum aws_http_proxy_authentication_type auth_type) {
1762 if (auth_type == AWS_HPAT_BASIC) {
1763 return configs->http_proxy_basic_url;
1764 }
1765 if (proxy_test_type == TUNNELING_DOUBLE_TLS) {
1766 return configs->https_proxy_url;
1767 }
1768 return configs->http_proxy_url;
1769 }
1770 static int s_get_proxy_connection_type_for_test(enum proxy_test_type proxy_test_type) {
1771 if (proxy_test_type == FORWARDING) {
1772 return AWS_HPCT_HTTP_FORWARD;
1773 }
1774 if (proxy_test_type == TUNNELING_DOUBLE_TLS || proxy_test_type == TUNNELING_HTTP ||
1775 proxy_test_type == TUNNELING_HTTPS) {
1776 return AWS_HPCT_HTTP_TUNNEL;
1777 }
1778 return AWS_HPCT_HTTP_LEGACY;
1779 }
1780
1781 static bool s_get_use_tls_from_proxy_test_type(enum proxy_test_type test_type) {
1782 if (test_type == FORWARDING || test_type == LEGACY_HTTP || test_type == TUNNELING_HTTP) {
1783 return false;
1784 }
1785 return true;
1786 }
1787
1788 static int s_get_tls_options_from_proxy_test_type(
1789 struct aws_allocator *allocator,
1790 enum proxy_test_type proxy_test_type,
1791 struct aws_tls_connection_options *proxy_tls_options,
1792 struct aws_byte_cursor host_name) {
1793 if (proxy_test_type == TUNNELING_DOUBLE_TLS) {
1794 struct aws_tls_ctx *tls_ctx = NULL;
1795 struct aws_tls_ctx_options tls_ctx_options;
1796 AWS_ZERO_STRUCT(tls_ctx_options);
1797 /* create a default tls options */
1798 aws_tls_ctx_options_init_default_client(&tls_ctx_options, allocator);
1799 aws_tls_ctx_options_set_verify_peer(&tls_ctx_options, false);
1800 tls_ctx = aws_tls_client_ctx_new(allocator, &tls_ctx_options);
1801 aws_tls_ctx_options_clean_up(&tls_ctx_options);
1802 if (!tls_ctx) {
1803 return AWS_OP_ERR;
1804 }
1805 aws_tls_connection_options_init_from_ctx(proxy_tls_options, tls_ctx);
1806 /* tls options hold a ref to the ctx */
1807 aws_tls_ctx_release(tls_ctx);
1808 if (aws_tls_connection_options_set_server_name(proxy_tls_options, allocator, &host_name)) {
1809 return AWS_OP_ERR;
1810 }
1811 }
1812 return AWS_OP_SUCCESS;
1813 }
1814
1815 static int s_proxy_integration_test_helper_general(
1816 struct aws_allocator *allocator,
1817 enum proxy_test_type proxy_test_type,
1818 enum aws_http_proxy_authentication_type auth_type,
1819 bool use_env,
1820 bool configured_tls,
1821 bool h2) {
1822 aws_http_library_init(allocator);
1823 struct proxy_integration_configurations configs;
1824 AWS_ZERO_STRUCT(configs);
1825 ASSERT_SUCCESS(s_get_proxy_environment_configurations(allocator, &configs));
1826 /* not creating new strings */
1827 struct aws_tls_connection_options proxy_tls_options;
1828 AWS_ZERO_STRUCT(proxy_tls_options);
1829 ASSERT_SUCCESS(s_get_tls_options_from_proxy_test_type(
1830 allocator,
1831 proxy_test_type,
1832 &proxy_tls_options,
1833 s_get_proxy_host_for_test(&configs, proxy_test_type, auth_type, h2)));
1834 struct aws_http_proxy_options proxy_options = {
1835 .host = s_get_proxy_host_for_test(&configs, proxy_test_type, auth_type, h2),
1836 .port = s_get_proxy_port_for_test(&configs, proxy_test_type, auth_type, h2),
1837 .connection_type = s_get_proxy_connection_type_for_test(proxy_test_type),
1838 .tls_options = proxy_test_type == TUNNELING_DOUBLE_TLS ? &proxy_tls_options : NULL,
1839 .auth_type = auth_type,
1840 .auth_username = aws_byte_cursor_from_string(configs.basic_auth_username),
1841 .auth_password = aws_byte_cursor_from_string(configs.basic_auth_password),
1842 };
1843 if (use_env) {
1844 /* set the environment variables */
1845 struct aws_string *proxy_url = s_get_proxy_url_for_test(&configs, proxy_test_type, auth_type);
1846 ASSERT_SUCCESS(aws_set_environment_value(s_http_proxy_env_var, proxy_url));
1847 ASSERT_SUCCESS(aws_set_environment_value(s_https_proxy_env_var, proxy_url));
1848 }
1849
1850 struct cm_tester_options options = {
1851 .allocator = allocator,
1852 .max_connections = 5,
1853 .use_proxy_env = use_env,
1854 .env_configured_tls = configured_tls ? &proxy_tls_options : NULL,
1855 .proxy_options = use_env ? NULL : &proxy_options,
1856 .use_tls = s_get_use_tls_from_proxy_test_type(proxy_test_type),
1857 .self_lib_init = true,
1858 };
1859
1860 struct aws_http2_setting settings_array[] = {
1861 {
1862 .id = AWS_HTTP2_SETTINGS_ENABLE_PUSH,
1863 .value = 0,
1864 },
1865 };
1866
1867 if (h2) {
1868 options.http2 = true;
1869 options.initial_settings_array = settings_array;
1870 options.num_initial_settings = AWS_ARRAY_SIZE(settings_array);
1871 }
1872
1873 ASSERT_SUCCESS(s_cm_tester_init(&options));
1874
1875 s_acquire_connections(1);
1876
1877 ASSERT_SUCCESS(s_wait_on_connection_reply_count(1));
1878
1879 /* Have a connection now, need to make a request and verify the request made successfully */
1880 struct aws_http_message *request = aws_http_message_new_request(allocator);
1881 aws_http_message_set_request_method(request, aws_byte_cursor_from_c_str("GET"));
1882 aws_http_message_set_request_path(request, aws_byte_cursor_from_c_str("/"));
1883
1884 struct aws_http_header host_header = {
1885 .name = aws_byte_cursor_from_c_str("Host"),
1886 .value = aws_byte_cursor_from_c_str("www.google.com"),
1887 };
1888 aws_http_message_add_header(request, host_header);
1889
1890 struct aws_http_header accept_header = {
1891 .name = aws_byte_cursor_from_c_str("Accept"),
1892 .value = aws_byte_cursor_from_c_str("*/*"),
1893 };
1894 aws_http_message_add_header(request, accept_header);
1895
1896 struct aws_http_make_request_options request_options = {
1897 .self_size = sizeof(request_options),
1898 .request = request,
1899 .user_data = &s_tester,
1900 .on_response_header_block_done = s_aws_http_on_incoming_header_block_done_proxy_test,
1901 .on_complete = s_aws_http_on_stream_complete_proxy_test,
1902 };
1903 struct aws_http_connection *connection = NULL;
1904 ASSERT_SUCCESS(aws_array_list_front(&s_tester.connections, &connection));
1905 struct aws_http_stream *stream = aws_http_connection_make_request(connection, &request_options);
1906 ASSERT_NOT_NULL(stream);
1907 aws_http_stream_activate(stream);
1908
1909 ASSERT_SUCCESS(s_wait_on_proxy_request_complete());
1910 ASSERT_TRUE(s_response_status_code / 100 == 2);
1911
1912 aws_http_stream_release(stream);
1913 aws_http_message_destroy(request);
1914 aws_tls_connection_options_clean_up(&proxy_tls_options);
1915 s_proxy_environment_configurations_clean_up(&configs);
1916 ASSERT_SUCCESS(s_release_connections(1, false));
1917
1918 ASSERT_SUCCESS(s_cm_tester_clean_up());
1919 aws_http_library_clean_up();
1920
1921 return AWS_OP_SUCCESS;
1922 }
1923
1924 static int s_proxy_integration_test_helper(
1925 struct aws_allocator *allocator,
1926 enum proxy_test_type proxy_test_type,
1927 enum aws_http_proxy_authentication_type auth_type,
1928 bool use_env,
1929 bool configured_tls) {
1930 return s_proxy_integration_test_helper_general(
1931 allocator, proxy_test_type, auth_type, use_env, configured_tls, false);
1932 }
1933
1934 static int s_test_connection_manager_proxy_integration_forwarding_proxy_no_auth(
1935 struct aws_allocator *allocator,
1936 void *ctx) {
1937 (void)ctx;
1938 return s_proxy_integration_test_helper(
1939 allocator, FORWARDING, AWS_HPAT_NONE, false /*use_env*/, false /*configured_tls*/);
1940 }
1941 AWS_TEST_CASE(
1942 connection_manager_proxy_integration_forwarding_proxy_no_auth,
1943 s_test_connection_manager_proxy_integration_forwarding_proxy_no_auth);
1944
1945 static int s_test_connection_manager_proxy_integration_forwarding_proxy_no_auth_env(
1946 struct aws_allocator *allocator,
1947 void *ctx) {
1948 (void)ctx;
1949 return s_proxy_integration_test_helper(
1950 allocator, FORWARDING, AWS_HPAT_NONE, true /*use_env*/, false /*configured_tls*/);
1951 }
1952 AWS_TEST_CASE(
1953 connection_manager_proxy_integration_forwarding_proxy_no_auth_env,
1954 s_test_connection_manager_proxy_integration_forwarding_proxy_no_auth_env);
1955
1956 static int s_test_connection_manager_proxy_integration_legacy_http_no_auth(struct aws_allocator *allocator, void *ctx) {
1957 (void)ctx;
1958 return s_proxy_integration_test_helper(
1959 allocator, LEGACY_HTTP, AWS_HPAT_NONE, false /*use_env*/, false /*configured_tls*/);
1960 }
1961 AWS_TEST_CASE(
1962 connection_manager_proxy_integration_legacy_http_no_auth,
1963 s_test_connection_manager_proxy_integration_legacy_http_no_auth);
1964
1965 static int s_test_connection_manager_proxy_integration_legacy_http_no_auth_env(
1966 struct aws_allocator *allocator,
1967 void *ctx) {
1968 (void)ctx;
1969 return s_proxy_integration_test_helper(
1970 allocator, LEGACY_HTTP, AWS_HPAT_NONE, true /*use_env*/, false /*configured_tls*/);
1971 }
1972 AWS_TEST_CASE(
1973 connection_manager_proxy_integration_legacy_http_no_auth_env,
1974 s_test_connection_manager_proxy_integration_legacy_http_no_auth_env);
1975
1976 static int s_test_connection_manager_proxy_integration_legacy_https_no_auth(
1977 struct aws_allocator *allocator,
1978 void *ctx) {
1979 (void)ctx;
1980 return s_proxy_integration_test_helper(
1981 allocator, LEGACY_HTTPS, AWS_HPAT_NONE, false /*use_env*/, false /*configured_tls*/);
1982 }
1983 AWS_TEST_CASE(
1984 connection_manager_proxy_integration_legacy_https_no_auth,
1985 s_test_connection_manager_proxy_integration_legacy_https_no_auth);
1986
1987 static int s_test_connection_manager_proxy_integration_legacy_https_no_auth_env(
1988 struct aws_allocator *allocator,
1989 void *ctx) {
1990 (void)ctx;
1991 return s_proxy_integration_test_helper(
1992 allocator, LEGACY_HTTPS, AWS_HPAT_NONE, true /*use_env*/, false /*configured_tls*/);
1993 }
1994 AWS_TEST_CASE(
1995 connection_manager_proxy_integration_legacy_https_no_auth_env,
1996 s_test_connection_manager_proxy_integration_legacy_https_no_auth_env);
1997
1998 static int s_test_connection_manager_proxy_integration_tunneling_proxy_http_no_auth(
1999 struct aws_allocator *allocator,
2000 void *ctx) {
2001 (void)ctx;
2002 return s_proxy_integration_test_helper(
2003 allocator, TUNNELING_HTTP, AWS_HPAT_NONE, false /*use_env*/, false /*configured_tls*/);
2004 }
2005 AWS_TEST_CASE(
2006 connection_manager_proxy_integration_tunneling_proxy_http_no_auth,
2007 s_test_connection_manager_proxy_integration_tunneling_proxy_http_no_auth);
2008
2009 static int s_test_connection_manager_proxy_integration_tunneling_proxy_http_no_auth_env(
2010 struct aws_allocator *allocator,
2011 void *ctx) {
2012 (void)ctx;
2013 return s_proxy_integration_test_helper(
2014 allocator, TUNNELING_HTTP, AWS_HPAT_NONE, true /*use_env*/, false /*configured_tls*/);
2015 }
2016 AWS_TEST_CASE(
2017 connection_manager_proxy_integration_tunneling_proxy_http_no_auth_env,
2018 s_test_connection_manager_proxy_integration_tunneling_proxy_http_no_auth_env);
2019
2020 static int s_test_connection_manager_proxy_integration_tunneling_proxy_https_no_auth(
2021 struct aws_allocator *allocator,
2022 void *ctx) {
2023 (void)ctx;
2024 return s_proxy_integration_test_helper(
2025 allocator, TUNNELING_HTTPS, AWS_HPAT_NONE, false /*use_env*/, false /*configured_tls*/);
2026 }
2027 AWS_TEST_CASE(
2028 connection_manager_proxy_integration_tunneling_proxy_https_no_auth,
2029 s_test_connection_manager_proxy_integration_tunneling_proxy_https_no_auth);
2030
2031 static int s_test_connection_manager_proxy_integration_tunneling_proxy_https_no_auth_env(
2032 struct aws_allocator *allocator,
2033 void *ctx) {
2034 (void)ctx;
2035 return s_proxy_integration_test_helper(
2036 allocator, TUNNELING_HTTPS, AWS_HPAT_NONE, true /*use_env*/, false /*configured_tls*/);
2037 }
2038 AWS_TEST_CASE(
2039 connection_manager_proxy_integration_tunneling_proxy_https_no_auth_env,
2040 s_test_connection_manager_proxy_integration_tunneling_proxy_https_no_auth_env);
2041
2042 static int s_test_connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth(
2043 struct aws_allocator *allocator,
2044 void *ctx) {
2045 (void)ctx;
2046 return s_proxy_integration_test_helper(
2047 allocator, TUNNELING_DOUBLE_TLS, AWS_HPAT_NONE, false /*use_env*/, false /*configured_tls*/);
2048 }
2049 AWS_TEST_CASE(
2050 connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth,
2051 s_test_connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth);
2052
2053 static int s_test_connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_env(
2054 struct aws_allocator *allocator,
2055 void *ctx) {
2056 (void)ctx;
2057 return s_proxy_integration_test_helper(
2058 allocator, TUNNELING_DOUBLE_TLS, AWS_HPAT_NONE, true /*use_env*/, false /*configured_tls*/);
2059 }
2060 AWS_TEST_CASE(
2061 connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_env,
2062 s_test_connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_env);
2063
2064 static int s_test_connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_configured_tls_env(
2065 struct aws_allocator *allocator,
2066 void *ctx) {
2067 /* TLS set from settings instead of creating temporary one */
2068 (void)ctx;
2069 return s_proxy_integration_test_helper(
2070 allocator, TUNNELING_DOUBLE_TLS, AWS_HPAT_NONE, true /*use_env*/, true /*configured_tls*/);
2071 }
2072 AWS_TEST_CASE(
2073 connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_configured_tls_env,
2074 s_test_connection_manager_proxy_integration_tunneling_proxy_double_tls_no_auth_configured_tls_env);
2075
2076 static int s_test_connection_manager_proxy_integration_forwarding_proxy_basic_auth(
2077 struct aws_allocator *allocator,
2078 void *ctx) {
2079 (void)ctx;
2080 return s_proxy_integration_test_helper(
2081 allocator, FORWARDING, AWS_HPAT_BASIC, false /*use_env*/, false /*configured_tls*/);
2082 }
2083 AWS_TEST_CASE(
2084 connection_manager_proxy_integration_forwarding_proxy_basic_auth,
2085 s_test_connection_manager_proxy_integration_forwarding_proxy_basic_auth);
2086
2087 static int s_test_connection_manager_proxy_integration_forwarding_proxy_basic_auth_env(
2088 struct aws_allocator *allocator,
2089 void *ctx) {
2090 (void)ctx;
2091 return s_proxy_integration_test_helper(
2092 allocator, FORWARDING, AWS_HPAT_BASIC, true /*use_env*/, false /*configured_tls*/);
2093 }
2094 AWS_TEST_CASE(
2095 connection_manager_proxy_integration_forwarding_proxy_basic_auth_env,
2096 s_test_connection_manager_proxy_integration_forwarding_proxy_basic_auth_env);
2097
2098 static int s_test_connection_manager_proxy_integration_legacy_http_basic_auth(
2099 struct aws_allocator *allocator,
2100 void *ctx) {
2101 (void)ctx;
2102 return s_proxy_integration_test_helper(
2103 allocator, LEGACY_HTTP, AWS_HPAT_BASIC, false /*use_env*/, false /*configured_tls*/);
2104 }
2105 AWS_TEST_CASE(
2106 connection_manager_proxy_integration_legacy_http_basic_auth,
2107 s_test_connection_manager_proxy_integration_legacy_http_basic_auth);
2108
2109 static int s_test_connection_manager_proxy_integration_legacy_http_basic_auth_env(
2110 struct aws_allocator *allocator,
2111 void *ctx) {
2112 (void)ctx;
2113 return s_proxy_integration_test_helper(
2114 allocator, LEGACY_HTTP, AWS_HPAT_BASIC, true /*use_env*/, false /*configured_tls*/);
2115 }
2116 AWS_TEST_CASE(
2117 connection_manager_proxy_integration_legacy_http_basic_auth_env,
2118 s_test_connection_manager_proxy_integration_legacy_http_basic_auth_env);
2119
2120 static int s_test_connection_manager_proxy_integration_legacy_https_basic_auth(
2121 struct aws_allocator *allocator,
2122 void *ctx) {
2123 (void)ctx;
2124 return s_proxy_integration_test_helper(
2125 allocator, LEGACY_HTTPS, AWS_HPAT_BASIC, false /*use_env*/, false /*configured_tls*/);
2126 }
2127 AWS_TEST_CASE(
2128 connection_manager_proxy_integration_legacy_https_basic_auth,
2129 s_test_connection_manager_proxy_integration_legacy_https_basic_auth);
2130
2131 static int s_test_connection_manager_proxy_integration_legacy_https_basic_auth_env(
2132 struct aws_allocator *allocator,
2133 void *ctx) {
2134 (void)ctx;
2135 return s_proxy_integration_test_helper(
2136 allocator, LEGACY_HTTPS, AWS_HPAT_BASIC, true /*use_env*/, false /*configured_tls*/);
2137 }
2138 AWS_TEST_CASE(
2139 connection_manager_proxy_integration_legacy_https_basic_auth_env,
2140 s_test_connection_manager_proxy_integration_legacy_https_basic_auth_env);
2141
2142 static int s_test_connection_manager_proxy_integration_tunneling_proxy_http_basic_auth(
2143 struct aws_allocator *allocator,
2144 void *ctx) {
2145 (void)ctx;
2146 return s_proxy_integration_test_helper(
2147 allocator, TUNNELING_HTTP, AWS_HPAT_BASIC, false /*use_env*/, false /*configured_tls*/);
2148 }
2149 AWS_TEST_CASE(
2150 connection_manager_proxy_integration_tunneling_proxy_http_basic_auth,
2151 s_test_connection_manager_proxy_integration_tunneling_proxy_http_basic_auth);
2152
2153 static int s_test_connection_manager_proxy_integration_tunneling_proxy_http_basic_auth_env(
2154 struct aws_allocator *allocator,
2155 void *ctx) {
2156 (void)ctx;
2157 return s_proxy_integration_test_helper(
2158 allocator, TUNNELING_HTTP, AWS_HPAT_BASIC, true /*use_env*/, false /*configured_tls*/);
2159 }
2160 AWS_TEST_CASE(
2161 connection_manager_proxy_integration_tunneling_proxy_http_basic_auth_env,
2162 s_test_connection_manager_proxy_integration_tunneling_proxy_http_basic_auth_env);
2163
2164 static int s_test_connection_manager_proxy_integration_tunneling_proxy_https_basic_auth(
2165 struct aws_allocator *allocator,
2166 void *ctx) {
2167 (void)ctx;
2168 return s_proxy_integration_test_helper(
2169 allocator, TUNNELING_HTTPS, AWS_HPAT_BASIC, false /*use_env*/, false /*configured_tls*/);
2170 }
2171 AWS_TEST_CASE(
2172 connection_manager_proxy_integration_tunneling_proxy_https_basic_auth,
2173 s_test_connection_manager_proxy_integration_tunneling_proxy_https_basic_auth);
2174
2175 static int s_test_connection_manager_proxy_integration_tunneling_proxy_https_basic_auth_env(
2176 struct aws_allocator *allocator,
2177 void *ctx) {
2178 (void)ctx;
2179 return s_proxy_integration_test_helper(
2180 allocator, TUNNELING_HTTPS, AWS_HPAT_BASIC, true /*use_env*/, false /*configured_tls*/);
2181 }
2182 AWS_TEST_CASE(
2183 connection_manager_proxy_integration_tunneling_proxy_https_basic_auth_env,
2184 s_test_connection_manager_proxy_integration_tunneling_proxy_https_basic_auth_env);
2185
2186 static int s_test_h1_proxy_h2_host_tunneling_double_tls_no_auth(struct aws_allocator *allocator, void *ctx) {
2187 (void)ctx;
2188 return s_proxy_integration_test_helper_general(
2189 allocator, TUNNELING_DOUBLE_TLS, AWS_HPAT_NONE, false /*use_env*/, false /*configured_tls*/, true /*h2*/);
2190 }
2191 AWS_TEST_CASE(h1_proxy_h2_host_tunneling_double_tls_no_auth, s_test_h1_proxy_h2_host_tunneling_double_tls_no_auth);