2020-12-07 14:19:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
*
|
2021-06-03 08:37:05 +02:00
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2020-12-07 14:19:10 +02:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
2021-02-02 09:28:23 +01:00
|
|
|
#include <inttypes.h>
|
2020-12-07 14:19:10 +02:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
#include <isc/async.h>
|
2020-12-07 14:19:10 +02:00
|
|
|
#include <isc/atomic.h>
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/condition.h>
|
|
|
|
#include <isc/mutex.h>
|
|
|
|
#include <isc/netmgr.h>
|
|
|
|
#include <isc/nonce.h>
|
|
|
|
#include <isc/os.h>
|
2021-02-02 09:28:23 +01:00
|
|
|
#include <isc/print.h>
|
2020-12-07 14:19:10 +02:00
|
|
|
#include <isc/refcount.h>
|
|
|
|
#include <isc/sockaddr.h>
|
|
|
|
#include <isc/thread.h>
|
2022-04-27 17:41:47 +02:00
|
|
|
#include <isc/uv.h>
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
#include "uv_wrap.h"
|
|
|
|
#define KEEP_BEFORE
|
|
|
|
|
2022-05-03 11:37:31 +02:00
|
|
|
#include "netmgr/http.c"
|
|
|
|
#include "netmgr/netmgr-int.h"
|
|
|
|
#include "netmgr/socket.c"
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
|
2022-05-03 11:37:31 +02:00
|
|
|
#include <tests/isc.h>
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
#define MAX_NM 2
|
|
|
|
|
|
|
|
static isc_sockaddr_t tcp_listen_addr;
|
|
|
|
|
|
|
|
static uint64_t send_magic = 0;
|
|
|
|
static uint64_t stop_magic = 0;
|
|
|
|
|
|
|
|
static uv_buf_t send_msg = { .base = (char *)&send_magic,
|
|
|
|
.len = sizeof(send_magic) };
|
|
|
|
|
2022-03-08 23:55:10 +01:00
|
|
|
static atomic_int_fast64_t active_cconnects = 0;
|
|
|
|
static atomic_int_fast64_t nsends = 0;
|
|
|
|
static atomic_int_fast64_t ssends = 0;
|
|
|
|
static atomic_int_fast64_t sreads = 0;
|
|
|
|
static atomic_int_fast64_t csends = 0;
|
|
|
|
static atomic_int_fast64_t creads = 0;
|
|
|
|
static atomic_int_fast64_t ctimeouts = 0;
|
|
|
|
static atomic_int_fast64_t total_sends = 0;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static int expected_ssends;
|
|
|
|
static int expected_sreads;
|
|
|
|
static int expected_csends;
|
|
|
|
static int expected_cconnects;
|
|
|
|
static int expected_creads;
|
|
|
|
static int expected_ctimeouts;
|
|
|
|
|
|
|
|
#define have_expected_ssends(v) ((v) >= expected_ssends && expected_ssends >= 0)
|
|
|
|
#define have_expected_sreads(v) ((v) >= expected_sreads && expected_sreads >= 0)
|
|
|
|
#define have_expected_csends(v) ((v) >= expected_csends && expected_csends >= 0)
|
|
|
|
#define have_expected_cconnects(v) \
|
|
|
|
((v) >= expected_cconnects && expected_cconnects >= 0)
|
|
|
|
#define have_expected_creads(v) ((v) >= expected_creads && expected_creads >= 0)
|
|
|
|
#define have_expected_ctimeouts(v) \
|
|
|
|
((v) >= expected_ctimeouts && expected_ctimeouts >= 0)
|
|
|
|
|
2021-04-21 11:55:40 -07:00
|
|
|
static bool noanswer = false;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-03-08 23:55:10 +01:00
|
|
|
static atomic_bool POST = true;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-03-08 23:55:10 +01:00
|
|
|
static atomic_bool slowdown = false;
|
2021-03-31 18:32:32 +02:00
|
|
|
|
2022-03-08 23:55:10 +01:00
|
|
|
static atomic_bool use_TLS = false;
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
static isc_tlsctx_t *server_tlsctx = NULL;
|
|
|
|
static isc_tlsctx_t *client_tlsctx = NULL;
|
2022-04-22 15:59:11 +03:00
|
|
|
static isc_tlsctx_client_session_cache_t *client_sess_cache = NULL;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static isc_quota_t listener_quota;
|
2022-03-08 23:55:10 +01:00
|
|
|
static atomic_bool check_listener_quota = false;
|
2021-05-14 11:50:33 +03:00
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
static isc_nm_http_endpoints_t *endpoints = NULL;
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static isc_nm_t **nm = NULL;
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
|
2021-04-22 13:29:34 +03:00
|
|
|
/* Timeout for soft-timeout tests (0.05 seconds) */
|
|
|
|
#define T_SOFT 50
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
#define NSENDS 100
|
|
|
|
#define NWRITES 10
|
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
#define CHECK_RANGE_FULL(v) \
|
|
|
|
{ \
|
|
|
|
int __v = atomic_load(&v); \
|
|
|
|
assert_true(__v >= atomic_load(&total_sends)); \
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
#define CHECK_RANGE_HALF(v) \
|
|
|
|
{ \
|
|
|
|
int __v = atomic_load(&v); \
|
|
|
|
assert_true(__v >= atomic_load(&total_sends) / 2); \
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable this to print values while running tests */
|
|
|
|
#undef PRINT_DEBUG
|
|
|
|
#ifdef PRINT_DEBUG
|
|
|
|
#define X(v) fprintf(stderr, #v " = %" PRIu64 "\n", atomic_load(&v))
|
|
|
|
#else
|
|
|
|
#define X(v)
|
|
|
|
#endif
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
typedef struct csdata {
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_mem_t *mctx;
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
isc_nm_recv_cb_t reply_cb;
|
|
|
|
void *cb_arg;
|
|
|
|
isc_region_t region;
|
|
|
|
} csdata_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
connect_send_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
|
|
|
|
csdata_t data;
|
|
|
|
|
|
|
|
REQUIRE(VALID_NMHANDLE(handle));
|
|
|
|
|
2021-04-21 15:15:27 +03:00
|
|
|
(void)atomic_fetch_sub(&active_cconnects, 1);
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
memmove(&data, arg, sizeof(data));
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_mem_put(data.mctx, arg, sizeof(data));
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = isc__nm_http_request(handle, &data.region, data.reply_cb,
|
|
|
|
data.cb_arg);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_mem_putanddetach(&data.mctx, data.region.base, data.region.length);
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
return;
|
|
|
|
error:
|
|
|
|
data.reply_cb(handle, result, NULL, data.cb_arg);
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_mem_putanddetach(&data.mctx, data.region.base, data.region.length);
|
2021-04-21 15:15:27 +03:00
|
|
|
if (result == ISC_R_TOOMANYOPENFILES) {
|
|
|
|
atomic_store(&slowdown, true);
|
|
|
|
}
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
}
|
|
|
|
|
2021-03-31 18:32:32 +02:00
|
|
|
static void
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
connect_send_request(isc_nm_t *mgr, const char *uri, bool post,
|
|
|
|
isc_region_t *region, isc_nm_recv_cb_t cb, void *cbarg,
|
|
|
|
bool tls, unsigned int timeout) {
|
|
|
|
isc_region_t copy;
|
|
|
|
csdata_t *data = NULL;
|
|
|
|
isc_tlsctx_t *ctx = NULL;
|
|
|
|
|
|
|
|
copy = (isc_region_t){ .base = isc_mem_get(mgr->mctx, region->length),
|
|
|
|
.length = region->length };
|
|
|
|
memmove(copy.base, region->base, region->length);
|
|
|
|
data = isc_mem_get(mgr->mctx, sizeof(*data));
|
|
|
|
*data = (csdata_t){ .reply_cb = cb, .cb_arg = cbarg, .region = copy };
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_mem_attach(mgr->mctx, &data->mctx);
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
if (tls) {
|
|
|
|
ctx = client_tlsctx;
|
|
|
|
}
|
|
|
|
|
2021-05-26 08:15:34 +02:00
|
|
|
isc_nm_httpconnect(mgr, NULL, &tcp_listen_addr, uri, post,
|
2022-04-22 15:59:11 +03:00
|
|
|
connect_send_cb, data, ctx, client_sess_cache,
|
|
|
|
timeout);
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static int
|
|
|
|
setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
|
|
|
|
isc_result_t result;
|
|
|
|
socklen_t addrlen = sizeof(*addr);
|
|
|
|
int fd;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
isc_sockaddr_fromin6(addr, &in6addr_loopback, 0);
|
|
|
|
|
|
|
|
fd = socket(AF_INET6, family, 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("setup_ephemeral_port: socket()");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = bind(fd, (const struct sockaddr *)&addr->type.sa,
|
|
|
|
sizeof(addr->type.sin6));
|
|
|
|
if (r != 0) {
|
|
|
|
perror("setup_ephemeral_port: bind()");
|
|
|
|
isc__nm_closesocket(fd);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
r = getsockname(fd, (struct sockaddr *)&addr->type.sa, &addrlen);
|
|
|
|
if (r != 0) {
|
|
|
|
perror("setup_ephemeral_port: getsockname()");
|
|
|
|
isc__nm_closesocket(fd);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = isc__nm_socket_reuse(fd);
|
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"setup_ephemeral_port: isc__nm_socket_reuse(): %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
close(fd);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = isc__nm_socket_reuse_lb(fd);
|
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"setup_ephemeral_port: isc__nm_socket_reuse_lb(): %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
close(fd);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if IPV6_RECVERR
|
|
|
|
#define setsockopt_on(socket, level, name) \
|
|
|
|
setsockopt(socket, level, name, &(int){ 1 }, sizeof(int))
|
|
|
|
|
|
|
|
r = setsockopt_on(fd, IPPROTO_IPV6, IPV6_RECVERR);
|
|
|
|
if (r != 0) {
|
|
|
|
perror("setup_ephemeral_port");
|
|
|
|
close(fd);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generic */
|
|
|
|
|
|
|
|
static void
|
|
|
|
noop_read_cb(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region,
|
|
|
|
void *cbarg) {
|
|
|
|
UNUSED(handle);
|
|
|
|
UNUSED(result);
|
|
|
|
UNUSED(region);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_local uint8_t tcp_buffer_storage[4096];
|
|
|
|
thread_local size_t tcp_buffer_length = 0;
|
|
|
|
|
|
|
|
static int
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
setup_test(void **state) {
|
|
|
|
char *env_workers = getenv("ISC_TASK_WORKERS");
|
|
|
|
uv_os_sock_t tcp_listen_sock = -1;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
tcp_listen_addr = (isc_sockaddr_t){ .length = 0 };
|
|
|
|
tcp_listen_sock = setup_ephemeral_port(&tcp_listen_addr, SOCK_STREAM);
|
|
|
|
if (tcp_listen_sock < 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
close(tcp_listen_sock);
|
|
|
|
tcp_listen_sock = -1;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
if (env_workers != NULL) {
|
|
|
|
workers = atoi(env_workers);
|
|
|
|
} else {
|
|
|
|
workers = isc_os_ncpus();
|
|
|
|
}
|
|
|
|
INSIST(workers > 0);
|
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
atomic_store(&total_sends, NSENDS * NWRITES);
|
|
|
|
atomic_store(&nsends, atomic_load(&total_sends));
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
atomic_store(&csends, 0);
|
|
|
|
atomic_store(&creads, 0);
|
|
|
|
atomic_store(&sreads, 0);
|
|
|
|
atomic_store(&ssends, 0);
|
2021-04-21 11:55:40 -07:00
|
|
|
atomic_store(&ctimeouts, 0);
|
2021-04-21 15:15:27 +03:00
|
|
|
atomic_store(&active_cconnects, 0);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
expected_cconnects = -1;
|
|
|
|
expected_csends = -1;
|
|
|
|
expected_creads = -1;
|
|
|
|
expected_sreads = -1;
|
|
|
|
expected_ssends = -1;
|
|
|
|
expected_ctimeouts = -1;
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&use_TLS, false);
|
|
|
|
|
2021-04-21 11:55:40 -07:00
|
|
|
noanswer = false;
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nonce_buf(&send_magic, sizeof(send_magic));
|
|
|
|
isc_nonce_buf(&stop_magic, sizeof(stop_magic));
|
|
|
|
if (send_magic == stop_magic) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
setup_loopmgr(state);
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
nm = isc_mem_get(mctx, MAX_NM * sizeof(nm[0]));
|
2020-12-07 14:19:10 +02:00
|
|
|
for (size_t i = 0; i < MAX_NM; i++) {
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_netmgr_create(mctx, loopmgr, &nm[i]);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_non_null(nm[i]);
|
|
|
|
}
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
server_tlsctx = NULL;
|
|
|
|
isc_tlsctx_createserver(NULL, NULL, &server_tlsctx);
|
Use the TLS context cache for server-side contexts
Using the TLS context cache for server-side contexts could reduce the
number of contexts to initialise in the configurations when e.g. the
same 'tls' entry is used in multiple 'listen-on' statements for the
same DNS transport, binding to multiple IP addresses.
In such a case, only one TLS context will be created, instead of a
context per IP address, which could reduce the initialisation time, as
initialising even a non-ephemeral TLS context introduces some delay,
which can be *visually* noticeable by log activity.
Also, this change lays down a foundation for Mutual TLS (when the
server validates a client certificate, additionally to a client
validating the server), as the TLS context cache can be extended to
store additional data required for validation (like intermediates CA
chain).
Additionally to the above, the change ensures that the contexts are
not being changed after initialisation, as such a practice is frowned
upon. Previously we would set the supported ALPN tags within
isc_nm_listenhttp() and isc_nm_listentlsdns(). We do not do that for
client-side contexts, so that appears to be an overlook. Now we set
the supported ALPN tags right after server-side contexts creation,
similarly how we do for client-side ones.
2021-12-23 12:01:34 +02:00
|
|
|
isc_tlsctx_enable_http2server_alpn(server_tlsctx);
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
client_tlsctx = NULL;
|
|
|
|
isc_tlsctx_createclient(&client_tlsctx);
|
|
|
|
isc_tlsctx_enable_http2client_alpn(client_tlsctx);
|
2022-04-22 15:59:11 +03:00
|
|
|
client_sess_cache = isc_tlsctx_client_session_cache_new(
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
mctx, client_tlsctx,
|
2022-04-22 15:59:11 +03:00
|
|
|
ISC_TLSCTX_CLIENT_SESSION_CACHE_DEFAULT_SIZE);
|
2021-02-02 09:28:23 +01:00
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
isc_quota_init(&listener_quota, 0);
|
|
|
|
atomic_store(&check_listener_quota, false);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
INSIST(endpoints == NULL);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
endpoints = isc_nm_http_endpoints_new(mctx);
|
2021-07-13 12:32:47 +03:00
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
*state = nm;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-07-26 13:03:45 +02:00
|
|
|
teardown_test(void **state __attribute__((__unused__))) {
|
2020-12-07 14:19:10 +02:00
|
|
|
for (size_t i = 0; i < MAX_NM; i++) {
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_netmgr_destroy(&nm[i]);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_null(nm[i]);
|
|
|
|
}
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_put(mctx, nm, MAX_NM * sizeof(nm[0]));
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
teardown_loopmgr(state);
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
if (server_tlsctx != NULL) {
|
|
|
|
isc_tlsctx_free(&server_tlsctx);
|
|
|
|
}
|
|
|
|
if (client_tlsctx != NULL) {
|
|
|
|
isc_tlsctx_free(&client_tlsctx);
|
2021-02-02 09:28:23 +01:00
|
|
|
}
|
|
|
|
|
2022-04-22 15:59:11 +03:00
|
|
|
isc_tlsctx_client_session_cache_detach(&client_sess_cache);
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
isc_quota_destroy(&listener_quota);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
isc_nm_http_endpoints_detach(&endpoints);
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_local size_t nwrites = NWRITES;
|
|
|
|
|
|
|
|
static void
|
|
|
|
sockaddr_to_url(isc_sockaddr_t *sa, const bool https, char *outbuf,
|
|
|
|
size_t outbuf_len, const char *append) {
|
2021-08-12 10:14:30 +03:00
|
|
|
isc_nm_http_makeuri(https, sa, NULL, 0, append, outbuf, outbuf_len);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static isc_quota_t *
|
|
|
|
init_listener_quota(size_t nthreads) {
|
|
|
|
isc_quota_t *quotap = NULL;
|
|
|
|
if (atomic_load(&check_listener_quota)) {
|
2022-09-07 17:22:47 +02:00
|
|
|
unsigned int max_quota = ISC_MAX(nthreads / 2, 1);
|
2021-05-14 11:50:33 +03:00
|
|
|
isc_quota_max(&listener_quota, max_quota);
|
|
|
|
quotap = &listener_quota;
|
|
|
|
}
|
|
|
|
return (quotap);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_receive_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
|
|
|
isc_region_t *region, void *cbarg) {
|
|
|
|
assert_non_null(handle);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
UNUSED(region);
|
|
|
|
|
|
|
|
if (eresult == ISC_R_SUCCESS) {
|
2021-04-21 15:15:27 +03:00
|
|
|
(void)atomic_fetch_sub(&nsends, 1);
|
2022-07-26 13:03:45 +02:00
|
|
|
if (have_expected_csends(atomic_fetch_add(&csends, 1) + 1) ||
|
|
|
|
have_expected_creads(atomic_fetch_add(&creads, 1) + 1))
|
|
|
|
{
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
|
|
|
}
|
2020-12-07 14:19:10 +02:00
|
|
|
} else {
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_reply_sent_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
|
|
|
UNUSED(eresult);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
assert_non_null(handle);
|
|
|
|
|
|
|
|
if (eresult == ISC_R_SUCCESS) {
|
|
|
|
atomic_fetch_add(&ssends, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_receive_request_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
|
|
|
isc_region_t *region, void *cbarg) {
|
|
|
|
uint64_t magic = 0;
|
|
|
|
|
|
|
|
UNUSED(cbarg);
|
|
|
|
assert_non_null(handle);
|
|
|
|
|
|
|
|
if (eresult != ISC_R_SUCCESS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_fetch_add(&sreads, 1);
|
|
|
|
|
|
|
|
memmove(tcp_buffer_storage + tcp_buffer_length, region->base,
|
|
|
|
region->length);
|
|
|
|
tcp_buffer_length += region->length;
|
|
|
|
|
|
|
|
while (tcp_buffer_length >= sizeof(magic)) {
|
|
|
|
magic = *(uint64_t *)tcp_buffer_storage;
|
|
|
|
assert_true(magic == stop_magic || magic == send_magic);
|
|
|
|
|
|
|
|
tcp_buffer_length -= sizeof(magic);
|
|
|
|
memmove(tcp_buffer_storage, tcp_buffer_storage + sizeof(magic),
|
|
|
|
tcp_buffer_length);
|
|
|
|
|
|
|
|
if (magic == send_magic) {
|
2021-04-21 11:55:40 -07:00
|
|
|
if (!noanswer) {
|
|
|
|
isc_nm_send(handle, region, doh_reply_sent_cb,
|
|
|
|
NULL);
|
|
|
|
}
|
2020-12-07 14:19:10 +02:00
|
|
|
return;
|
|
|
|
} else if (magic == stop_magic) {
|
2021-04-21 11:55:40 -07:00
|
|
|
/*
|
|
|
|
* We are done, so we don't send anything back.
|
|
|
|
* There should be no more packets in the buffer.
|
|
|
|
*/
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(tcp_buffer_length, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(mock_doh_uv_tcp_bind) {
|
2021-02-02 09:28:23 +01:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
|
|
|
|
|
|
|
WILL_RETURN(uv_tcp_bind, UV_EADDRINUSE);
|
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
noop_read_cb, NULL);
|
2021-07-13 12:32:47 +03:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, NULL, NULL, endpoints,
|
|
|
|
0, &listen_sock);
|
2021-02-02 09:28:23 +01:00
|
|
|
assert_int_not_equal(result, ISC_R_SUCCESS);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
|
|
|
|
RESET_RETURN;
|
2022-07-26 13:03:45 +02:00
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2021-02-02 09:28:23 +01:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:48 +02:00
|
|
|
static void
|
|
|
|
listen_sock_close(void *arg) {
|
|
|
|
isc_nmsocket_t *listen_sock = arg;
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_noop(void *arg __attribute__((__unused__))) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
|
|
|
isc_nm_t *connect_nm = nm[1];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
|
|
|
char req_url[256];
|
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
noop_read_cb, NULL);
|
2021-07-13 12:32:47 +03:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, NULL, NULL, endpoints,
|
|
|
|
0, &listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2022-07-26 13:03:48 +02:00
|
|
|
isc_loop_teardown(mainloop, listen_sock_close, listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url),
|
2021-08-12 14:56:34 +03:00
|
|
|
ISC_NM_HTTP_DEFAULT_PATH);
|
2021-03-31 18:32:32 +02:00
|
|
|
connect_send_request(connect_nm, req_url, atomic_load(&POST),
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
noop_read_cb, NULL, atomic_load(&use_TLS), 30000);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
assert_int_equal(0, atomic_load(&csends));
|
|
|
|
assert_int_equal(0, atomic_load(&creads));
|
|
|
|
assert_int_equal(0, atomic_load(&sreads));
|
|
|
|
assert_int_equal(0, atomic_load(&ssends));
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_noop_POST) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_noop(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_noop_GET) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_noop(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_noresponse(void *arg __attribute__((__unused__))) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
|
|
|
isc_nm_t *connect_nm = nm[1];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
|
|
|
char req_url[256];
|
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
noop_read_cb, NULL);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, NULL, NULL, endpoints,
|
|
|
|
0, &listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2022-07-26 13:03:48 +02:00
|
|
|
isc_loop_teardown(mainloop, listen_sock_close, listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url),
|
2021-08-12 14:56:34 +03:00
|
|
|
ISC_NM_HTTP_DEFAULT_PATH);
|
2021-03-31 18:32:32 +02:00
|
|
|
connect_send_request(connect_nm, req_url, atomic_load(&POST),
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
noop_read_cb, NULL, atomic_load(&use_TLS), 30000);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_noresponse_POST) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_noresponse(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_noresponse_GET) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_noresponse(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2021-04-21 11:55:40 -07:00
|
|
|
static void
|
|
|
|
timeout_query_sent_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
|
|
|
void *cbarg) {
|
|
|
|
UNUSED(eresult);
|
|
|
|
UNUSED(cbarg);
|
|
|
|
|
|
|
|
assert_non_null(handle);
|
|
|
|
|
|
|
|
if (eresult == ISC_R_SUCCESS) {
|
|
|
|
atomic_fetch_add(&csends, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_nmhandle_detach(&handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
timeout_retry_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_region_t *region __attribute__((__unused__)),
|
|
|
|
void *arg __attribute__((__unused__))) {
|
2021-04-21 11:55:40 -07:00
|
|
|
assert_non_null(handle);
|
|
|
|
|
|
|
|
atomic_fetch_add(&ctimeouts, 1);
|
|
|
|
|
|
|
|
if (eresult == ISC_R_TIMEDOUT && atomic_load(&ctimeouts) < 5) {
|
2021-04-22 13:29:34 +03:00
|
|
|
isc_nmhandle_settimeout(handle, T_SOFT);
|
2021-04-21 11:55:40 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-21 17:35:07 -07:00
|
|
|
isc_nmhandle_detach(&handle);
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2021-04-21 11:55:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
timeout_request_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
|
|
|
|
isc_nmhandle_t *sendhandle = NULL;
|
2021-04-21 17:35:07 -07:00
|
|
|
isc_nmhandle_t *readhandle = NULL;
|
2021-04-21 11:55:40 -07:00
|
|
|
|
|
|
|
REQUIRE(VALID_NMHANDLE(handle));
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2022-07-26 13:03:48 +02:00
|
|
|
return;
|
2021-04-21 11:55:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_nmhandle_attach(handle, &sendhandle);
|
|
|
|
isc_nm_send(handle,
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
timeout_query_sent_cb, arg);
|
|
|
|
|
2021-04-21 17:35:07 -07:00
|
|
|
isc_nmhandle_attach(handle, &readhandle);
|
2021-04-21 11:55:40 -07:00
|
|
|
isc_nm_read(handle, timeout_retry_cb, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_timeout_recovery(void *arg __attribute__((__unused__))) {
|
2021-04-21 11:55:40 -07:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
2021-04-21 11:55:40 -07:00
|
|
|
isc_nm_t *connect_nm = nm[1];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_tlsctx_t *ctx = atomic_load(&use_TLS) ? server_tlsctx : NULL;
|
|
|
|
char req_url[256];
|
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
doh_receive_request_cb, NULL);
|
2021-07-13 12:32:47 +03:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, NULL, NULL, endpoints,
|
|
|
|
0, &listen_sock);
|
2021-04-21 11:55:40 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loop_teardown(mainloop, listen_sock_close, listen_sock);
|
2021-04-21 11:55:40 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Accept connections but don't send responses, forcing client
|
|
|
|
* reads to time out.
|
|
|
|
*/
|
|
|
|
noanswer = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shorten all the TCP client timeouts to 0.05 seconds.
|
|
|
|
* timeout_retry_cb() will give up after five timeouts.
|
|
|
|
*/
|
2021-04-22 13:29:34 +03:00
|
|
|
isc_nm_settimeouts(connect_nm, T_SOFT, T_SOFT, T_SOFT, T_SOFT);
|
2021-04-21 11:55:40 -07:00
|
|
|
sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url),
|
2021-08-12 14:56:34 +03:00
|
|
|
ISC_NM_HTTP_DEFAULT_PATH);
|
2021-05-26 08:15:34 +02:00
|
|
|
isc_nm_httpconnect(connect_nm, NULL, &tcp_listen_addr, req_url,
|
|
|
|
atomic_load(&POST), timeout_request_cb, NULL, ctx,
|
2022-04-22 15:59:11 +03:00
|
|
|
client_sess_cache, T_SOFT);
|
2022-07-26 13:03:45 +02:00
|
|
|
}
|
2021-04-21 11:55:40 -07:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static int
|
|
|
|
doh_timeout_recovery_teardown(void **state) {
|
2021-04-21 11:55:40 -07:00
|
|
|
assert_true(atomic_load(&ctimeouts) == 5);
|
2022-07-26 13:03:45 +02:00
|
|
|
return (teardown_test(state));
|
2021-04-21 11:55:40 -07:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_timeout_recovery_POST) {
|
2021-04-21 11:55:40 -07:00
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_timeout_recovery(arg);
|
2021-04-21 11:55:40 -07:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_timeout_recovery_GET) {
|
2021-04-21 11:55:40 -07:00
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_timeout_recovery(arg);
|
2021-04-21 11:55:40 -07:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static void
|
|
|
|
doh_connect_thread(void *arg);
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
|
|
|
isc_region_t *region, void *cbarg) {
|
2021-04-21 15:15:27 +03:00
|
|
|
isc_nmhandle_t *thandle = NULL;
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_nm_t *connect_nm = (isc_nm_t *)cbarg;
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_non_null(handle);
|
|
|
|
UNUSED(region);
|
|
|
|
|
2021-04-21 15:15:27 +03:00
|
|
|
isc_nmhandle_attach(handle, &thandle);
|
2020-12-07 14:19:10 +02:00
|
|
|
if (eresult == ISC_R_SUCCESS) {
|
2021-04-21 15:15:27 +03:00
|
|
|
int_fast64_t sends = atomic_fetch_sub(&nsends, 1);
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_fetch_add(&csends, 1);
|
|
|
|
atomic_fetch_add(&creads, 1);
|
2022-07-26 13:03:45 +02:00
|
|
|
if (sends > 0 && connect_nm != NULL) {
|
2020-12-07 14:19:10 +02:00
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < NWRITES / 2; i++) {
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
eresult = isc__nm_http_request(
|
2020-12-07 14:19:10 +02:00
|
|
|
handle,
|
|
|
|
&(isc_region_t){
|
|
|
|
.base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_receive_send_reply_cb, NULL);
|
2021-04-21 15:15:27 +03:00
|
|
|
if (eresult == ISC_R_CANCELED) {
|
|
|
|
break;
|
|
|
|
}
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(eresult == ISC_R_SUCCESS);
|
|
|
|
}
|
2022-07-26 13:03:45 +02:00
|
|
|
|
|
|
|
isc_job_run(loopmgr, doh_connect_thread, connect_nm);
|
|
|
|
}
|
|
|
|
if (sends <= 0) {
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-21 15:15:27 +03:00
|
|
|
isc_nmhandle_detach(&thandle);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static void
|
|
|
|
doh_connect_thread(void *arg) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_t *connect_nm = (isc_nm_t *)arg;
|
|
|
|
char req_url[256];
|
2021-03-31 18:32:32 +02:00
|
|
|
int64_t sends = atomic_load(&nsends);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url,
|
2021-08-12 14:56:34 +03:00
|
|
|
sizeof(req_url), ISC_NM_HTTP_DEFAULT_PATH);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
/*
|
|
|
|
* We need to back off and slow down if we start getting
|
|
|
|
* errors, to prevent a thundering herd problem.
|
|
|
|
*/
|
|
|
|
int_fast64_t active = atomic_fetch_add(&active_cconnects, 1);
|
|
|
|
if (atomic_load(&slowdown) || active > workers) {
|
|
|
|
goto next;
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
2022-07-26 13:03:45 +02:00
|
|
|
connect_send_request(connect_nm, req_url, atomic_load(&POST),
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
doh_receive_send_reply_cb, connect_nm,
|
|
|
|
atomic_load(&use_TLS), 30000);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
if (sends <= 0) {
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
next : {}
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(void *arg __attribute__((__unused__))) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
|
|
|
isc_nm_t *connect_nm = nm[1];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
|
|
|
char req_url[256];
|
2021-05-14 11:50:33 +03:00
|
|
|
isc_quota_t *quotap = init_listener_quota(workers);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
atomic_store(&total_sends, 1);
|
2022-07-26 13:03:45 +02:00
|
|
|
expected_creads = 1;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
atomic_store(&nsends, atomic_load(&total_sends));
|
2021-07-13 12:32:47 +03:00
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
doh_receive_request_cb, NULL);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, quotap,
|
2021-07-13 12:32:47 +03:00
|
|
|
atomic_load(&use_TLS) ? server_tlsctx : NULL,
|
|
|
|
endpoints, 0, &listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url,
|
2021-08-12 14:56:34 +03:00
|
|
|
sizeof(req_url), ISC_NM_HTTP_DEFAULT_PATH);
|
2021-03-31 18:32:32 +02:00
|
|
|
connect_send_request(connect_nm, req_url, atomic_load(&POST),
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
doh_receive_reply_cb, NULL, atomic_load(&use_TLS),
|
|
|
|
30000);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loop_teardown(mainloop, listen_sock_close, listen_sock);
|
|
|
|
}
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static int
|
|
|
|
doh_recv_one_teardown(void **state) {
|
2021-05-12 19:28:29 +03:00
|
|
|
X(total_sends);
|
2020-12-07 14:19:10 +02:00
|
|
|
X(csends);
|
|
|
|
X(creads);
|
|
|
|
X(sreads);
|
|
|
|
X(ssends);
|
|
|
|
|
|
|
|
assert_int_equal(atomic_load(&csends), 1);
|
|
|
|
assert_int_equal(atomic_load(&creads), 1);
|
|
|
|
assert_int_equal(atomic_load(&sreads), 1);
|
|
|
|
assert_int_equal(atomic_load(&ssends), 1);
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
return (teardown_test(state));
|
|
|
|
}
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_POST) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_GET) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_POST_TLS) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_GET_TLS) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_POST_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_GET_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_POST_TLS_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_one_GET_TLS_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_one(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_connect_send_two_requests_cb(isc_nmhandle_t *handle, isc_result_t result,
|
|
|
|
void *arg) {
|
|
|
|
REQUIRE(VALID_NMHANDLE(handle));
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2022-07-26 13:03:48 +02:00
|
|
|
return;
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
result = isc__nm_http_request(
|
2020-12-07 14:19:10 +02:00
|
|
|
handle,
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
doh_receive_reply_cb, arg);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2022-07-26 13:03:48 +02:00
|
|
|
return;
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
result = isc__nm_http_request(
|
2020-12-07 14:19:10 +02:00
|
|
|
handle,
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
doh_receive_reply_cb, arg);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2022-07-26 13:03:48 +02:00
|
|
|
return;
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(void *arg __attribute__((__unused__))) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
|
|
|
isc_nm_t *connect_nm = nm[1];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
|
|
|
char req_url[256];
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
isc_tlsctx_t *ctx = NULL;
|
2021-05-14 11:50:33 +03:00
|
|
|
isc_quota_t *quotap = init_listener_quota(workers);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
atomic_store(&total_sends, 2);
|
2022-07-26 13:03:45 +02:00
|
|
|
expected_creads = 2;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
atomic_store(&nsends, atomic_load(&total_sends));
|
2021-07-13 12:32:47 +03:00
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
doh_receive_request_cb, NULL);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, quotap,
|
2021-07-13 12:32:47 +03:00
|
|
|
atomic_load(&use_TLS) ? server_tlsctx : NULL,
|
|
|
|
endpoints, 0, &listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url,
|
2021-08-12 14:56:34 +03:00
|
|
|
sizeof(req_url), ISC_NM_HTTP_DEFAULT_PATH);
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
|
|
|
|
if (atomic_load(&use_TLS)) {
|
|
|
|
ctx = client_tlsctx;
|
|
|
|
}
|
|
|
|
|
2021-05-26 08:15:34 +02:00
|
|
|
isc_nm_httpconnect(connect_nm, NULL, &tcp_listen_addr, req_url,
|
|
|
|
atomic_load(&POST), doh_connect_send_two_requests_cb,
|
2022-04-22 15:59:11 +03:00
|
|
|
NULL, ctx, client_sess_cache, 5000);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loop_teardown(mainloop, listen_sock_close, listen_sock);
|
|
|
|
}
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static int
|
|
|
|
doh_recv_two_teardown(void **state) {
|
2021-05-12 19:28:29 +03:00
|
|
|
X(total_sends);
|
2020-12-07 14:19:10 +02:00
|
|
|
X(csends);
|
|
|
|
X(creads);
|
|
|
|
X(sreads);
|
|
|
|
X(ssends);
|
|
|
|
|
|
|
|
assert_int_equal(atomic_load(&csends), 2);
|
|
|
|
assert_int_equal(atomic_load(&creads), 2);
|
|
|
|
assert_int_equal(atomic_load(&sreads), 2);
|
|
|
|
assert_int_equal(atomic_load(&ssends), 2);
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
return (teardown_test(state));
|
|
|
|
}
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_POST) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_GET) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_POST_TLS) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_GET_TLS) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_POST_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_GET_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_POST_TLS_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_two_GET_TLS_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_two(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(void *arg __attribute__((__unused__))) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
|
|
|
isc_nm_t *connect_nm = nm[1];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
2022-07-26 13:03:45 +02:00
|
|
|
size_t nthreads = isc_loopmgr_nloops(loopmgr);
|
2021-05-14 11:50:33 +03:00
|
|
|
isc_quota_t *quotap = init_listener_quota(workers);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
atomic_store(&total_sends, 1000);
|
|
|
|
atomic_store(&nsends, 1000);
|
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
doh_receive_request_cb, NULL);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, quotap,
|
2021-07-13 12:32:47 +03:00
|
|
|
atomic_load(&use_TLS) ? server_tlsctx : NULL,
|
|
|
|
endpoints, 0, &listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < nthreads; i++) {
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_async_run(isc_loop_get(loopmgr, i), doh_connect_thread,
|
|
|
|
connect_nm);
|
2021-08-05 12:42:40 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loop_teardown(mainloop, listen_sock_close, listen_sock);
|
|
|
|
}
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static int
|
|
|
|
doh_recv_send_teardown(void **state) {
|
|
|
|
int res = teardown_test(state);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-05-12 19:28:29 +03:00
|
|
|
X(total_sends);
|
2020-12-07 14:19:10 +02:00
|
|
|
X(csends);
|
|
|
|
X(creads);
|
|
|
|
X(sreads);
|
|
|
|
X(ssends);
|
|
|
|
|
|
|
|
CHECK_RANGE_FULL(csends);
|
|
|
|
CHECK_RANGE_FULL(creads);
|
|
|
|
CHECK_RANGE_FULL(sreads);
|
|
|
|
CHECK_RANGE_FULL(ssends);
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
return (res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_POST) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_GET) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, false);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_POST_TLS) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&use_TLS, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_GET_TLS) {
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&use_TLS, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_POST_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_GET_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_POST_TLS_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_recv_send_GET_TLS_quota) {
|
2021-05-14 11:50:33 +03:00
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
2022-07-26 13:03:45 +02:00
|
|
|
doh_recv_send(arg);
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static int
|
|
|
|
doh_bad_connect_uri_teardown(void **state) {
|
2021-05-12 19:28:29 +03:00
|
|
|
X(total_sends);
|
2020-12-07 14:19:10 +02:00
|
|
|
X(csends);
|
|
|
|
X(creads);
|
|
|
|
X(sreads);
|
|
|
|
X(ssends);
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
/* As we used an ill-formed URI, there ought to be an error. */
|
|
|
|
assert_int_equal(atomic_load(&csends), 0);
|
|
|
|
assert_int_equal(atomic_load(&creads), 0);
|
|
|
|
assert_int_equal(atomic_load(&sreads), 0);
|
|
|
|
assert_int_equal(atomic_load(&ssends), 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
return (teardown_test(state));
|
2021-05-14 11:50:33 +03:00
|
|
|
}
|
|
|
|
|
2021-08-10 17:02:19 +03:00
|
|
|
/* See: GL #2858, !5319 */
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_LOOP_TEST_IMPL(doh_bad_connect_uri) {
|
2021-08-10 17:02:19 +03:00
|
|
|
isc_nm_t *listen_nm = nm[0];
|
|
|
|
isc_nm_t *connect_nm = nm[1];
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
isc_nmsocket_t *listen_sock = NULL;
|
|
|
|
char req_url[256];
|
|
|
|
isc_quota_t *quotap = init_listener_quota(workers);
|
|
|
|
|
|
|
|
atomic_store(&total_sends, 1);
|
|
|
|
|
|
|
|
atomic_store(&nsends, atomic_load(&total_sends));
|
|
|
|
|
2021-08-12 14:56:34 +03:00
|
|
|
result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH,
|
2022-03-23 13:57:15 +01:00
|
|
|
doh_receive_request_cb, NULL);
|
2021-08-10 17:02:19 +03:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2022-03-25 16:44:21 +01:00
|
|
|
result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL,
|
|
|
|
&tcp_listen_addr, 0, quotap, server_tlsctx,
|
|
|
|
endpoints, 0, &listen_sock);
|
2021-08-10 17:02:19 +03:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "https://::1:XXXX/dns-query" is a bad URI, it should be
|
|
|
|
* "https://[::1]:XXXX/dns-query"
|
|
|
|
*/
|
|
|
|
(void)snprintf(req_url, sizeof(req_url), "https://::1:%u/%s",
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_sockaddr_getport(&tcp_listen_addr),
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH);
|
2021-08-10 17:02:19 +03:00
|
|
|
connect_send_request(connect_nm, req_url, atomic_load(&POST),
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
|
|
|
doh_receive_reply_cb, NULL, true, 30000);
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loop_teardown(mainloop, listen_sock_close, listen_sock);
|
2021-08-10 17:02:19 +03:00
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(doh_parse_GET_query_string) {
|
2020-12-07 14:19:10 +02:00
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] =
|
|
|
|
"dns=AAABAAABAAAAAAAAAWE-"
|
|
|
|
"NjJjaGFyYWN0ZXJsYWJlbC1tYWtlcy1iYXNlNjR1cmwtZGlzdGluY3"
|
|
|
|
"QtZnJvbS1zdGFuZGFyZC1iYXNlNjQHZXhhbXBsZQNjb20AAAEAAQ";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(ret);
|
|
|
|
assert_non_null(queryp);
|
|
|
|
assert_true(len > 0);
|
|
|
|
assert_true(len == strlen(str) - 4);
|
|
|
|
assert_true(memcmp(queryp, str + 4, len) == 0);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] =
|
|
|
|
"?dns=AAABAAABAAAAAAAAAWE-"
|
|
|
|
"NjJjaGFyYWN0ZXJsYWJlbC1tYWtlcy1iYXNlNjR1cmwtZGlzdGluY3"
|
|
|
|
"QtZnJvbS1zdGFuZGFyZC1iYXNlNjQHZXhhbXBsZQNjb20AAAEAAQ&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(ret);
|
|
|
|
assert_non_null(queryp);
|
|
|
|
assert_true(len > 0);
|
|
|
|
assert_true(len == strlen(str) - 6);
|
|
|
|
assert_true(memcmp(queryp, str + 5, len) == 0);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=123&dns=567";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(ret);
|
|
|
|
assert_non_null(queryp);
|
|
|
|
assert_true(len > 0);
|
|
|
|
assert_true(len == 3);
|
|
|
|
assert_true(memcmp(queryp, "567", 3) == 0);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?name1=123&dns=567&name2=123&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(ret);
|
|
|
|
assert_non_null(queryp);
|
|
|
|
assert_true(len > 0);
|
|
|
|
assert_true(len == 3);
|
|
|
|
assert_true(memcmp(queryp, "567", 3) == 0);
|
|
|
|
}
|
|
|
|
/* complex, but still valid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] =
|
|
|
|
"?title=%D0%92%D1%96%D0%B4%D1%81%D0%BE%D1%82%D0%BA%D0%"
|
|
|
|
"BE%D0%B2%D0%B5_%D0%BA%D0%BE%D0%B4%D1%83%D0%B2%D0%B0%"
|
|
|
|
"D0%BD%D0%BD%D1%8F&dns=123&veaction=edit§ion=0";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(ret);
|
|
|
|
assert_non_null(queryp);
|
|
|
|
assert_true(len > 0);
|
|
|
|
assert_true(len == 3);
|
|
|
|
assert_true(memcmp(queryp, "123", 3) == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] =
|
|
|
|
"?title=%D0%92%D1%96%D0%B4%D1%81%D0%BE%D1%82%D0%BA%D0%"
|
|
|
|
"BE%D0%B2%D0%B5_%D0%BA%D0%BE%D0%B4%D1%83%D0%B2%D0%B0%"
|
|
|
|
"D0%BD%D0%BD%D1%8F&veaction=edit§ion=0";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=123&&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=123%12&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(ret);
|
|
|
|
assert_non_null(queryp);
|
|
|
|
assert_true(len > 0);
|
|
|
|
assert_true(len == 6);
|
|
|
|
assert_true(memcmp(queryp, "123%12", 6) == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=123%ZZ&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=123%%&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=123%AZ&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_false(ret);
|
|
|
|
assert_null(queryp);
|
|
|
|
assert_true(len == 0);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
const char *queryp = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
char str[] = "?dns=123%0AZ&";
|
|
|
|
|
refactor outgoing HTTP connection support
- style, cleanup, and removal of unnecessary code.
- combined isc_nm_http_add_endpoint() and isc_nm_http_add_doh_endpoint()
into one function, renamed isc_http_endpoint().
- moved isc_nm_http_connect_send_request() into doh_test.c as a helper
function; remove it from the public API.
- renamed isc_http2 and isc_nm_http2 types and functions to just isc_http
and isc_nm_http, for consistency with other existing names.
- shortened a number of long names.
- the caller is now responsible for determining the peer address.
in isc_nm_httpconnect(); this eliminates the need to parse the URI
and the dependency on an external resolver.
- the caller is also now responsible for creating the SSL client context,
for consistency with isc_nm_tlsdnsconnect().
- added setter functions for HTTP/2 ALPN. instead of setting up ALPN in
isc_tlsctx_createclient(), we now have a function
isc_tlsctx_enable_http2client_alpn() that can be run from
isc_nm_httpconnect().
- refactored isc_nm_httprequest() into separate read and send functions.
isc_nm_send() or isc_nm_read() is called on an http socket, it will
be stored until a corresponding isc_nm_read() or _send() arrives; when
we have both halves of the pair the HTTP request will be initiated.
- isc_nm_httprequest() is renamed isc__nm_http_request() for use as an
internal helper function by the DoH unit test. (eventually doh_test
should be rewritten to use read and send, and this function should
be removed.)
- added implementations of isc__nm_tls_settimeout() and
isc__nm_http_settimeout().
- increased NGHTTP2 header block length for client connections to 128K.
- use isc_mem_t for internal memory allocations inside nghttp2, to
help track memory leaks.
- send "Cache-Control" header in requests and responses. (note:
currently we try to bypass HTTP caching proxies, but ideally we should
interact with them: https://tools.ietf.org/html/rfc8484#section-5.1)
2021-02-03 16:59:49 -08:00
|
|
|
ret = isc__nm_parse_httpquery(str, &queryp, &len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_true(ret);
|
|
|
|
assert_non_null(queryp);
|
|
|
|
assert_true(len > 0);
|
|
|
|
assert_true(len == 7);
|
|
|
|
assert_true(memcmp(queryp, "123%0AZ", 7) == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(doh_base64url_to_base64) {
|
2020-12-07 14:19:10 +02:00
|
|
|
char *res;
|
|
|
|
size_t res_len = 0;
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4=";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3U";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U=";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg";
|
|
|
|
char res_test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg";
|
|
|
|
char res_test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
NULL);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, 0, &res_len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "";
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg==";
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg%3D%3D"; /* percent encoded "==" at the
|
|
|
|
end */
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64url_to_base64(mctx, NULL, 31231, &res_len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(doh_base64_to_base64url) {
|
2020-12-07 14:19:10 +02:00
|
|
|
char *res;
|
|
|
|
size_t res_len = 0;
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4=";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3U=";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "PDw_Pz8-Pg";
|
|
|
|
char test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "PDw_Pz8-Pg";
|
|
|
|
char test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
NULL);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
isc_mem_free(mctx, res);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, 0, &res_len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "";
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg==";
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg%3D%3D"; /* percent encoded "==" at the
|
|
|
|
end */
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, test, strlen(test),
|
2020-12-07 14:19:10 +02:00
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
res_len = 0;
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
res = isc__nm_base64_to_base64url(mctx, NULL, 31231, &res_len);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 09:28:23 +01:00
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(doh_path_validation) {
|
2021-05-19 18:03:11 +03:00
|
|
|
assert_true(isc_nm_http_path_isvalid("/"));
|
2021-08-12 14:56:34 +03:00
|
|
|
assert_true(isc_nm_http_path_isvalid(ISC_NM_HTTP_DEFAULT_PATH));
|
2021-05-19 18:03:11 +03:00
|
|
|
assert_false(isc_nm_http_path_isvalid("laaaa"));
|
|
|
|
assert_false(isc_nm_http_path_isvalid(""));
|
|
|
|
assert_false(isc_nm_http_path_isvalid("//"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/lala///"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/lalaaaaaa"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/lalaaa/la/la/la"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/la/a"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/la+la"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/la&la/la*la/l-a_/la!/la\'"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/la/(la)/la"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/la,la,la"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/la-'la'-la"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/la:la=la"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/l@l@l@"));
|
|
|
|
assert_false(isc_nm_http_path_isvalid("/#lala"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/lala;la"));
|
|
|
|
assert_false(
|
|
|
|
isc_nm_http_path_isvalid("la&la/laalaala*lala/l-al_a/lal!/"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/Lal/lAla.jpg"));
|
|
|
|
|
|
|
|
/* had to replace ? with ! because it does not verify a query string */
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/watch!v=oavMtUWDBTM"));
|
|
|
|
assert_false(isc_nm_http_path_isvalid("/watch?v=dQw4w9WgXcQ"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/datatracker.ietf.org/doc/html/"
|
|
|
|
"rfc2616"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/doc/html/rfc8484"));
|
|
|
|
assert_true(isc_nm_http_path_isvalid("/123"));
|
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_RUN_TEST_IMPL(doh_connect_makeuri) {
|
2021-11-25 16:13:46 +11:00
|
|
|
struct in_addr localhostv4 = { .s_addr = ntohl(INADDR_LOOPBACK) };
|
2021-08-12 10:14:30 +03:00
|
|
|
isc_sockaddr_t sa;
|
|
|
|
char uri[256];
|
|
|
|
|
|
|
|
/* Firstly, test URI generation using isc_sockaddr_t */
|
|
|
|
isc_sockaddr_fromin(&sa, &localhostv4, 0);
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, &sa, NULL, 0, ISC_NM_HTTP_DEFAULT_PATH, uri,
|
|
|
|
sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://127.0.0.1:443/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, &sa, NULL, 0, ISC_NM_HTTP_DEFAULT_PATH, uri,
|
|
|
|
sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://127.0.0.1:80/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The port value should be ignored, because we can get one from
|
|
|
|
* the isc_sockaddr_t object.
|
|
|
|
*/
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, &sa, NULL, 44343, ISC_NM_HTTP_DEFAULT_PATH,
|
|
|
|
uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://127.0.0.1:443/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, &sa, NULL, 8080, ISC_NM_HTTP_DEFAULT_PATH,
|
|
|
|
uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://127.0.0.1:80/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/* IPv6 */
|
|
|
|
isc_sockaddr_fromin6(&sa, &in6addr_loopback, 0);
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, &sa, NULL, 0, ISC_NM_HTTP_DEFAULT_PATH, uri,
|
|
|
|
sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://[::1]:443/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, &sa, NULL, 0, ISC_NM_HTTP_DEFAULT_PATH, uri,
|
|
|
|
sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://[::1]:80/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The port value should be ignored, because we can get one from
|
|
|
|
* the isc_sockaddr_t object.
|
|
|
|
*/
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, &sa, NULL, 44343, ISC_NM_HTTP_DEFAULT_PATH,
|
|
|
|
uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://[::1]:443/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, &sa, NULL, 8080, ISC_NM_HTTP_DEFAULT_PATH,
|
|
|
|
uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://[::1]:80/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/* Try to set the port numbers. */
|
|
|
|
isc_sockaddr_setport(&sa, 44343);
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, &sa, NULL, 0, ISC_NM_HTTP_DEFAULT_PATH, uri,
|
|
|
|
sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://[::1]:44343/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
isc_sockaddr_setport(&sa, 8080);
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, &sa, NULL, 0, ISC_NM_HTTP_DEFAULT_PATH, uri,
|
|
|
|
sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://[::1]:8080/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to make a URI using a hostname and a port number. The
|
|
|
|
* isc_sockaddr_t object will be ignored.
|
|
|
|
*/
|
|
|
|
isc_sockaddr_any(&sa);
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, &sa, "example.com", 0,
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH, uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://example.com:443/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, &sa, "example.com", 0,
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH, uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://example.com:80/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/* Try to set the port numbers. */
|
|
|
|
isc_sockaddr_setport(&sa, 443);
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, &sa, "example.com", 44343,
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH, uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://example.com:44343/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
isc_sockaddr_setport(&sa, 80);
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, &sa, "example.com", 8080,
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH, uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://example.com:8080/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/* IPv4 as the hostname - nothing fancy here */
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, NULL, "127.0.0.1", 8080,
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH, uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://127.0.0.1:8080/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, NULL, "127.0.0.1", 44343,
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH, uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://127.0.0.1:44343/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A peculiar edge case: IPv6 given as the hostname (notice
|
|
|
|
* the brackets)
|
|
|
|
*/
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(false, NULL, "::1", 8080, ISC_NM_HTTP_DEFAULT_PATH,
|
|
|
|
uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("http://[::1]:8080/dns-query", uri) == 0);
|
|
|
|
|
|
|
|
uri[0] = '\0';
|
2021-08-12 14:56:34 +03:00
|
|
|
isc_nm_http_makeuri(true, NULL, "[::1]", 44343,
|
|
|
|
ISC_NM_HTTP_DEFAULT_PATH, uri, sizeof(uri));
|
2021-08-12 10:14:30 +03:00
|
|
|
assert_true(strcmp("https://[::1]:44343/dns-query", uri) == 0);
|
|
|
|
}
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_LIST_START
|
2022-07-26 13:03:48 +02:00
|
|
|
|
|
|
|
/* Mock tests are unreliable on OpenBSD */
|
|
|
|
#if !defined(__OpenBSD__)
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_ENTRY_CUSTOM(mock_doh_uv_tcp_bind, setup_test, teardown_test)
|
2022-07-26 13:03:48 +02:00
|
|
|
#endif /* !defined(__OpenBSD__) */
|
|
|
|
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_ENTRY(doh_parse_GET_query_string)
|
|
|
|
ISC_TEST_ENTRY(doh_base64url_to_base64)
|
|
|
|
ISC_TEST_ENTRY(doh_base64_to_base64url)
|
|
|
|
ISC_TEST_ENTRY(doh_path_validation)
|
|
|
|
ISC_TEST_ENTRY(doh_connect_makeuri)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_noop_POST, setup_test, teardown_test)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_noop_GET, setup_test, teardown_test)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_noresponse_POST, setup_test, teardown_test)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_noresponse_GET, setup_test, teardown_test)
|
2022-07-26 13:03:45 +02:00
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_timeout_recovery_POST, setup_test,
|
|
|
|
doh_timeout_recovery_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_timeout_recovery_GET, setup_test,
|
|
|
|
doh_timeout_recovery_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST, setup_test, doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET, setup_test, doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_TLS, setup_test, doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_TLS, setup_test, doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_quota, setup_test,
|
|
|
|
doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_quota, setup_test, doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_POST_TLS_quota, setup_test,
|
|
|
|
doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_one_GET_TLS_quota, setup_test,
|
|
|
|
doh_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST, setup_test, doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET, setup_test, doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_TLS, setup_test, doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_TLS, setup_test, doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_quota, setup_test,
|
|
|
|
doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_quota, setup_test, doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_POST_TLS_quota, setup_test,
|
|
|
|
doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_two_GET_TLS_quota, setup_test,
|
|
|
|
doh_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET, setup_test, doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST, setup_test, doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_TLS, setup_test, doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_TLS, setup_test,
|
|
|
|
doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_quota, setup_test,
|
|
|
|
doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_quota, setup_test,
|
|
|
|
doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_GET_TLS_quota, setup_test,
|
|
|
|
doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_recv_send_POST_TLS_quota, setup_test,
|
|
|
|
doh_recv_send_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(doh_bad_connect_uri, setup_test,
|
|
|
|
doh_bad_connect_uri_teardown)
|
Give the unit tests a big overhaul
The unit tests contain a lot of duplicated code and here's an attempt
to reduce code duplication.
This commit does several things:
1. Remove #ifdef HAVE_CMOCKA - we already solve this with automake
conditionals.
2. Create a set of ISC_TEST_* and ISC_*_TEST_ macros to wrap the test
implementations, test lists, and the main test routine, so we don't
have to repeat this all over again. The macros were modeled after
libuv test suite but adapted to cmocka as the test driver.
A simple example of a unit test would be:
ISC_RUN_TEST_IMPL(test1) { assert_true(true); }
ISC_TEST_LIST_START
ISC_TEST_ENTRY(test1)
ISC_TEST_LIST_END
ISC_TEST_MAIN (Discussion: Should this be ISC_TEST_RUN ?)
For more complicated examples including group setup and teardown
functions, and per-test setup and teardown functions.
3. The macros prefix the test functions and cmocka entries, so the name
of the test can now match the tested function name, and we don't have
to append `_test` because `run_test_` is automatically prepended to
the main test function, and `setup_test_` and `teardown_test_` is
prepended to setup and teardown function.
4. Update all the unit tests to use the new syntax and fix a few bits
here and there.
5. In the future, we can separate the test declarations and test
implementations which are going to greatly help with uncluttering the
bigger unit tests like doh_test and netmgr_test, because the test
implementations are not declared static (see `ISC_RUN_TEST_DECLARE`
and `ISC_RUN_TEST_IMPL` for more details.
NOTE: This heavily relies on preprocessor macros, but the result greatly
outweighs all the negatives of using the macros. There's less
duplicated code, the tests are more uniform and the implementation can
be more flexible.
2022-05-02 10:56:42 +02:00
|
|
|
ISC_TEST_LIST_END
|
|
|
|
|
|
|
|
ISC_TEST_MAIN
|