| 1 |
/* |
| 2 |
* Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MPL-2.0 |
| 5 |
* |
| 6 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 7 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 |
* file, you can obtain one at https://mozilla.org/MPL/2.0/. |
| 9 |
* |
| 10 |
* See the COPYRIGHT file distributed with this work for additional |
| 11 |
* information regarding copyright ownership. |
| 12 |
*/ |
| 13 |
|
| 14 |
#include <inttypes.h> |
| 15 |
#include <sched.h> /* IWYU pragma: keep */ |
| 16 |
#include <setjmp.h> |
| 17 |
#include <signal.h> |
| 18 |
#include <stdarg.h> |
| 19 |
#include <stdlib.h> |
| 20 |
#include <unistd.h> |
| 21 |
|
| 22 |
/* |
| 23 |
* As a workaround, include an OpenSSL header file before including cmocka.h, |
| 24 |
* because OpenSSL 3.1.0 uses __attribute__(malloc), conflicting with a |
| 25 |
* redefined malloc in cmocka.h. |
| 26 |
*/ |
| 27 |
#include <openssl/err.h> |
| 28 |
|
| 29 |
#define UNIT_TESTING |
| 30 |
#include <cmocka.h> |
| 31 |
|
| 32 |
#include <isc/loop.h> |
| 33 |
#include <isc/nonce.h> |
| 34 |
#include <isc/os.h> |
| 35 |
#include <isc/quota.h> |
| 36 |
#include <isc/refcount.h> |
| 37 |
#include <isc/sockaddr.h> |
| 38 |
#include <isc/thread.h> |
| 39 |
#include <isc/util.h> |
| 40 |
#include <isc/uv.h> |
| 41 |
|
| 42 |
#include "uv_wrap.h" |
| 43 |
#define KEEP_BEFORE |
| 44 |
|
| 45 |
#include "netmgr_common.h" |
| 46 |
|
| 47 |
#include <tests/isc.h> |
| 48 |
|
| 49 |
ISC_LOOP_TEST_IMPL(tls_noop) { |
| 50 |
stream_noop(arg); |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
ISC_LOOP_TEST_IMPL(tls_noresponse) { |
| 55 |
stream_noresponse(arg); |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
ISC_LOOP_TEST_IMPL(tls_shutdownconnect) { |
| 60 |
stream_shutdownconnect(arg); |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
ISC_LOOP_TEST_IMPL(tls_shutdownread) { |
| 65 |
stream_shutdownread(arg); |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
ISC_LOOP_TEST_IMPL(tls_timeout_recovery) { |
| 70 |
stream_timeout_recovery(arg); |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
ISC_LOOP_TEST_IMPL(tls_recv_one) { |
| 75 |
stream_recv_one(arg); |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
ISC_LOOP_TEST_IMPL(tls_recv_two) { |
| 80 |
stream_recv_two(arg); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
ISC_LOOP_TEST_IMPL(tls_recv_send) { |
| 85 |
stream_recv_send(arg); |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
ISC_LOOP_TEST_IMPL(tls_recv_send_sendback) { |
| 90 |
allow_send_back = true; |
| 91 |
stream_recv_send(arg); |
| 92 |
} |
| 93 |
|
| 94 |
/* TLS quota */ |
| 95 |
|
| 96 |
ISC_LOOP_TEST_IMPL(tls_recv_one_quota) { |
| 97 |
atomic_store(&check_listener_quota, true); |
| 98 |
stream_recv_one(arg); |
| 99 |
} |
| 100 |
|
| 101 |
ISC_LOOP_TEST_IMPL(tls_recv_two_quota) { |
| 102 |
atomic_store(&check_listener_quota, true); |
| 103 |
stream_recv_two(arg); |
| 104 |
} |
| 105 |
|
| 106 |
ISC_LOOP_TEST_IMPL(tls_recv_send_quota) { |
| 107 |
atomic_store(&check_listener_quota, true); |
| 108 |
stream_recv_send(arg); |
| 109 |
} |
| 110 |
|
| 111 |
ISC_LOOP_TEST_IMPL(tls_recv_send_quota_sendback) { |
| 112 |
allow_send_back = true; |
| 113 |
atomic_store(&check_listener_quota, true); |
| 114 |
stream_recv_send(arg); |
| 115 |
} |
| 116 |
|
| 117 |
/* PROXY tests */ |
| 118 |
|
| 119 |
ISC_LOOP_TEST_IMPL(proxy_tls_noop) { loop_test_tls_noop(arg); } |
| 120 |
|
| 121 |
ISC_LOOP_TEST_IMPL(proxy_tls_noresponse) { loop_test_tls_noresponse(arg); } |
| 122 |
|
| 123 |
ISC_LOOP_TEST_IMPL(proxy_tls_shutdownconnect) { |
| 124 |
loop_test_tls_shutdownconnect(arg); |
| 125 |
} |
| 126 |
|
| 127 |
ISC_LOOP_TEST_IMPL(proxy_tls_shutdownread) { loop_test_tls_shutdownread(arg); } |
| 128 |
|
| 129 |
ISC_LOOP_TEST_IMPL(proxy_tls_timeout_recovery) { |
| 130 |
loop_test_tls_timeout_recovery(arg); |
| 131 |
} |
| 132 |
|
| 133 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_one) { loop_test_tls_recv_one(arg); } |
| 134 |
|
| 135 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_two) { loop_test_tls_recv_two(arg); } |
| 136 |
|
| 137 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_send) { loop_test_tls_recv_send(arg); } |
| 138 |
|
| 139 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_send_sendback) { |
| 140 |
loop_test_tls_recv_send(arg); |
| 141 |
} |
| 142 |
|
| 143 |
/* TLS quota */ |
| 144 |
|
| 145 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_one_quota) { loop_test_tls_recv_one(arg); } |
| 146 |
|
| 147 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_two_quota) { loop_test_tls_recv_two(arg); } |
| 148 |
|
| 149 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_send_quota) { loop_test_tls_recv_send(arg); } |
| 150 |
|
| 151 |
ISC_LOOP_TEST_IMPL(proxy_tls_recv_send_quota_sendback) { |
| 152 |
loop_test_tls_recv_send(arg); |
| 153 |
} |
| 154 |
|
| 155 |
ISC_TEST_LIST_START |
| 156 |
|
| 157 |
/* TLS */ |
| 158 |
ISC_TEST_ENTRY_CUSTOM(tls_noop, stream_noop_setup, stream_noop_teardown) |
| 159 |
ISC_TEST_ENTRY_CUSTOM(tls_noresponse, stream_noresponse_setup, |
| 160 |
stream_noresponse_teardown) |
| 161 |
ISC_TEST_ENTRY_CUSTOM(tls_shutdownconnect, stream_shutdownconnect_setup, |
| 162 |
stream_shutdownconnect_teardown) |
| 163 |
ISC_TEST_ENTRY_CUSTOM(tls_shutdownread, stream_shutdownread_setup, |
| 164 |
stream_shutdownread_teardown) |
| 165 |
ISC_TEST_ENTRY_CUSTOM(tls_timeout_recovery, stream_timeout_recovery_setup, |
| 166 |
stream_timeout_recovery_teardown) |
| 167 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_one, stream_recv_one_setup, |
| 168 |
stream_recv_one_teardown) |
| 169 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_two, stream_recv_two_setup, |
| 170 |
stream_recv_two_teardown) |
| 171 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_send, stream_recv_send_setup, |
| 172 |
stream_recv_send_teardown) |
| 173 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_send_sendback, stream_recv_send_setup, |
| 174 |
stream_recv_send_teardown) |
| 175 |
|
| 176 |
/* TLS quota */ |
| 177 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_one_quota, stream_recv_one_setup, |
| 178 |
stream_recv_one_teardown) |
| 179 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_two_quota, stream_recv_two_setup, |
| 180 |
stream_recv_two_teardown) |
| 181 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_send_quota, stream_recv_send_setup, |
| 182 |
stream_recv_send_teardown) |
| 183 |
ISC_TEST_ENTRY_CUSTOM(tls_recv_send_quota_sendback, stream_recv_send_setup, |
| 184 |
stream_recv_send_teardown) |
| 185 |
|
| 186 |
/* PROXY */ |
| 187 |
|
| 188 |
/* TLS */ |
| 189 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_noop, proxystream_noop_setup, |
| 190 |
proxystream_noop_teardown) |
| 191 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_noresponse, proxystream_noresponse_setup, |
| 192 |
proxystream_noresponse_teardown) |
| 193 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_shutdownconnect, |
| 194 |
proxystream_shutdownconnect_setup, |
| 195 |
proxystream_shutdownconnect_teardown) |
| 196 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_shutdownread, proxystream_shutdownread_setup, |
| 197 |
proxystream_shutdownread_teardown) |
| 198 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_timeout_recovery, |
| 199 |
proxystream_timeout_recovery_setup, |
| 200 |
proxystream_timeout_recovery_teardown) |
| 201 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_one, proxystream_recv_one_setup, |
| 202 |
proxystream_recv_one_teardown) |
| 203 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_two, proxystream_recv_two_setup, |
| 204 |
proxystream_recv_two_teardown) |
| 205 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_send, proxystream_recv_send_setup, |
| 206 |
proxystream_recv_send_teardown) |
| 207 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_send_sendback, proxystream_recv_send_setup, |
| 208 |
proxystream_recv_send_teardown) |
| 209 |
|
| 210 |
/* TLS quota */ |
| 211 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_one_quota, proxystream_recv_one_setup, |
| 212 |
proxystream_recv_one_teardown) |
| 213 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_two_quota, proxystream_recv_two_setup, |
| 214 |
proxystream_recv_two_teardown) |
| 215 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_send_quota, proxystream_recv_send_setup, |
| 216 |
proxystream_recv_send_teardown) |
| 217 |
ISC_TEST_ENTRY_CUSTOM(proxy_tls_recv_send_quota_sendback, |
| 218 |
proxystream_recv_send_setup, |
| 219 |
proxystream_recv_send_teardown) |
| 220 |
|
| 221 |
ISC_TEST_LIST_END |
| 222 |
|
| 223 |
static int |
| 224 |
tls_setup(void **state ISC_ATTR_UNUSED) { |
| 225 |
stream_port = TLS_TEST_PORT; |
| 226 |
stream_use_TLS = true; |
| 227 |
stream = true; |
| 228 |
|
| 229 |
return 0; |
| 230 |
} |
| 231 |
|
| 232 |
ISC_TEST_MAIN_CUSTOM(tls_setup, NULL) |