http: cover various non RFC3986 conformant URIs

- http/basic_trailing_space -- covers cases when there is trailing space
  after the request line (nginx handles this)
- http/simple_nonconformant -- covers non RFC3986 conformant URIs
This commit is contained in:
Azat Khuzhin 2018-10-22 23:38:42 +03:00
parent b94d913d90
commit 15bfe712a7
No known key found for this signature in database
GPG Key ID: B86086848EF8686D

View File

@ -150,6 +150,7 @@ http_setup_gencb(ev_uint16_t *pport, struct event_base *base, int mask,
/* Register a callback for certain types of requests */
evhttp_set_cb(myhttp, "/test", http_basic_cb, myhttp);
evhttp_set_cb(myhttp, "/test nonconformant", http_basic_cb, myhttp);
evhttp_set_cb(myhttp, "/timeout", http_timeout_cb, myhttp);
evhttp_set_cb(myhttp, "/large", http_large_cb, base);
evhttp_set_cb(myhttp, "/chunked", http_chunked_cb, base);
@ -493,7 +494,7 @@ create_bev(struct event_base *base, int fd, int ssl_mask)
}
static void
http_basic_test_impl(void *arg, int ssl)
http_basic_test_impl(void *arg, int ssl, const char *request_line)
{
struct basic_test_data *data = arg;
struct timeval tv;
@ -503,6 +504,7 @@ http_basic_test_impl(void *arg, int ssl)
ev_uint16_t port = 0, port2 = 0;
int server_flags = ssl ? HTTP_BIND_SSL : 0;
struct evhttp *http = http_setup(&port, data->base, server_flags);
struct evbuffer *out;
exit_base = data->base;
test_ok = 0;
@ -519,13 +521,13 @@ http_basic_test_impl(void *arg, int ssl)
bev = create_bev(data->base, fd, ssl);
bufferevent_setcb(bev, http_readcb, http_writecb,
http_errorcb, data->base);
out = bufferevent_get_output(bev);
/* first half of the http request */
http_request =
"GET /test HTTP/1.1\r\n"
"Host: some";
evbuffer_add_printf(out,
"%s\r\n"
"Host: some", request_line);
bufferevent_write(bev, http_request, strlen(http_request));
evutil_timerclear(&tv);
tv.tv_usec = 100000;
event_base_once(data->base,
@ -533,7 +535,7 @@ http_basic_test_impl(void *arg, int ssl)
event_base_dispatch(data->base);
tt_assert(test_ok == 3);
tt_int_op(test_ok, ==, 3);
/* connect to the second port */
bufferevent_free(bev);
@ -545,18 +547,17 @@ http_basic_test_impl(void *arg, int ssl)
bev = create_bev(data->base, fd, ssl);
bufferevent_setcb(bev, http_readcb, http_writecb,
http_errorcb, data->base);
out = bufferevent_get_output(bev);
http_request =
"GET /test HTTP/1.1\r\n"
evbuffer_add_printf(out,
"%s\r\n"
"Host: somehost\r\n"
"Connection: close\r\n"
"\r\n";
bufferevent_write(bev, http_request, strlen(http_request));
"\r\n", request_line);
event_base_dispatch(data->base);
tt_assert(test_ok == 5);
tt_int_op(test_ok, ==, 5);
/* Connect to the second port again. This time, send an absolute uri. */
bufferevent_free(bev);
@ -579,14 +580,17 @@ http_basic_test_impl(void *arg, int ssl)
event_base_dispatch(data->base);
tt_assert(test_ok == 7);
tt_int_op(test_ok, ==, 7);
evhttp_free(http);
end:
if (bev)
bufferevent_free(bev);
}
static void http_basic_test(void *arg) { http_basic_test_impl(arg, 0); }
static void http_basic_test(void *arg)\
{ http_basic_test_impl(arg, 0, "GET /test HTTP/1.1"); }
static void http_basic_trailing_space_test(void *arg)
{ http_basic_test_impl(arg, 0, "GET /test HTTP/1.1 "); }
static void
@ -3642,7 +3646,7 @@ http_make_web_server(evutil_socket_t fd, short what, void *arg)
}
static void
http_simple_test_impl(void *arg, int ssl, int dirty)
http_simple_test_impl(void *arg, int ssl, int dirty, const char *uri)
{
struct basic_test_data *data = arg;
struct evhttp_connection *evcon = NULL;
@ -3667,9 +3671,8 @@ http_simple_test_impl(void *arg, int ssl, int dirty)
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
tt_assert(req);
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, uri) == -1)
tt_abort_msg("Couldn't make request");
}
event_base_dispatch(data->base);
tt_int_op(test_ok, ==, 1);
@ -3681,7 +3684,9 @@ http_simple_test_impl(void *arg, int ssl, int dirty)
evhttp_free(http);
}
static void http_simple_test(void *arg)
{ http_simple_test_impl(arg, 0, 0); }
{ http_simple_test_impl(arg, 0, 0, "/test"); }
static void http_simple_nonconformant_test(void *arg)
{ http_simple_test_impl(arg, 0, 0, "/test nonconformant"); }
static void
http_connection_retry_test_basic(void *arg, const char *addr, struct evdns_base *dns_base, int ssl)
@ -4761,17 +4766,17 @@ http_newreqcb_test(void *arg)
#ifdef EVENT__HAVE_OPENSSL
static void https_basic_test(void *arg)
{ http_basic_test_impl(arg, 1); }
{ http_basic_test_impl(arg, 1, "GET /test HTTP/1.1"); }
static void https_filter_basic_test(void *arg)
{ http_basic_test_impl(arg, 1 | HTTP_SSL_FILTER); }
{ http_basic_test_impl(arg, 1 | HTTP_SSL_FILTER, "GET /test HTTP/1.1"); }
static void https_incomplete_test(void *arg)
{ http_incomplete_test_(arg, 0, 1); }
static void https_incomplete_timeout_test(void *arg)
{ http_incomplete_test_(arg, 1, 1); }
static void https_simple_test(void *arg)
{ http_simple_test_impl(arg, 1, 0); }
{ http_simple_test_impl(arg, 1, 0, "/test"); }
static void https_simple_dirty_test(void *arg)
{ http_simple_test_impl(arg, 1, 1); }
{ http_simple_test_impl(arg, 1, 1, "/test"); }
static void https_connection_retry_conn_address_test(void *arg)
{ http_connection_retry_conn_address_test_impl(arg, 1); }
static void https_connection_retry_test(void *arg)
@ -4801,7 +4806,9 @@ struct testcase_t http_testcases[] = {
{ "parse_uri_nc", http_parse_uri_test, 0, &basic_setup, (void*)"nc" },
{ "uriencode", http_uriencode_test, 0, NULL, NULL },
HTTP(basic),
HTTP(basic_trailing_space),
HTTP(simple),
HTTP(simple_nonconformant),
HTTP_N(cancel, cancel, BASIC),
HTTP_N(cancel_by_host, cancel, BY_HOST),