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-07-16 14:57:08 +03:00
|
|
|
#if defined(HAVE_CMOCKA) && defined(HAVE_LIBNGHTTP2)
|
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>
|
|
|
|
#include <uv.h>
|
|
|
|
|
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
#include "uv_wrap.h"
|
|
|
|
#define KEEP_BEFORE
|
|
|
|
|
|
|
|
#include "../netmgr/http.c"
|
|
|
|
#include "../netmgr/netmgr-int.h"
|
|
|
|
#include "../netmgr/uv-compat.c"
|
|
|
|
#include "../netmgr/uv-compat.h"
|
2021-04-27 00:07:43 +02:00
|
|
|
#include "../netmgr_p.h"
|
2020-12-07 14:19:10 +02:00
|
|
|
#include "isctest.h"
|
|
|
|
|
|
|
|
#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-03-08 23:55:10 +01:00
|
|
|
static atomic_bool was_error = false;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-03-10 14:30:16 +02:00
|
|
|
static unsigned int workers = 0;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
static bool reuse_supported = true;
|
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;
|
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;
|
|
|
|
|
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 {
|
|
|
|
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));
|
|
|
|
isc_mem_put(handle->sock->mgr->mctx, arg, sizeof(data));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_put(handle->sock->mgr->mctx, data.region.base,
|
|
|
|
data.region.length);
|
|
|
|
return;
|
|
|
|
error:
|
|
|
|
data.reply_cb(handle, result, NULL, data.cb_arg);
|
|
|
|
isc_mem_put(handle->sock->mgr->mctx, data.region.base,
|
|
|
|
data.region.length);
|
2021-04-21 15:15:27 +03:00
|
|
|
if (result == ISC_R_TOOMANYOPENFILES) {
|
|
|
|
atomic_store(&slowdown, true);
|
|
|
|
} else {
|
|
|
|
atomic_store(&was_error, 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 };
|
|
|
|
if (tls) {
|
|
|
|
ctx = client_tlsctx;
|
|
|
|
}
|
|
|
|
|
2021-05-26 08:15:34 +02:00
|
|
|
isc_nm_httpconnect(mgr, NULL, &tcp_listen_addr, uri, post,
|
2022-03-23 13:57:15 +01:00
|
|
|
connect_send_cb, data, ctx, 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 (result == ISC_R_NOTIMPLEMENTED) {
|
|
|
|
reuse_supported = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_setup(void **state) {
|
2021-03-10 14:30:16 +02:00
|
|
|
char *p = NULL;
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
UNUSED(state);
|
|
|
|
|
2021-03-10 14:30:16 +02:00
|
|
|
if (workers == 0) {
|
|
|
|
workers = isc_os_ncpus();
|
|
|
|
}
|
|
|
|
p = getenv("ISC_TASK_WORKERS");
|
|
|
|
if (p != NULL) {
|
|
|
|
workers = atoi(p);
|
|
|
|
}
|
|
|
|
INSIST(workers != 0);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
if (isc_test_begin(NULL, false, workers) != ISC_R_SUCCESS) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_teardown(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
isc_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
nm_setup(void **state) {
|
|
|
|
size_t nworkers = ISC_MAX(ISC_MIN(workers, 32), 1);
|
|
|
|
int tcp_listen_sock = -1;
|
|
|
|
isc_nm_t **nm = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
atomic_store(&was_error, false);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
nm = isc_mem_get(test_mctx, MAX_NM * sizeof(nm[0]));
|
|
|
|
for (size_t i = 0; i < MAX_NM; i++) {
|
2021-04-27 00:07:43 +02:00
|
|
|
isc__netmgr_create(test_mctx, nworkers, &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);
|
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);
|
|
|
|
endpoints = isc_nm_http_endpoints_new(test_mctx);
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
*state = nm;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nm_teardown(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < MAX_NM; i++) {
|
2021-04-27 00:07:43 +02:00
|
|
|
isc__netmgr_destroy(&nm[i]);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_null(nm[i]);
|
|
|
|
}
|
|
|
|
isc_mem_put(test_mctx, nm, MAX_NM * sizeof(nm[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
|
|
|
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
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
unsigned max_quota = ISC_MAX(nthreads / 2, 1);
|
|
|
|
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);
|
2020-12-07 14:19:10 +02:00
|
|
|
atomic_fetch_add(&csends, 1);
|
|
|
|
atomic_fetch_add(&creads, 1);
|
|
|
|
} else {
|
|
|
|
/* We failed to connect; try again */
|
|
|
|
atomic_store(&was_error, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
atomic_store(&was_error, true);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 09:28:23 +01:00
|
|
|
static void
|
|
|
|
mock_doh_uv_tcp_bind(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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);
|
2021-05-26 08:15:34 +02:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, NULL, NULL,
|
2021-07-13 12:32:47 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_noop(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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);
|
|
|
|
|
2021-05-26 08:15:34 +02:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, NULL, NULL,
|
2021-07-13 12:32:47 +03:00
|
|
|
endpoints, 0, &listen_sock);
|
2020-12-07 14:19:10 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_noop_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_noop(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_noop_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_noop(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_noresponse(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &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);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_noresponse_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_noresponse(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_noresponse_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_noresponse(state);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
isc_region_t *region, void *arg) {
|
|
|
|
UNUSED(region);
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
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);
|
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) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
atomic_store(&was_error, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_timeout_recovery(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
|
2021-05-26 08:15:34 +02:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, NULL, NULL,
|
2021-07-13 12:32:47 +03:00
|
|
|
endpoints, 0, &listen_sock);
|
2021-04-21 11:55:40 -07:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-03-23 13:57:15 +01:00
|
|
|
T_SOFT);
|
2021-04-21 11:55:40 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sleep until sends reaches 5.
|
|
|
|
*/
|
|
|
|
for (size_t i = 0; i < 1000; i++) {
|
|
|
|
if (atomic_load(&ctimeouts) == 5) {
|
|
|
|
break;
|
|
|
|
}
|
2021-04-27 10:16:01 +02:00
|
|
|
isc_test_nap(1000);
|
2021-04-21 11:55:40 -07:00
|
|
|
}
|
|
|
|
assert_true(atomic_load(&ctimeouts) == 5);
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
2021-04-21 11:55:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_timeout_recovery_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_timeout_recovery(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_timeout_recovery_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_timeout_recovery(state);
|
|
|
|
}
|
|
|
|
|
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;
|
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);
|
2021-07-28 19:30:30 +03:00
|
|
|
if (sends > 0 && cbarg == 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 },
|
2021-07-28 19:30:30 +03:00
|
|
|
doh_receive_send_reply_cb, (void *)1);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
atomic_store(&was_error, true);
|
|
|
|
}
|
2021-04-21 15:15:27 +03:00
|
|
|
isc_nmhandle_detach(&thandle);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_threadresult_t
|
|
|
|
doh_connect_thread(isc_threadarg_t arg) {
|
|
|
|
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
|
|
|
|
2021-03-31 18:32:32 +02:00
|
|
|
while (sends > 0) {
|
|
|
|
/*
|
|
|
|
* We need to back off and slow down if we start getting
|
|
|
|
* errors, to prevent a thundering herd problem.
|
|
|
|
*/
|
2021-04-21 15:15:27 +03:00
|
|
|
int_fast64_t active = atomic_fetch_add(&active_cconnects, 1);
|
|
|
|
if (atomic_load(&slowdown) || active > workers) {
|
|
|
|
isc_test_nap(1000 * (active - workers));
|
2021-03-31 18:32:32 +02:00
|
|
|
atomic_store(&slowdown, false);
|
|
|
|
}
|
|
|
|
connect_send_request(
|
2020-12-07 14:19:10 +02:00
|
|
|
connect_nm, req_url, atomic_load(&POST),
|
|
|
|
&(isc_region_t){ .base = (uint8_t *)send_msg.base,
|
|
|
|
.length = send_msg.len },
|
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
|
|
|
doh_receive_send_reply_cb, NULL, atomic_load(&use_TLS),
|
|
|
|
30000);
|
2021-03-31 18:32:32 +02:00
|
|
|
sends = atomic_load(&nsends);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ((isc_threadresult_t)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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);
|
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);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, quotap,
|
|
|
|
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
|
|
|
|
|
|
|
while (atomic_load(&nsends) > 0) {
|
|
|
|
if (atomic_load(&was_error)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (atomic_load(&ssends) != 1 || atomic_load(&sreads) != 1 ||
|
|
|
|
atomic_load(&csends) != 1)
|
|
|
|
{
|
|
|
|
if (atomic_load(&was_error)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one_POST_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one_GET_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static void
|
|
|
|
doh_recv_one_POST_quota(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one_GET_quota(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one_POST_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_one_GET_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_one(state);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
error:
|
|
|
|
atomic_store(&was_error, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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);
|
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);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, quotap,
|
|
|
|
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-03-23 13:57:15 +01:00
|
|
|
NULL, ctx, 5000);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
while (atomic_load(&nsends) > 0) {
|
|
|
|
if (atomic_load(&was_error)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (atomic_load(&ssends) != 2 || atomic_load(&sreads) != 2 ||
|
|
|
|
atomic_load(&csends) != 2)
|
|
|
|
{
|
|
|
|
if (atomic_load(&was_error)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two_POST_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two_GET_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static void
|
|
|
|
doh_recv_two_POST_quota(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two_GET_quota(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two_POST_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_two_GET_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_two(state);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_recv_send(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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;
|
|
|
|
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
|
|
|
isc_thread_t threads[32] = { 0 };
|
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-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);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, quotap,
|
|
|
|
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++) {
|
|
|
|
isc_thread_create(doh_connect_thread, connect_nm, &threads[i]);
|
|
|
|
}
|
|
|
|
|
2021-08-05 12:42:40 +03:00
|
|
|
/* wait for the all responses from the server */
|
|
|
|
while (atomic_load(&ssends) < atomic_load(&total_sends)) {
|
|
|
|
if (atomic_load(&was_error)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
isc_test_nap(100);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
for (size_t i = 0; i < nthreads; i++) {
|
|
|
|
isc_thread_join(threads[i], NULL);
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_send_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_send_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_send_POST_TLS(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_send_GET_TLS(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static void
|
|
|
|
doh_recv_send_POST_quota(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_send_GET_quota(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_send_POST_TLS_quota(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_send_GET_TLS_quota(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_send(state);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_recv_half_send(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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;
|
|
|
|
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
|
|
|
isc_thread_t threads[32] = { 0 };
|
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, atomic_load(&total_sends) / 2);
|
2021-04-21 15:15:27 +03: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);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, quotap,
|
|
|
|
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++) {
|
|
|
|
isc_thread_create(doh_connect_thread, connect_nm, &threads[i]);
|
|
|
|
}
|
|
|
|
|
2021-04-21 15:15:27 +03:00
|
|
|
while (atomic_load(&nsends) > 0) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
2020-12-07 14:19:10 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < nthreads; i++) {
|
|
|
|
isc_thread_join(threads[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
|
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_HALF(csends);
|
|
|
|
CHECK_RANGE_HALF(creads);
|
|
|
|
CHECK_RANGE_HALF(sreads);
|
|
|
|
CHECK_RANGE_HALF(ssends);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_half_send_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_half_send_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_half_send_POST_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_half_send_GET_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static void
|
|
|
|
doh_recv_half_send_POST_quota(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_half_send_GET_quota(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_half_send_POST_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_recv_half_send_GET_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_half_recv_send(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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;
|
|
|
|
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
|
|
|
isc_thread_t threads[32] = { 0 };
|
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, atomic_load(&total_sends) / 2);
|
2021-04-21 15:15:27 +03: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);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, quotap,
|
|
|
|
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++) {
|
|
|
|
isc_thread_create(doh_connect_thread, connect_nm, &threads[i]);
|
|
|
|
}
|
|
|
|
|
2021-04-21 15:15:27 +03:00
|
|
|
while (atomic_load(&nsends) > 0) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < nthreads; i++) {
|
|
|
|
isc_thread_join(threads[i], NULL);
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
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_HALF(csends);
|
|
|
|
CHECK_RANGE_HALF(creads);
|
|
|
|
CHECK_RANGE_HALF(sreads);
|
|
|
|
CHECK_RANGE_HALF(ssends);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_send_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_send_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_send_POST_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_send_GET_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static void
|
|
|
|
doh_half_recv_send_POST_quota(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_send_GET_quota(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_send_POST_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_send_GET_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_send(state);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_half_recv_half_send(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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;
|
|
|
|
size_t nthreads = ISC_MAX(ISC_MIN(workers, 32), 1);
|
|
|
|
isc_thread_t threads[32] = { 0 };
|
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, atomic_load(&total_sends) / 2);
|
2021-04-21 15:15:27 +03: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);
|
|
|
|
|
2021-07-13 12:32:47 +03:00
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, quotap,
|
|
|
|
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++) {
|
|
|
|
isc_thread_create(doh_connect_thread, connect_nm, &threads[i]);
|
|
|
|
}
|
|
|
|
|
2021-04-21 15:15:27 +03:00
|
|
|
while (atomic_load(&nsends) > 0) {
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:28:40 +02:00
|
|
|
isc__netmgr_shutdown(connect_nm);
|
2020-12-07 14:19:10 +02:00
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < nthreads; i++) {
|
|
|
|
isc_thread_join(threads[i], NULL);
|
|
|
|
}
|
|
|
|
|
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_HALF(csends);
|
|
|
|
CHECK_RANGE_HALF(creads);
|
|
|
|
CHECK_RANGE_HALF(sreads);
|
|
|
|
CHECK_RANGE_HALF(ssends);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_POST(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_GET(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_POST_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_GET_TLS(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
2021-05-14 11:50:33 +03:00
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_POST_quota(void **state) {
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_GET_quota(void **state) {
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_POST_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, true);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_half_recv_half_send_GET_TLS_quota(void **state) {
|
|
|
|
atomic_store(&use_TLS, true);
|
|
|
|
atomic_store(&POST, false);
|
|
|
|
atomic_store(&check_listener_quota, true);
|
|
|
|
doh_half_recv_half_send(state);
|
|
|
|
}
|
|
|
|
|
2021-08-10 17:02:19 +03:00
|
|
|
/* See: GL #2858, !5319 */
|
|
|
|
static void
|
|
|
|
doh_bad_connect_uri(void **state) {
|
|
|
|
isc_nm_t **nm = (isc_nm_t **)*state;
|
|
|
|
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);
|
|
|
|
|
|
|
|
result = isc_nm_listenhttp(listen_nm, &tcp_listen_addr, 0, quotap,
|
|
|
|
server_tlsctx, endpoints, 0, &listen_sock);
|
|
|
|
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);
|
|
|
|
|
|
|
|
while (atomic_load(&nsends) > 0) {
|
|
|
|
if (atomic_load(&was_error)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
isc_thread_yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_nm_stoplistening(listen_sock);
|
|
|
|
isc_nmsocket_close(&listen_sock);
|
|
|
|
assert_null(listen_sock);
|
|
|
|
isc__netmgr_shutdown(connect_nm);
|
|
|
|
|
|
|
|
X(total_sends);
|
|
|
|
X(csends);
|
|
|
|
X(creads);
|
|
|
|
X(sreads);
|
|
|
|
X(ssends);
|
|
|
|
|
|
|
|
/* As we used an ill-formed URI, there ought to be an error. */
|
|
|
|
assert_true(atomic_load(&was_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);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
static void
|
|
|
|
doh_parse_GET_query_string(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_base64url_to_base64(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
char *res;
|
|
|
|
size_t res_len = 0;
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4=";
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3U";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U=";
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg";
|
|
|
|
char res_test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg";
|
|
|
|
char res_test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
NULL);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, 0, &res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "";
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg==";
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&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;
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64url_to_base64(test_mctx, NULL, 31231,
|
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
doh_base64_to_base64url(void **state) {
|
|
|
|
char *res;
|
|
|
|
size_t res_len = 0;
|
|
|
|
UNUSED(state);
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3VyZS4=";
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3Vy";
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhc3U";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhc3U=";
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw==";
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "PDw_Pz8-Pg";
|
|
|
|
char test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(res_len == strlen(res_test));
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* valid */
|
|
|
|
{
|
|
|
|
char res_test[] = "PDw_Pz8-Pg";
|
|
|
|
char test[] = "PDw/Pz8+Pg==";
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
NULL);
|
|
|
|
assert_non_null(res);
|
|
|
|
assert_true(strcmp(res, res_test) == 0);
|
|
|
|
isc_mem_free(test_mctx, res);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "YW55IGNhcm5hbCBwbGVhcw";
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, 0, &res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "";
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
char test[] = "PDw_Pz8-Pg==";
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&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;
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, test, strlen(test),
|
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
/* invalid */
|
|
|
|
{
|
|
|
|
res_len = 0;
|
|
|
|
|
|
|
|
res = isc__nm_base64_to_base64url(test_mctx, NULL, 31231,
|
|
|
|
&res_len);
|
|
|
|
assert_null(res);
|
|
|
|
assert_true(res_len == 0);
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 09:28:23 +01:00
|
|
|
|
2021-05-19 18:03:11 +03:00
|
|
|
static void
|
|
|
|
doh_path_validation(void **state) {
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2021-08-12 10:14:30 +03:00
|
|
|
static void
|
|
|
|
doh_connect_makeuri(void **state) {
|
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];
|
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:19:10 +02:00
|
|
|
int
|
|
|
|
main(void) {
|
2021-02-02 09:28:23 +01:00
|
|
|
const struct CMUnitTest tests_short[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(mock_doh_uv_tcp_bind, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_parse_GET_query_string,
|
|
|
|
NULL, NULL),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_base64url_to_base64, NULL,
|
|
|
|
NULL),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_base64_to_base64url, NULL,
|
|
|
|
NULL),
|
2021-05-19 18:03:11 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_path_validation, NULL,
|
|
|
|
NULL),
|
2021-08-12 10:14:30 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_connect_makeuri, NULL,
|
|
|
|
NULL),
|
2021-02-02 09:28:23 +01:00
|
|
|
cmocka_unit_test_setup_teardown(doh_noop_POST, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_noop_GET, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_noresponse_POST, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_noresponse_GET, nm_setup,
|
|
|
|
nm_teardown),
|
2021-08-10 17:02:19 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_bad_connect_uri, nm_setup,
|
|
|
|
nm_teardown),
|
2021-02-02 09:28:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct CMUnitTest tests_long[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(mock_doh_uv_tcp_bind, nm_setup,
|
|
|
|
nm_teardown),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_parse_GET_query_string,
|
|
|
|
NULL, NULL),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_base64url_to_base64, NULL,
|
|
|
|
NULL),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_base64_to_base64url, NULL,
|
|
|
|
NULL),
|
2021-05-19 18:03:11 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_path_validation, NULL,
|
|
|
|
NULL),
|
2021-08-12 10:14:30 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_connect_makeuri, NULL,
|
|
|
|
NULL),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_noop_POST, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_noop_GET, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_noresponse_POST, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_noresponse_GET, nm_setup,
|
|
|
|
nm_teardown),
|
2021-04-21 11:55:40 -07:00
|
|
|
cmocka_unit_test_setup_teardown(doh_timeout_recovery_POST,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_timeout_recovery_GET,
|
|
|
|
nm_setup, nm_teardown),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_POST, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_GET, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_POST_TLS, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_GET_TLS, nm_setup,
|
|
|
|
nm_teardown),
|
2021-05-14 11:50:33 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_POST_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_GET_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_POST_TLS_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_one_GET_TLS_quota,
|
|
|
|
nm_setup, nm_teardown),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_POST, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_GET, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_POST_TLS, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_GET_TLS, nm_setup,
|
|
|
|
nm_teardown),
|
2021-05-14 11:50:33 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_POST_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_GET_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_POST_TLS_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_two_GET_TLS_quota,
|
|
|
|
nm_setup, nm_teardown),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_GET, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_POST, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_GET_TLS, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_POST_TLS,
|
|
|
|
nm_setup, nm_teardown),
|
2021-05-14 11:50:33 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_GET_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_POST_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_GET_TLS_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_send_POST_TLS_quota,
|
|
|
|
nm_setup, nm_teardown),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_half_send_GET,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_half_send_POST,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_half_send_GET_TLS,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_half_send_POST_TLS,
|
|
|
|
nm_setup, nm_teardown),
|
2021-05-14 11:50:33 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_half_send_GET_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_recv_half_send_POST_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_recv_half_send_GET_TLS_quota, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_recv_half_send_POST_TLS_quota, nm_setup,
|
|
|
|
nm_teardown),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_send_GET,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_send_POST,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_send_GET_TLS,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_send_POST_TLS,
|
|
|
|
nm_setup, nm_teardown),
|
2021-05-14 11:50:33 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_send_GET_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_send_POST_quota,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_half_recv_send_GET_TLS_quota, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_half_recv_send_POST_TLS_quota, nm_setup,
|
|
|
|
nm_teardown),
|
2020-12-07 14:19:10 +02:00
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_half_send_GET,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_half_send_POST,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(doh_half_recv_half_send_GET_TLS,
|
|
|
|
nm_setup, nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_half_recv_half_send_POST_TLS, nm_setup,
|
|
|
|
nm_teardown),
|
2021-05-14 11:50:33 +03:00
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_half_recv_half_send_GET_quota, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_half_recv_half_send_POST_quota, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_half_recv_half_send_GET_TLS_quota, nm_setup,
|
|
|
|
nm_teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(
|
|
|
|
doh_half_recv_half_send_POST_TLS_quota, nm_setup,
|
|
|
|
nm_teardown),
|
2021-08-10 17:02:19 +03:00
|
|
|
cmocka_unit_test_setup_teardown(doh_bad_connect_uri, nm_setup,
|
|
|
|
nm_teardown),
|
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
|
|
|
int result = 0;
|
2020-12-07 14:19:10 +02:00
|
|
|
|
2021-02-02 09:28:23 +01:00
|
|
|
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
|
|
UNUSED(tests_long);
|
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 = (cmocka_run_group_tests(tests_short, _setup, _teardown));
|
2021-02-02 09:28:23 +01:00
|
|
|
#else
|
|
|
|
if (getenv("CI") != NULL || !reuse_supported) {
|
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 = (cmocka_run_group_tests(tests_short, _setup,
|
|
|
|
_teardown));
|
2021-02-02 09:28:23 +01:00
|
|
|
} else {
|
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 =
|
|
|
|
(cmocka_run_group_tests(tests_long, _setup, _teardown));
|
2021-02-02 09:28:23 +01:00
|
|
|
}
|
|
|
|
#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
|
|
|
return result;
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void) {
|
2021-07-16 14:57:08 +03:00
|
|
|
#if HAVE_LIBNGHTTP2
|
2020-12-07 14:19:10 +02:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
2021-07-16 14:57:08 +03:00
|
|
|
#else
|
|
|
|
printf("1..0 # Skipped: libnghttp2 is not available\n");
|
|
|
|
#endif
|
2021-02-15 17:20:50 +01:00
|
|
|
return (SKIPPED_TEST_EXIT_CODE);
|
2020-12-07 14:19:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* if HAVE_CMOCKA */
|