test/http: https basic

This commit is contained in:
Azat Khuzhin 2015-11-05 19:12:58 +03:00
parent 615490d048
commit 59714b46bc

View File

@ -300,6 +300,9 @@ http_writecb(struct bufferevent *bev, void *arg)
static void static void
http_errorcb(struct bufferevent *bev, short what, void *arg) http_errorcb(struct bufferevent *bev, short what, void *arg)
{ {
/** For ssl */
if (what & BEV_EVENT_CONNECTED)
return;
test_ok = -2; test_ok = -2;
event_base_loopexit(arg, NULL); event_base_loopexit(arg, NULL);
} }
@ -446,7 +449,7 @@ create_bev(struct event_base *base, int fd, int ssl)
} }
static void static void
http_basic_test(void *arg) http_basic_test_impl(void *arg, int ssl)
{ {
struct basic_test_data *data = arg; struct basic_test_data *data = arg;
struct timeval tv; struct timeval tv;
@ -454,13 +457,14 @@ http_basic_test(void *arg)
evutil_socket_t fd; evutil_socket_t fd;
const char *http_request; const char *http_request;
ev_uint16_t port = 0, port2 = 0; ev_uint16_t port = 0, port2 = 0;
int server_flags = ssl ? HTTP_BIND_SSL : 0;
test_ok = 0; test_ok = 0;
http = http_setup(&port, data->base, 0); http = http_setup(&port, data->base, server_flags);
/* bind to a second socket */ /* bind to a second socket */
if (http_bind(http, &port2, 0) == -1) { if (http_bind(http, &port2, server_flags) == -1) {
fprintf(stdout, "FAILED (bind)\n"); fprintf(stdout, "FAILED (bind)\n");
exit(1); exit(1);
} }
@ -468,7 +472,7 @@ http_basic_test(void *arg)
fd = http_connect("127.0.0.1", port); fd = http_connect("127.0.0.1", port);
/* Stupid thing to send a request */ /* Stupid thing to send a request */
bev = bufferevent_socket_new(data->base, fd, 0); bev = create_bev(data->base, fd, ssl);
bufferevent_setcb(bev, http_readcb, http_writecb, bufferevent_setcb(bev, http_readcb, http_writecb,
http_errorcb, data->base); http_errorcb, data->base);
@ -494,7 +498,7 @@ http_basic_test(void *arg)
fd = http_connect("127.0.0.1", port2); fd = http_connect("127.0.0.1", port2);
/* Stupid thing to send a request */ /* Stupid thing to send a request */
bev = bufferevent_socket_new(data->base, fd, 0); bev = create_bev(data->base, fd, ssl);
bufferevent_setcb(bev, http_readcb, http_writecb, bufferevent_setcb(bev, http_readcb, http_writecb,
http_errorcb, data->base); http_errorcb, data->base);
@ -517,8 +521,7 @@ http_basic_test(void *arg)
fd = http_connect("127.0.0.1", port2); fd = http_connect("127.0.0.1", port2);
/* Stupid thing to send a request */ /* Stupid thing to send a request */
bev = bufferevent_socket_new(data->base, fd, 0); bev = create_bev(data->base, fd, ssl);
bufferevent_setcb(bev, http_readcb, http_writecb, bufferevent_setcb(bev, http_readcb, http_writecb,
http_errorcb, data->base); http_errorcb, data->base);
@ -539,6 +542,10 @@ http_basic_test(void *arg)
if (bev) if (bev)
bufferevent_free(bev); bufferevent_free(bev);
} }
static void http_basic_test(void *arg)
{ return http_basic_test_impl(arg, 0); }
static void https_basic_test(void *arg)
{ return http_basic_test_impl(arg, 1); }
static void static void
@ -4278,6 +4285,7 @@ struct testcase_t http_testcases[] = {
HTTP(request_own), HTTP(request_own),
#ifdef EVENT__HAVE_OPENSSL #ifdef EVENT__HAVE_OPENSSL
HTTPS(basic),
HTTPS(simple), HTTPS(simple),
HTTPS(simple_dirty), HTTPS(simple_dirty),
HTTPS(incomplete), HTTPS(incomplete),