mirror of
https://github.com/libevent/libevent.git
synced 2025-01-20 05:02:55 +08:00
Add regress test ipv6_for_domain.
Written for commit 71e709c7829275a594f767b27468b1b52e8b5bb9. Fix ipv6 support for http. When URL contain domain, not IP address.
This commit is contained in:
parent
71e709c782
commit
9ec88bdf5f
@ -80,12 +80,16 @@ static void http_large_delay_cb(struct evhttp_request *req, void *arg);
|
||||
static void http_badreq_cb(struct evhttp_request *req, void *arg);
|
||||
static void http_dispatcher_cb(struct evhttp_request *req, void *arg);
|
||||
static int
|
||||
http_bind(struct evhttp *myhttp, ev_uint16_t *pport)
|
||||
http_bind(struct evhttp *myhttp, ev_uint16_t *pport, int ipv6)
|
||||
{
|
||||
int port;
|
||||
struct evhttp_bound_socket *sock;
|
||||
|
||||
sock = evhttp_bind_socket_with_handle(myhttp, "127.0.0.1", *pport);
|
||||
if (ipv6)
|
||||
sock = evhttp_bind_socket_with_handle(myhttp, "::1", *pport);
|
||||
else
|
||||
sock = evhttp_bind_socket_with_handle(myhttp, "127.0.0.1", *pport);
|
||||
|
||||
if (sock == NULL)
|
||||
event_errx(1, "Could not start web server");
|
||||
|
||||
@ -98,14 +102,14 @@ http_bind(struct evhttp *myhttp, ev_uint16_t *pport)
|
||||
}
|
||||
|
||||
static struct evhttp *
|
||||
http_setup(ev_uint16_t *pport, struct event_base *base)
|
||||
http_setup(ev_uint16_t *pport, struct event_base *base, int ipv6)
|
||||
{
|
||||
struct evhttp *myhttp;
|
||||
|
||||
/* Try a few different ports */
|
||||
myhttp = evhttp_new(base);
|
||||
|
||||
if (http_bind(myhttp, pport) < 0)
|
||||
if (http_bind(myhttp, pport, ipv6) < 0)
|
||||
return NULL;
|
||||
|
||||
/* Register a callback for certain types of requests */
|
||||
@ -377,10 +381,10 @@ http_basic_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
/* bind to a second socket */
|
||||
if (http_bind(http, &port2) == -1) {
|
||||
if (http_bind(http, &port2, 0) == -1) {
|
||||
fprintf(stdout, "FAILED (bind)\n");
|
||||
exit(1);
|
||||
}
|
||||
@ -565,10 +569,10 @@ http_bad_request_test(void *arg)
|
||||
test_ok = 0;
|
||||
exit_base = data->base;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
/* bind to a second socket */
|
||||
if (http_bind(http, &port2) == -1)
|
||||
if (http_bind(http, &port2, 0) == -1)
|
||||
TT_DIE(("Bind socket failed"));
|
||||
|
||||
/* NULL request test */
|
||||
@ -683,7 +687,7 @@ http_delete_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
fd = http_connect("127.0.0.1", port);
|
||||
|
||||
@ -744,7 +748,7 @@ http_allowed_methods_test(void *arg)
|
||||
exit_base = data->base;
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
fd1 = http_connect("127.0.0.1", port);
|
||||
|
||||
@ -835,7 +839,7 @@ static void http_request_done(struct evhttp_request *, void *);
|
||||
static void http_request_empty_done(struct evhttp_request *, void *);
|
||||
|
||||
static void
|
||||
http_connection_test_(struct basic_test_data *data, int persistent)
|
||||
http_connection_test_(struct basic_test_data *data, int persistent, const char *address, struct evdns_base *dnsbase, int ipv6)
|
||||
{
|
||||
ev_uint16_t port = 0;
|
||||
struct evhttp_connection *evcon = NULL;
|
||||
@ -843,9 +847,9 @@ http_connection_test_(struct basic_test_data *data, int persistent)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, ipv6);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
evcon = evhttp_connection_base_new(data->base, dnsbase, address, port);
|
||||
tt_assert(evcon);
|
||||
|
||||
tt_assert(evhttp_connection_get_base(evcon) == data->base);
|
||||
@ -918,12 +922,12 @@ http_connection_test_(struct basic_test_data *data, int persistent)
|
||||
static void
|
||||
http_connection_test(void *arg)
|
||||
{
|
||||
http_connection_test_(arg, 0);
|
||||
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0);
|
||||
}
|
||||
static void
|
||||
http_persist_connection_test(void *arg)
|
||||
{
|
||||
http_connection_test_(arg, 1);
|
||||
http_connection_test_(arg, 1, "127.0.0.1", NULL, 0);
|
||||
}
|
||||
|
||||
static struct regress_dns_server_table search_table[] = {
|
||||
@ -955,7 +959,7 @@ http_connection_async_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, dns_base, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -1064,7 +1068,7 @@ http_cancel_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -1186,7 +1190,7 @@ http_virtual_host_test(void *arg)
|
||||
|
||||
exit_base = data->base;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
/* virtual host */
|
||||
second = evhttp_new(NULL);
|
||||
@ -1427,7 +1431,7 @@ http_dispatcher_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -1477,7 +1481,7 @@ http_post_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -1617,7 +1621,7 @@ http_put_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -1743,7 +1747,7 @@ http_failure_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
fd = http_connect("127.0.0.1", port);
|
||||
|
||||
@ -1832,7 +1836,7 @@ http_close_detection_(struct basic_test_data *data, int with_delay)
|
||||
const struct timeval sec_tenth = { 0, 100000 };
|
||||
|
||||
test_ok = 0;
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
/* .1 second timeout */
|
||||
evhttp_set_timeout_tv(http, &sec_tenth);
|
||||
@ -2498,7 +2502,7 @@ http_base_test(void *ptr)
|
||||
|
||||
test_ok = 0;
|
||||
base = event_base_new();
|
||||
http = http_setup(&port, base);
|
||||
http = http_setup(&port, base, 0);
|
||||
|
||||
fd = http_connect("127.0.0.1", port);
|
||||
|
||||
@ -2580,7 +2584,7 @@ http_incomplete_test_(struct basic_test_data *data, int use_timeout)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
evhttp_set_timeout(http, 1);
|
||||
|
||||
fd = http_connect("127.0.0.1", port);
|
||||
@ -2794,7 +2798,7 @@ http_chunk_out_test(void *arg)
|
||||
exit_base = data->base;
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
fd = http_connect("127.0.0.1", port);
|
||||
|
||||
@ -2866,7 +2870,7 @@ http_stream_out_test(void *arg)
|
||||
test_ok = 0;
|
||||
exit_base = data->base;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -2934,7 +2938,7 @@ http_stream_in_test_(struct basic_test_data *data, char const *url,
|
||||
ev_uint16_t port = 0;
|
||||
|
||||
exit_base = data->base;
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL,"127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -3005,7 +3009,7 @@ http_stream_in_cancel_test(void *arg)
|
||||
struct evhttp_request *req = NULL;
|
||||
ev_uint16_t port = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -3056,7 +3060,7 @@ http_connection_fail_test(void *arg)
|
||||
test_ok = 0;
|
||||
|
||||
/* auto detect a port */
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
evhttp_free(http);
|
||||
http = NULL;
|
||||
|
||||
@ -3107,7 +3111,7 @@ static void
|
||||
http_make_web_server(evutil_socket_t fd, short what, void *arg)
|
||||
{
|
||||
ev_uint16_t port = *(ev_uint16_t*)arg;
|
||||
http = http_setup(&port, http_make_web_server_base);
|
||||
http = http_setup(&port, http_make_web_server_base, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -3123,7 +3127,7 @@ http_connection_retry_test(void *arg)
|
||||
test_ok = 0;
|
||||
|
||||
/* auto detect a port */
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
evhttp_free(http);
|
||||
http = NULL;
|
||||
|
||||
@ -3275,7 +3279,7 @@ http_multi_line_header_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
fd = http_connect("127.0.0.1", port);
|
||||
|
||||
@ -3335,7 +3339,7 @@ http_negative_content_length_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -3394,7 +3398,7 @@ http_data_length_constraints_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
||||
tt_assert(evcon);
|
||||
@ -3552,7 +3556,7 @@ http_terminate_chunked_test(void *arg)
|
||||
|
||||
test_ok = 0;
|
||||
|
||||
http = http_setup(&port, data->base);
|
||||
http = http_setup(&port, data->base, 0);
|
||||
evhttp_del_cb(http, "/test");
|
||||
tt_assert(evhttp_set_cb(http, "/test",
|
||||
terminate_chunked_cb, &terminate_state) == 0);
|
||||
@ -3593,6 +3597,37 @@ http_terminate_chunked_test(void *arg)
|
||||
evhttp_free(http);
|
||||
}
|
||||
|
||||
static struct regress_dns_server_table ipv6_search_table[] = {
|
||||
{ "localhost", "AAAA", "::1", 0 },
|
||||
{ NULL, NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
static void
|
||||
http_ipv6_for_domain_test(void *arg)
|
||||
{
|
||||
struct basic_test_data *data = arg;
|
||||
struct evdns_base *dns_base = NULL;
|
||||
ev_uint16_t portnum = 0;
|
||||
char address[64];
|
||||
|
||||
tt_assert(regress_dnsserver(data->base, &portnum, ipv6_search_table));
|
||||
|
||||
dns_base = evdns_base_new(data->base, 0/* init name servers */);
|
||||
tt_assert(dns_base);
|
||||
|
||||
/* Add ourself as the only nameserver, and make sure we really are
|
||||
* the only nameserver. */
|
||||
evutil_snprintf(address, sizeof(address), "127.0.0.1:%d", portnum);
|
||||
evdns_base_nameserver_ip_add(dns_base, address);
|
||||
|
||||
http_connection_test_(arg, 0 /* not persistent */, "localhost", dns_base, 1 /* ipv6 */);
|
||||
|
||||
end:
|
||||
if (dns_base)
|
||||
evdns_base_free(dns_base, 0);
|
||||
regress_clean_dnsserver();
|
||||
}
|
||||
|
||||
#define HTTP_LEGACY(name) \
|
||||
{ #name, run_legacy_test_fn, TT_ISOLATED|TT_LEGACY, &legacy_setup, \
|
||||
http_##name##_test }
|
||||
@ -3640,6 +3675,8 @@ struct testcase_t http_testcases[] = {
|
||||
HTTP(connection_retry),
|
||||
HTTP(data_length_constraints),
|
||||
|
||||
HTTP(ipv6_for_domain),
|
||||
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user