test-http-server-errors.c revision 5f1d689131a75c39f064cbd4202373e7edf78f18
/* Copyright (c) 2016-2017 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "hostpid.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "time-util.h"
#include "connection.h"
#include "test-common.h"
#include "http-url.h"
#include "http-request.h"
#include "http-server.h"
#include <signal.h>
#include <unistd.h>
/*
* Types
*/
struct client_connection {
struct connection conn;
};
typedef void (*test_server_init_t)
(const struct http_server_settings *server_set);
typedef void (*test_client_init_t)(unsigned int index);
/*
* State
*/
/* common */
/* server */
static int fd_listen = -1;
/* client */
static struct connection_list *client_conn_list;
static unsigned int client_pids_count = 0;
static unsigned int client_index;
/*
* Forward declarations
*/
/* server */
static void
static void
/* client */
static void test_client_run(unsigned int index);
/* test*/
static void test_run_client_server(
const struct http_server_settings *server_set,
unsigned int client_tests_count)
ATTR_NULL(3);
/*
* Slow request
*/
/* client */
static void
{
/* do nothing */
}
static void
{
"GET / HTTP/1.1\r\n"
"Host: example.com\r\n"
"\r\n");
}
static void test_client_slow_request(unsigned int index)
{
}
/* server */
struct _slow_request {
struct http_server_request *req;
bool serviced:1;
};
static void
{
}
static void
{
struct http_server_response *resp;
}
static void
struct http_server_request *req)
{
const struct http_request *hreq =
struct _slow_request *ctx;
if (debug) {
i_debug("REQUEST: %s %s HTTP/%u.%u",
}
}
static void test_server_slow_request
(const struct http_server_settings *server_set)
{
}
/* test */
static void test_slow_request(void)
{
struct http_server_settings http_server_set;
test_begin("slow request");
test_end();
}
/*
* Hanging request payload
*/
/* client */
static void
{
"GET / HTTP/1.1\r\n"
"Host: example.com\r\n"
"Content-Length: 1000\r\n"
"\r\n"
"To be continued... or not");
}
static void test_client_hanging_request_payload(unsigned int index)
{
}
/* server */
struct _hanging_request_payload {
struct http_server_request *req;
struct istream *payload_input;
bool serviced:1;
};
static void
{
}
static void
{
struct http_server_response *resp;
const unsigned char *data;
int ret;
if (debug)
i_debug("test server: got more payload");
while ((ret=i_stream_read_data
}
if (ret == 0)
return;
if (debug) {
i_debug("test server: failed to read payload: %s",
}
400, "Bad request");
return;
}
}
static void
struct http_server_request *req)
{
const struct http_request *hreq =
struct _hanging_request_payload *ctx;
if (debug) {
i_debug("REQUEST: %s %s HTTP/%u.%u",
}
ctx->payload_input =
}
static void test_server_hanging_request_payload
(const struct http_server_settings *server_set)
{
}
/* test */
static void test_hanging_request_payload(void)
{
struct http_server_settings http_server_set;
test_begin("hanging request payload");
test_end();
}
/*
* Hanging response payload
*/
/* client */
static void
{
"GET / HTTP/1.1\r\n"
"Host: example.com\r\n"
"Content-Length: 18\r\n"
"\r\n"
"Complete payload\r\n");
}
static void test_client_hanging_response_payload(unsigned int index)
{
}
/* server */
struct _hanging_response_payload {
struct http_server_request *req;
struct istream *payload_input;
bool serviced:1;
};
static void
{
}
static void
struct http_server_request *req)
{
const struct http_request *hreq =
struct http_server_response *resp;
struct _hanging_response_payload *ctx;
unsigned int i;
if (debug) {
i_debug("REQUEST: %s %s HTTP/%u.%u",
}
T_BEGIN {
for (i = 0; i < 3200; i++) {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n");
}
} T_END;
}
static void test_server_hanging_response_payload
(const struct http_server_settings *server_set)
{
}
/* test */
static void test_hanging_response_payload(void)
{
struct http_server_settings http_server_set;
test_begin("hanging response payload");
test_end();
}
/*
* Excessive payload length
*/
/* client */
static void
{
"GET / HTTP/1.1\r\n"
"Host: example.com\r\n"
"Content-Length: 150\r\n"
"\r\n"
"Too long\r\nToo long\r\nToo long\r\nToo long\r\nToo long\r\n"
"Too long\r\nToo long\r\nToo long\r\nToo long\r\nToo long\r\n"
"Too long\r\nToo long\r\nToo long\r\nToo long\r\nToo long\r\n");
}
static void
test_client_excessive_payload_length1(unsigned int index)
{
}
static void
{
"GET / HTTP/1.1\r\n"
"Host: example.com\r\n"
"Transfer-Encoding: chunked\r\n"
"\r\n"
"32\r\n"
"Too long\r\nToo long\r\nToo long\r\nToo long\r\nToo long\r\n"
"\r\n"
"32\r\n"
"Too long\r\nToo long\r\nToo long\r\nToo long\r\nToo long\r\n"
"\r\n"
"32\r\n"
"Too long\r\nToo long\r\nToo long\r\nToo long\r\nToo long\r\n"
"\r\n"
"0\r\n"
"\r\n");
}
static void
test_client_excessive_payload_length2(unsigned int index)
{
}
/* server */
struct _excessive_payload_length {
struct http_server_request *req;
bool serviced:1;
};
static void
struct _excessive_payload_length *ctx)
{
struct http_server_response *resp;
const char *reason;
int status;
}
}
static void
struct _excessive_payload_length *ctx)
{
struct http_server_response *resp;
}
static void
struct http_server_request *req)
{
const struct http_request *hreq =
struct _excessive_payload_length *ctx;
if (debug) {
i_debug("REQUEST: %s %s HTTP/%u.%u",
}
}
static void test_server_excessive_payload_length
(const struct http_server_settings *server_set)
{
}
/* test */
static void test_excessive_payload_length(void)
{
struct http_server_settings http_server_set;
test_begin("excessive payload length (length)");
test_end();
test_begin("excessive payload length (chunked)");
test_end();
}
/*
* All tests
*/
static void (*const test_functions[])(void) = {
};
/*
* Test client
*/
/* client connection */
static void
{
if (test_client_input != NULL)
}
static void
{
}
static void
{
struct client_connection *conn;
}
static void
{
}
static void
{
struct client_connection *conn =
(struct client_connection *)_conn;
}
/* */
static struct connection_settings client_connection_set = {
};
static const struct connection_vfuncs client_connection_vfuncs = {
};
static void test_client_run(unsigned int index)
{
if (debug)
/* close server socket */
}
/*
* Test server
*/
static void
{
/* server settings */
}
/* client connection */
static void
struct http_server_request *req)
{
}
struct http_server_callbacks http_server_callbacks = {
};
static void
{
int fd;
/* accept new client */
if (fd == -1)
return;
if (fd == -2) {
i_fatal("test server: accept() failed: %m");
}
}
/* */
static void
{
i_fatal("Server timed out");
}
static void
{
/* open server socket */
/* close server socket */
timeout_remove(&to);
}
/*
* Tests
*/
static int test_open_server_fd(void)
{
if (debug)
if (fd == -1) {
i_fatal("listen(%s:%u) failed: %m",
}
return fd;
}
static void test_clients_kill_all(void)
{
unsigned int i;
if (client_pids_count > 0) {
for (i = 0; i < client_pids_count; i++) {
client_pids[i] = -1;
}
}
}
client_pids_count = 0;
}
static void test_run_client_server(
const struct http_server_settings *server_set,
unsigned int client_tests_count)
{
unsigned int i;
client_pids = NULL;
client_pids_count = 0;
if (client_tests_count > 0) {
for (i = 0; i < client_tests_count; i++)
for (i = 0; i < client_tests_count; i++) {
i_fatal("fork() failed: %m");
if (client_pids[i] == 0) {
client_pids_count = 0;
hostpid_init();
if (debug)
/* child: client */
ioloop = io_loop_create();
client_test(i);
/* wait for it to be killed; this way, valgrind will not
object to this process going away inelegantly. */
sleep(60);
exit(1);
}
}
if (debug)
}
/* parent: server */
ioloop = io_loop_create();
}
/*
* Main
*/
volatile sig_atomic_t terminating = 0;
static void
test_signal_handler(int signo)
{
if (terminating != 0)
terminating = 1;
/* make sure we don't leave any pesky children alive */
}
static void test_atexit(void)
{
}
{
int c;
switch (c) {
case 'D':
break;
default:
}
}
/* listen on localhost */
}