| 1 |
#ifndef AWS_HTTP_PROXY_TEST_HELPER_H |
| 2 |
#define AWS_HTTP_PROXY_TEST_HELPER_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <aws/common/condition_variable.h> |
| 10 |
#include <aws/common/mutex.h> |
| 11 |
#include <aws/http/proxy.h> |
| 12 |
#include <aws/io/channel_bootstrap.h> |
| 13 |
#include <aws/io/event_loop.h> |
| 14 |
#include <aws/io/logging.h> |
| 15 |
#include <aws/io/tls_channel_handler.h> |
| 16 |
|
| 17 |
struct aws_http_client_bootstrap; |
| 18 |
struct testing_channel; |
| 19 |
|
| 20 |
typedef void(aws_http_release_connection_fn)(struct aws_http_connection *connection); |
| 21 |
|
| 22 |
enum proxy_tester_test_mode { |
| 23 |
PTTM_HTTP_FORWARD = 0, |
| 24 |
PTTM_HTTP_TUNNEL, |
| 25 |
PTTM_HTTPS_TUNNEL, |
| 26 |
PTTM_NO_PROXY, |
| 27 |
}; |
| 28 |
|
| 29 |
enum proxy_tester_failure_type { |
| 30 |
PTFT_NONE = 0, |
| 31 |
PTFT_CONNECT_REQUEST, |
| 32 |
PTFT_TLS_NEGOTIATION, |
| 33 |
PTFT_CHANNEL, |
| 34 |
PTFT_CONNECTION, |
| 35 |
PTFT_PROXY_STRATEGY, |
| 36 |
}; |
| 37 |
|
| 38 |
struct proxy_tester_options { |
| 39 |
struct aws_allocator *alloc; |
| 40 |
struct aws_http_proxy_options *proxy_options; |
| 41 |
struct aws_byte_cursor host; |
| 42 |
uint32_t port; |
| 43 |
enum proxy_tester_test_mode test_mode; |
| 44 |
enum proxy_tester_failure_type failure_type; |
| 45 |
|
| 46 |
uint32_t desired_connect_response_count; |
| 47 |
struct aws_byte_cursor *desired_connect_responses; |
| 48 |
}; |
| 49 |
|
| 50 |
struct proxy_tester { |
| 51 |
struct aws_allocator *alloc; |
| 52 |
struct aws_logger logger; |
| 53 |
struct aws_event_loop_group *event_loop_group; |
| 54 |
struct aws_host_resolver *host_resolver; |
| 55 |
struct aws_client_bootstrap *client_bootstrap; |
| 56 |
|
| 57 |
struct aws_tls_ctx *tls_ctx; |
| 58 |
struct aws_tls_ctx_options tls_ctx_options; |
| 59 |
struct aws_tls_connection_options tls_connection_options; |
| 60 |
|
| 61 |
struct aws_http_proxy_options proxy_options; |
| 62 |
struct aws_byte_cursor host; |
| 63 |
uint32_t port; |
| 64 |
|
| 65 |
enum proxy_tester_test_mode test_mode; |
| 66 |
enum proxy_tester_failure_type failure_type; |
| 67 |
|
| 68 |
struct aws_http_connection *client_connection; |
| 69 |
struct aws_array_list testing_channels; |
| 70 |
|
| 71 |
bool client_connection_is_setup; |
| 72 |
bool client_connection_is_shutdown; |
| 73 |
|
| 74 |
|
| 75 |
struct aws_mutex wait_lock; |
| 76 |
struct aws_condition_variable wait_cvar; |
| 77 |
int wait_result; |
| 78 |
bool request_successful; |
| 79 |
bool request_complete; |
| 80 |
|
| 81 |
bool tls_finished; |
| 82 |
bool tls_successful; |
| 83 |
|
| 84 |
struct aws_byte_buf connection_host_name; |
| 85 |
uint32_t connection_port; |
| 86 |
|
| 87 |
struct aws_array_list connect_requests; |
| 88 |
|
| 89 |
uint32_t current_response_index; |
| 90 |
struct aws_array_list desired_connect_responses; |
| 91 |
}; |
| 92 |
|
| 93 |
int proxy_tester_wait(struct proxy_tester *tester, bool (*pred)(void *user_data)); |
| 94 |
|
| 95 |
bool proxy_tester_connection_setup_pred(void *user_data); |
| 96 |
bool proxy_tester_connection_complete_pred(void *user_data); |
| 97 |
bool proxy_tester_connection_shutdown_pred(void *user_data); |
| 98 |
bool proxy_tester_request_complete_pred_fn(void *user_data); |
| 99 |
|
| 100 |
int proxy_tester_init(struct proxy_tester *tester, const struct proxy_tester_options *options); |
| 101 |
|
| 102 |
int proxy_tester_clean_up(struct proxy_tester *tester); |
| 103 |
|
| 104 |
void proxy_tester_on_client_connection_setup(struct aws_http_connection *connection, int error_code, void *user_data); |
| 105 |
|
| 106 |
void proxy_tester_on_client_connection_shutdown( |
| 107 |
struct aws_http_connection *connection, |
| 108 |
int error_code, |
| 109 |
void *user_data); |
| 110 |
|
| 111 |
void proxy_tester_on_client_bootstrap_shutdown(void *user_data); |
| 112 |
|
| 113 |
int proxy_tester_create_testing_channel_connection( |
| 114 |
struct proxy_tester *tester, |
| 115 |
struct aws_http_client_bootstrap *http_bootstrap); |
| 116 |
|
| 117 |
int proxy_tester_verify_connect_request(struct proxy_tester *tester); |
| 118 |
|
| 119 |
int proxy_tester_send_connect_response(struct proxy_tester *tester); |
| 120 |
|
| 121 |
int proxy_tester_verify_connection_attempt_was_to_proxy( |
| 122 |
struct proxy_tester *tester, |
| 123 |
struct aws_byte_cursor expected_host, |
| 124 |
uint32_t expected_port); |
| 125 |
|
| 126 |
int proxy_tester_verify_connection_attempt_was_to_target( |
| 127 |
struct proxy_tester *tester, |
| 128 |
struct aws_byte_cursor expected_host, |
| 129 |
uint32_t expected_port); |
| 130 |
|
| 131 |
struct testing_channel *proxy_tester_get_current_channel(struct proxy_tester *tester); |
| 132 |
|
| 133 |
#endif |