|
| 1 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | + |
| 3 | +#include <fluent-bit/flb_info.h> |
| 4 | +#include <fluent-bit/flb_upstream.h> |
| 5 | +#include <fluent-bit/flb_upstream_conn.h> |
| 6 | +#include <fluent-bit/flb_connection.h> |
| 7 | +#include <fluent-bit/flb_pipe.h> |
| 8 | +#include <fluent-bit/flb_socket.h> |
| 9 | +#include <fluent-bit/tls/flb_tls.h> |
| 10 | + |
| 11 | +#include "flb_tests_internal.h" |
| 12 | + |
| 13 | +#ifdef FLB_HAVE_TLS |
| 14 | + |
| 15 | +#ifdef FLB_SYSTEM_WINDOWS |
| 16 | +#include <fluent-bit/flb_compat.h> |
| 17 | +#endif |
| 18 | + |
| 19 | +struct test_backend_ctx { |
| 20 | + int invalidate_calls; |
| 21 | +}; |
| 22 | + |
| 23 | +static void test_session_invalidate(void *session) |
| 24 | +{ |
| 25 | + struct test_backend_ctx *ctx = session; |
| 26 | + |
| 27 | + if (ctx != NULL) { |
| 28 | + ctx->invalidate_calls++; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +void test_prepare_destroy_conn_marks_tls_session_stale(void) |
| 33 | +{ |
| 34 | + struct test_backend_ctx backend_session = {0}; |
| 35 | + struct flb_tls_backend backend_api = {0}; |
| 36 | + struct flb_tls tls_context = {0}; |
| 37 | + struct flb_tls_session tls_session = {0}; |
| 38 | + struct flb_connection conn = {0}; |
| 39 | + struct flb_upstream upstream = {0}; |
| 40 | + struct flb_config config = {0}; |
| 41 | + struct flb_upstream_queue *queue; |
| 42 | + flb_pipefd_t socket_pair[2]; |
| 43 | + int ret; |
| 44 | + |
| 45 | +#ifdef FLB_SYSTEM_WINDOWS |
| 46 | + WSADATA wsa_data; |
| 47 | + |
| 48 | + WSAStartup(0x0201, &wsa_data); |
| 49 | +#endif |
| 50 | + |
| 51 | + ret = flb_pipe_create(socket_pair); |
| 52 | + TEST_CHECK(ret == 0); |
| 53 | + |
| 54 | + backend_api.session_invalidate = test_session_invalidate; |
| 55 | + tls_context.api = &backend_api; |
| 56 | + |
| 57 | + tls_session.ptr = &backend_session; |
| 58 | + tls_session.tls = &tls_context; |
| 59 | + tls_session.connection = &conn; |
| 60 | + |
| 61 | + config.is_shutting_down = FLB_FALSE; |
| 62 | + upstream.base.config = &config; |
| 63 | + upstream.base.net.keepalive = FLB_FALSE; |
| 64 | + upstream.tcp_host = "example"; |
| 65 | + upstream.tcp_port = 443; |
| 66 | + |
| 67 | + flb_upstream_queue_init(&upstream.queue); |
| 68 | + |
| 69 | + conn.fd = socket_pair[0]; |
| 70 | + conn.event.fd = conn.fd; |
| 71 | + conn.event.status = 0; |
| 72 | + conn.stream = (struct flb_stream *) &upstream; |
| 73 | + conn.net = &upstream.base.net; |
| 74 | + conn.tls_session = &tls_session; |
| 75 | + conn.net_error = 0; |
| 76 | + |
| 77 | + mk_list_init(&conn._head); |
| 78 | + queue = &upstream.queue; |
| 79 | + mk_list_add(&conn._head, &queue->busy_queue); |
| 80 | + |
| 81 | + ret = flb_upstream_conn_release(&conn); |
| 82 | + TEST_CHECK(ret == 0); |
| 83 | + |
| 84 | + TEST_CHECK(backend_session.invalidate_calls == 1); |
| 85 | + TEST_CHECK(conn.fd == -1); |
| 86 | + TEST_CHECK(conn.event.fd == -1); |
| 87 | + TEST_CHECK(mk_list_size(&queue->destroy_queue) == 1); |
| 88 | + TEST_CHECK(conn.shutdown_flag == FLB_TRUE); |
| 89 | + |
| 90 | + flb_pipe_close(socket_pair[1]); |
| 91 | + |
| 92 | +#ifdef FLB_SYSTEM_WINDOWS |
| 93 | + WSACleanup(); |
| 94 | +#endif |
| 95 | +} |
| 96 | + |
| 97 | +#endif |
| 98 | + |
| 99 | +TEST_LIST = { |
| 100 | +#ifdef FLB_HAVE_TLS |
| 101 | + {"prepare_destroy_conn_marks_tls_session_stale", test_prepare_destroy_conn_marks_tls_session_stale}, |
| 102 | +#endif |
| 103 | + {0} |
| 104 | +}; |
0 commit comments