annotate src/lib-http/test-http-server-errors.c @ 23017:c1d36f2575c7 default tip

lib-imap: Fix "Don't accept strings with NULs" cherry-pick
author Timo Sirainen <timo.sirainen@open-xchange.com>
date Thu, 29 Aug 2019 09:55:25 +0300
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21761
diff changeset
1 /* Copyright (c) 2016-2018 Dovecot authors, see the included COPYING file */
20372
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
2
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
3 #include "lib.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
4 #include "str.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
5 #include "hostpid.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
6 #include "ioloop.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
7 #include "istream.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
8 #include "ostream.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
9 #include "time-util.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
10 #include "connection.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
11 #include "test-common.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
12 #include "http-url.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
13 #include "http-request.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
14 #include "http-server.h"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
15
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
16 #include <sys/types.h>
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
17 #include <sys/wait.h>
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
18 #include <signal.h>
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
19 #include <unistd.h>
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
20
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
21 #define SERVER_MAX_TIMEOUT_MSECS 10*1000
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
22
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
23 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
24 * Types
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
25 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
26
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
27 struct client_connection {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
28 struct connection conn;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
29
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
30 pool_t pool;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
31 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
32
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
33 typedef void (*test_server_init_t)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
34 (const struct http_server_settings *server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
35 typedef void (*test_client_init_t)(unsigned int index);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
36
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
37 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
38 * State
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
39 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
40
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
41 /* common */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
42 static struct ip_addr bind_ip;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
43 static in_port_t bind_port = 0;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
44 static struct ioloop *ioloop;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
45 static bool debug = FALSE;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
46
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
47 /* server */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
48 static struct http_server *http_server = NULL;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
49 static struct io *io_listen;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
50 static int fd_listen = -1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
51 static void (*test_server_request)(struct http_server_request *req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
52
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
53 /* client */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
54 static pid_t *client_pids = NULL;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
55 static struct connection_list *client_conn_list;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
56 static unsigned int client_pids_count = 0;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
57 static unsigned int client_index;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
58 static void (*test_client_connected)(struct client_connection *conn);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
59 static void (*test_client_input)(struct client_connection *conn);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
60
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
61 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
62 * Forward declarations
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
63 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
64
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
65 /* server */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
66 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
67 test_server_defaults(struct http_server_settings *http_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
68 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
69 test_server_run(const struct http_server_settings *http_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
70
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
71 /* client */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
72 static void test_client_run(unsigned int index);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
73
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
74 /* test*/
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
75 static void test_run_client_server(
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
76 const struct http_server_settings *server_set,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
77 test_server_init_t server_test,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
78 test_client_init_t client_test,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
79 unsigned int client_tests_count)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
80 ATTR_NULL(3);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
81
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
82 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
83 * Slow request
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
84 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
85
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
86 /* client */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
87
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
88 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
89 test_slow_request_input(struct client_connection *conn ATTR_UNUSED)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
90 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
91 /* do nothing */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
92 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
93
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
94 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
95 test_slow_request_connected(struct client_connection *conn)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
96 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
97 (void)o_stream_send_str(conn->conn.output,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
98 "GET / HTTP/1.1\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
99 "Host: example.com\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
100 "\r\n");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
101 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
102
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
103 static void test_client_slow_request(unsigned int index)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
104 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
105 test_client_input = test_slow_request_input;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
106 test_client_connected = test_slow_request_connected;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
107 test_client_run(index);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
108 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
109
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
110 /* server */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
111
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
112 struct _slow_request {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
113 struct http_server_request *req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
114 struct timeout *to_delay;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
115 unsigned int serviced:1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
116 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
117
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
118 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
119 test_server_slow_request_destroyed(void *context)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
120 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
121 struct _slow_request *ctx = (struct _slow_request *)context;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
122 test_assert(ctx->serviced);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
123 if (ctx->to_delay != NULL)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
124 timeout_remove(&ctx->to_delay);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
125 i_free(ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
126 io_loop_stop(ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
127 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
128
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
129 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
130 test_server_slow_request_delayed(struct _slow_request *ctx)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
131 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
132 struct http_server_response *resp;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
133 struct http_server_request *req = ctx->req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
134
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
135 resp = http_server_response_create(req, 200, "OK");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
136 http_server_response_submit(resp);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
137 ctx->serviced = TRUE;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
138
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
139 http_server_request_unref(&req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
140 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
141
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
142 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
143 test_server_slow_request_request(
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
144 struct http_server_request *req)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
145 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
146 const struct http_request *hreq =
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
147 http_server_request_get(req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
148 struct _slow_request *ctx;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
149
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
150 if (debug) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
151 i_debug("REQUEST: %s %s HTTP/%u.%u",
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
152 hreq->method, hreq->target_raw,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
153 hreq->version_major, hreq->version_minor);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
154 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
155
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
156 ctx = i_new(struct _slow_request, 1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
157 ctx->req = req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
158
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
159 http_server_request_set_destroy_callback(req,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
160 test_server_slow_request_destroyed, ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
161
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
162 http_server_request_ref(req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
163 ctx->to_delay = timeout_add
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
164 (4000, test_server_slow_request_delayed, ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
165 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
166
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
167 static void test_server_slow_request
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
168 (const struct http_server_settings *server_set)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
169 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
170 test_server_request = test_server_slow_request_request;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
171 test_server_run(server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
172 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
173
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
174 /* test */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
175
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
176 static void test_slow_request(void)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
177 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
178 struct http_server_settings http_server_set;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
179
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
180 test_server_defaults(&http_server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
181 http_server_set.max_client_idle_time_msecs = 1000;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
182
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
183 test_begin("slow request");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
184 test_run_client_server(&http_server_set,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
185 test_server_slow_request,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
186 test_client_slow_request, 1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
187 test_end();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
188 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
189
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
190 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
191 * Hanging request payload
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
192 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
193
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
194 /* client */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
195
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
196 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
197 test_hanging_request_payload_connected(struct client_connection *conn)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
198 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
199 (void)o_stream_send_str(conn->conn.output,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
200 "GET / HTTP/1.1\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
201 "Host: example.com\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
202 "Content-Length: 1000\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
203 "\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
204 "To be continued... or not");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
205 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
206
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
207 static void test_client_hanging_request_payload(unsigned int index)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
208 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
209 test_client_connected = test_hanging_request_payload_connected;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
210 test_client_run(index);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
211 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
212
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
213 /* server */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
214
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
215 struct _hanging_request_payload {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
216 struct http_server_request *req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
217 struct istream *payload_input;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
218 struct io *io;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
219 unsigned int serviced:1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
220 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
221
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
222 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
223 test_server_hanging_request_payload_destroyed(void *context)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
224 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
225 struct _hanging_request_payload *ctx =
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
226 (struct _hanging_request_payload *)context;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
227 test_assert(!ctx->serviced);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
228 if (ctx->io != NULL)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
229 io_remove(&ctx->io);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
230 i_free(ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
231 io_loop_stop(ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
232 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
233
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
234 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
235 test_server_hanging_request_payload_input(struct _hanging_request_payload *ctx)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
236 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
237 struct http_server_response *resp;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
238 struct http_server_request *req = ctx->req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
239 const unsigned char *data;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
240 size_t size;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
241 int ret;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
242
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
243 if (debug)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
244 i_debug("test server: got more payload");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
245
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
246 while ((ret=i_stream_read_data
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
247 (ctx->payload_input, &data, &size, 0)) > 0) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
248 i_stream_skip(ctx->payload_input, size);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
249 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
250
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
251 if (ret == 0)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
252 return;
21761
0a4ca3f1f285 lib-http: test-http-server-errors: Fixed logically dead code.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21390
diff changeset
253 if (ctx->payload_input->stream_errno != 0) {
20372
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
254 if (debug) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
255 i_debug("test server: failed to read payload: %s",
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
256 i_stream_get_error(ctx->payload_input));
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
257 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
258 i_stream_unref(&ctx->payload_input);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
259 io_remove(&ctx->io);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
260 http_server_request_fail_close(req,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
261 400, "Bad request");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
262 http_server_request_unref(&req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
263 return;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
264 }
21761
0a4ca3f1f285 lib-http: test-http-server-errors: Fixed logically dead code.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21390
diff changeset
265
0a4ca3f1f285 lib-http: test-http-server-errors: Fixed logically dead code.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21390
diff changeset
266 i_assert(i_stream_is_eof(ctx->payload_input));
20372
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
267
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
268 resp = http_server_response_create(req, 200, "OK");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
269 http_server_response_submit(resp);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
270 ctx->serviced = TRUE;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
271
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
272 i_stream_unref(&ctx->payload_input);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
273 http_server_request_unref(&req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
274 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
275
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
276 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
277 test_server_hanging_request_payload_request(
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
278 struct http_server_request *req)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
279 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
280 const struct http_request *hreq =
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
281 http_server_request_get(req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
282 struct _hanging_request_payload *ctx;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
283
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
284 if (debug) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
285 i_debug("REQUEST: %s %s HTTP/%u.%u",
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
286 hreq->method, hreq->target_raw,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
287 hreq->version_major, hreq->version_minor);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
288 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
289
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
290 ctx = i_new(struct _hanging_request_payload, 1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
291 ctx->req = req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
292
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
293 http_server_request_set_destroy_callback(req,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
294 test_server_hanging_request_payload_destroyed, ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
295
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
296 ctx->payload_input =
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
297 http_server_request_get_payload_input(req, FALSE);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
298
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
299 http_server_request_ref(req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
300 ctx->io = io_add_istream(ctx->payload_input,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
301 test_server_hanging_request_payload_input, ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
302 test_server_hanging_request_payload_input(ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
303 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
304
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
305 static void test_server_hanging_request_payload
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
306 (const struct http_server_settings *server_set)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
307 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
308 test_server_request = test_server_hanging_request_payload_request;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
309 test_server_run(server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
310 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
311
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
312 /* test */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
313
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
314 static void test_hanging_request_payload(void)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
315 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
316 struct http_server_settings http_server_set;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
317
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
318 test_server_defaults(&http_server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
319 http_server_set.max_client_idle_time_msecs = 1000;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
320
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
321 test_begin("hanging request payload");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
322 test_run_client_server(&http_server_set,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
323 test_server_hanging_request_payload,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
324 test_client_hanging_request_payload, 1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
325 test_end();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
326 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
327
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
328 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
329 * Hanging response payload
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
330 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
331
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
332 /* client */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
333
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
334 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
335 test_hanging_response_payload_connected(struct client_connection *conn)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
336 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
337 (void)o_stream_send_str(conn->conn.output,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
338 "GET / HTTP/1.1\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
339 "Host: example.com\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
340 "Content-Length: 18\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
341 "\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
342 "Complete payload\r\n");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
343 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
344
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
345 static void test_client_hanging_response_payload(unsigned int index)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
346 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
347 test_client_connected = test_hanging_response_payload_connected;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
348 test_client_run(index);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
349 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
350
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
351 /* server */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
352
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
353 struct _hanging_response_payload {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
354 struct http_server_request *req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
355 struct istream *payload_input;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
356 struct io *io;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
357 unsigned int serviced:1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
358 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
359
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
360 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
361 test_server_hanging_response_payload_destroyed(void *context)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
362 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
363 struct _hanging_response_payload *ctx =
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
364 (struct _hanging_response_payload *)context;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
365 test_assert(!ctx->serviced);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
366 if (ctx->io != NULL)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
367 io_remove(&ctx->io);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
368 i_free(ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
369 io_loop_stop(ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
370 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
371
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
372 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
373 test_server_hanging_response_payload_request(
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
374 struct http_server_request *req)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
375 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
376 const struct http_request *hreq =
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
377 http_server_request_get(req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
378 struct http_server_response *resp;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
379 struct _hanging_response_payload *ctx;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
380 string_t *payload;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
381 unsigned int i;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
382
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
383 if (debug) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
384 i_debug("REQUEST: %s %s HTTP/%u.%u",
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
385 hreq->method, hreq->target_raw,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
386 hreq->version_major, hreq->version_minor);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
387 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
388
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
389 ctx = i_new(struct _hanging_response_payload, 1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
390 ctx->req = req;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
391
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
392 http_server_request_set_destroy_callback(req,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
393 test_server_hanging_response_payload_destroyed, ctx);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
394
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
395 resp = http_server_response_create(req, 200, "OK");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
396 T_BEGIN {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
397 payload = t_str_new(204800);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
398 for (i = 0; i < 3200; i++) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
399 str_append(payload,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
400 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
401 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
402 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
403
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
404 http_server_response_set_payload_data
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
405 (resp, str_data(payload), str_len(payload));
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
406 } T_END;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
407 http_server_response_submit(resp);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
408 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
409
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
410 static void test_server_hanging_response_payload
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
411 (const struct http_server_settings *server_set)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
412 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
413 test_server_request = test_server_hanging_response_payload_request;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
414 test_server_run(server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
415 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
416
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
417 /* test */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
418
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
419 static void test_hanging_response_payload(void)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
420 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
421 struct http_server_settings http_server_set;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
422
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
423 test_server_defaults(&http_server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
424 http_server_set.socket_send_buffer_size = 4096;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
425 http_server_set.max_client_idle_time_msecs = 1000;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
426
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
427 test_begin("hanging response payload");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
428 test_run_client_server(&http_server_set,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
429 test_server_hanging_response_payload,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
430 test_client_hanging_response_payload, 1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
431 test_end();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
432 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
433
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
434 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
435 * All tests
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
436 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
437
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
438 static void (*test_functions[])(void) = {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
439 test_slow_request,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
440 test_hanging_request_payload,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
441 test_hanging_response_payload,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
442 NULL
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
443 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
444
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
445 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
446 * Test client
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
447 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
448
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
449 /* client connection */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
450
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
451 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
452 client_connection_input(struct connection *_conn)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
453 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
454 struct client_connection *conn = (struct client_connection *)_conn;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
455
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
456 if (test_client_input != NULL)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
457 test_client_input(conn);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
458 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
459
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
460 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
461 client_connection_connected(struct connection *_conn, bool success)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
462 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
463 struct client_connection *conn = (struct client_connection *)_conn;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
464
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
465 if (success && test_client_connected != NULL)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
466 test_client_connected(conn);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
467 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
468
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
469 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
470 client_connection_init(const struct ip_addr *ip, in_port_t port)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
471 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
472 struct client_connection *conn;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
473 pool_t pool;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
474
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
475 pool = pool_alloconly_create("client connection", 256);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
476 conn = p_new(pool, struct client_connection, 1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
477 conn->pool = pool;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
478
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
479 connection_init_client_ip(client_conn_list,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
480 &conn->conn, ip, port);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
481 (void)connection_client_connect(&conn->conn);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
482 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
483
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
484 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
485 server_connection_deinit(struct client_connection **_conn)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
486 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
487 struct client_connection *conn = *_conn;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
488
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
489 *_conn = NULL;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
490
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
491 connection_deinit(&conn->conn);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
492 pool_unref(&conn->pool);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
493 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
494
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
495 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
496 client_connection_destroy(struct connection *_conn)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
497 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
498 struct client_connection *conn =
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
499 (struct client_connection *)_conn;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
500
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
501 server_connection_deinit(&conn);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
502 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
503
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
504 /* */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
505
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
506 static struct connection_settings client_connection_set = {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
507 .input_max_size = (size_t)-1,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
508 .output_max_size = (size_t)-1,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
509 .client = TRUE
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
510 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
511
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
512 static const struct connection_vfuncs client_connection_vfuncs = {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
513 .destroy = client_connection_destroy,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
514 .client_connected = client_connection_connected,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
515 .input = client_connection_input
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
516 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
517
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
518 static void test_client_run(unsigned int index)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
519 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
520 client_index = index;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
521
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
522 if (debug)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
523 i_debug("client connecting to %u", bind_port);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
524
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
525 client_conn_list = connection_list_init
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
526 (&client_connection_set, &client_connection_vfuncs);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
527
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
528 client_connection_init(&bind_ip, bind_port);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
529
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
530 io_loop_run(ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
531
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
532 /* close server socket */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
533 io_remove(&io_listen);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
534
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
535 connection_list_deinit(&client_conn_list);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
536 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
537
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
538 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
539 * Test server
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
540 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
541
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
542 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
543 test_server_defaults(struct http_server_settings *http_set)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
544 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
545 /* server settings */
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 20372
diff changeset
546 i_zero(http_set);
20372
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
547 http_set->max_client_idle_time_msecs = 5*1000;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
548 http_set->max_pipelined_requests = 1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
549 http_set->debug = debug;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
550 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
551
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
552 /* client connection */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
553
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
554 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
555 server_handle_request(void *context ATTR_UNUSED,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
556 struct http_server_request *req)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
557 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
558 test_server_request(req);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
559 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
560
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
561 struct http_server_callbacks http_server_callbacks = {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
562 .handle_request = server_handle_request
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
563 };
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
564
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
565 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
566 server_connection_accept(void *context ATTR_UNUSED)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
567 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
568 int fd;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
569
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
570 /* accept new client */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
571 fd = net_accept(fd_listen, NULL, NULL);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
572 if (fd == -1)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
573 return;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
574 if (fd == -2) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
575 i_fatal("test server: accept() failed: %m");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
576 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
577
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
578 (void)http_server_connection_create(http_server, fd, fd, FALSE,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
579 &http_server_callbacks, NULL);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
580 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
581
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
582 /* */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
583
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
584 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
585 test_server_timeout(void *context ATTR_UNUSED)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
586 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
587 i_fatal("Server timed out");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
588 io_loop_stop(ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
589 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
590
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
591 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
592 test_server_run(const struct http_server_settings *http_set)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
593 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
594 struct timeout *to;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
595
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
596 to = timeout_add(SERVER_MAX_TIMEOUT_MSECS,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
597 test_server_timeout, NULL);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
598
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
599 /* open server socket */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
600 io_listen = io_add(fd_listen,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
601 IO_READ, server_connection_accept, (void *)NULL);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
602
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
603 http_server = http_server_init(http_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
604
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
605 io_loop_run(ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
606
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
607 /* close server socket */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
608 io_remove(&io_listen);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
609 timeout_remove(&to);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
610
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
611 http_server_deinit(&http_server);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
612 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
613
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
614 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
615 * Tests
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
616 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
617
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
618 static int test_open_server_fd(void)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
619 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
620 int fd = net_listen(&bind_ip, &bind_port, 128);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
621 if (debug)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
622 i_debug("server listening on %u", bind_port);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
623 if (fd == -1) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
624 i_fatal("listen(%s:%u) failed: %m",
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
625 net_ip2addr(&bind_ip), bind_port);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
626 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
627 return fd;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
628 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
629
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
630 static void test_clients_kill_all(void)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
631 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
632 unsigned int i;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
633
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
634 if (client_pids_count > 0) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
635 for (i = 0; i < client_pids_count; i++) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
636 if (client_pids[i] != (pid_t)-1) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
637 (void)kill(client_pids[i], SIGKILL);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
638 (void)waitpid(client_pids[i], NULL, 0);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
639 client_pids[i] = -1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
640 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
641 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
642 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
643 client_pids_count = 0;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
644 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
645
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
646 static void test_run_client_server(
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
647 const struct http_server_settings *server_set,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
648 test_server_init_t server_test,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
649 test_client_init_t client_test,
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
650 unsigned int client_tests_count)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
651 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
652 unsigned int i;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
653
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
654 client_pids = NULL;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
655 client_pids_count = 0;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
656
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
657 fd_listen = test_open_server_fd();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
658
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
659 if (client_tests_count > 0) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
660 client_pids = i_new(pid_t, client_tests_count);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
661 for (i = 0; i < client_tests_count; i++)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
662 client_pids[i] = (pid_t)-1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
663 client_pids_count = client_tests_count;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
664
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
665 for (i = 0; i < client_tests_count; i++) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
666 if ((client_pids[i] = fork()) == (pid_t)-1)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
667 i_fatal("fork() failed: %m");
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
668 if (client_pids[i] == 0) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
669 client_pids[i] = (pid_t)-1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
670 client_pids_count = 0;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
671 hostpid_init();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
672 if (debug)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
673 i_debug("client[%d]: PID=%s", i+1, my_pid);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
674 /* child: client */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
675 usleep(100000); /* wait a little for server setup */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
676 i_close_fd(&fd_listen);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
677 ioloop = io_loop_create();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
678 client_test(i);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
679 io_loop_destroy(&ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
680 i_free(client_pids);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
681 /* wait for it to be killed; this way, valgrind will not
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
682 object to this process going away inelegantly. */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
683 sleep(60);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
684 exit(1);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
685 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
686 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
687 if (debug)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
688 i_debug("server: PID=%s", my_pid);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
689 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
690
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
691 /* parent: server */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
692
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
693 ioloop = io_loop_create();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
694 server_test(server_set);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
695 io_loop_destroy(&ioloop);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
696
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
697 i_close_fd(&fd_listen);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
698
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
699 test_clients_kill_all();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
700 i_free(client_pids);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
701 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
702
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
703 /*
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
704 * Main
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
705 */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
706
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
707 volatile sig_atomic_t terminating = 0;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
708
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
709 static void
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
710 test_signal_handler(int signo)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
711 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
712 if (terminating != 0)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
713 raise(signo);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
714 terminating = 1;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
715
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
716 /* make sure we don't leave any pesky children alive */
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
717 test_clients_kill_all();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
718
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
719 (void)signal(signo, SIG_DFL);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
720 raise(signo);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
721 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
722
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
723 static void test_atexit(void)
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
724 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
725 test_clients_kill_all();
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
726 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
727
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
728 int main(int argc, char *argv[])
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
729 {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
730 int c;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
731
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
732 atexit(test_atexit);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
733 (void)signal(SIGCHLD, SIG_IGN);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
734 (void)signal(SIGTERM, test_signal_handler);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
735 (void)signal(SIGQUIT, test_signal_handler);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
736 (void)signal(SIGINT, test_signal_handler);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
737 (void)signal(SIGSEGV, test_signal_handler);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
738 (void)signal(SIGABRT, test_signal_handler);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
739
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
740 while ((c = getopt(argc, argv, "D")) > 0) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
741 switch (c) {
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
742 case 'D':
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
743 debug = TRUE;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
744 break;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
745 default:
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
746 i_fatal("Usage: %s [-D]", argv[0]);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
747 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
748 }
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
749
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
750 /* listen on localhost */
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 20372
diff changeset
751 i_zero(&bind_ip);
20372
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
752 bind_ip.family = AF_INET;
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
753 bind_ip.u.ip4.s_addr = htonl(INADDR_LOOPBACK);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
754
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
755 test_run(test_functions);
0dcb9bb9862a lib-http: server: Created test program that tests error conditions.
Stephan Bosch <stephan@dovecot.fi>
parents:
diff changeset
756 }