diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-02-02 06:29:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-02-02 06:29:47 +0000 |
commit | 6585ad92514d42c1238a463e4d0c5a73be19674a (patch) | |
tree | 62583f0298239d06ab00dae96b4acdf318271257 | |
parent | 4866ea1fef107ddca0f5aa3dcb187c6fd7f4afe1 (diff) | |
download | libmicrohttpd-6585ad92514d42c1238a463e4d0c5a73be19674a.tar.gz libmicrohttpd-6585ad92514d42c1238a463e4d0c5a73be19674a.zip |
cleanup
-rw-r--r-- | src/testcurl/https/Makefile.am | 10 | ||||
-rw-r--r-- | src/testcurl/https/bug-test.c | 69 | ||||
-rw-r--r-- | src/testcurl/https/tls_authentication_test.c | 6 | ||||
-rw-r--r-- | src/testcurl/https/tls_daemon_options_test.c | 2 | ||||
-rw-r--r-- | src/testcurl/https/tls_multi_thread_mode_test.c | 481 | ||||
-rw-r--r-- | src/testcurl/https/tls_thread_mode_test.c | 28 |
6 files changed, 537 insertions, 59 deletions
diff --git a/src/testcurl/https/Makefile.am b/src/testcurl/https/Makefile.am index 7ae29ec1..925a3a86 100644 --- a/src/testcurl/https/Makefile.am +++ b/src/testcurl/https/Makefile.am | |||
@@ -18,7 +18,8 @@ check_PROGRAMS = \ | |||
18 | tls_authentication_test \ | 18 | tls_authentication_test \ |
19 | mhds_multi_daemon_test \ | 19 | mhds_multi_daemon_test \ |
20 | mhds_session_info_test \ | 20 | mhds_session_info_test \ |
21 | tls_thread_mode_test | 21 | tls_thread_mode_test \ |
22 | tls_multi_thread_mode_test | ||
22 | 23 | ||
23 | if MHD_DEBUG_TLS | 24 | if MHD_DEBUG_TLS |
24 | check_PROGRAMS += \ | 25 | check_PROGRAMS += \ |
@@ -65,6 +66,13 @@ tls_thread_mode_test_LDADD = \ | |||
65 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | 66 | $(top_builddir)/src/daemon/libmicrohttpd.la \ |
66 | @LIBCURL@ | 67 | @LIBCURL@ |
67 | 68 | ||
69 | tls_multi_thread_mode_test_SOURCES = \ | ||
70 | tls_multi_thread_mode_test.c | ||
71 | tls_multi_thread_mode_test_LDADD = \ | ||
72 | $(top_builddir)/src/testcurl/libcurl_version_check.a \ | ||
73 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | ||
74 | @LIBCURL@ | ||
75 | |||
68 | tls_authentication_test_SOURCES = \ | 76 | tls_authentication_test_SOURCES = \ |
69 | tls_authentication_test.c | 77 | tls_authentication_test.c |
70 | tls_authentication_test_LDADD = \ | 78 | tls_authentication_test_LDADD = \ |
diff --git a/src/testcurl/https/bug-test.c b/src/testcurl/https/bug-test.c index 34680b5f..8c28bea7 100644 --- a/src/testcurl/https/bug-test.c +++ b/src/testcurl/https/bug-test.c | |||
@@ -238,7 +238,7 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version) | |||
238 | return 0; | 238 | return 0; |
239 | } | 239 | } |
240 | 240 | ||
241 | int | 241 | static int |
242 | test_cipher_option (FILE * test_fd, char *cipher_suite, int proto_version) | 242 | test_cipher_option (FILE * test_fd, char *cipher_suite, int proto_version) |
243 | { | 243 | { |
244 | 244 | ||
@@ -264,35 +264,8 @@ test_cipher_option (FILE * test_fd, char *cipher_suite, int proto_version) | |||
264 | return ret; | 264 | return ret; |
265 | } | 265 | } |
266 | 266 | ||
267 | int | ||
268 | test_mac_option (FILE * test_fd, char *cipher_suite, int proto_version) | ||
269 | { | ||
270 | |||
271 | int ret; | ||
272 | int mac[] = { MHD_GNUTLS_MAC_SHA1, 0 }; | ||
273 | struct MHD_Daemon *d; | ||
274 | |||
275 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | ||
276 | MHD_USE_DEBUG, 42433, | ||
277 | NULL, NULL, &http_ahc, NULL, | ||
278 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | ||
279 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | ||
280 | MHD_OPTION_MAC_ALGO, mac, MHD_OPTION_END); | ||
281 | |||
282 | if (d == NULL) | ||
283 | { | ||
284 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
285 | return -1; | ||
286 | } | ||
287 | |||
288 | ret = test_daemon_get (test_fd, cipher_suite, proto_version); | ||
289 | |||
290 | MHD_stop_daemon (d); | ||
291 | return ret; | ||
292 | } | ||
293 | |||
294 | /* setup a temporary transfer test file */ | 267 | /* setup a temporary transfer test file */ |
295 | FILE * | 268 | static FILE * |
296 | setupTestFile () | 269 | setupTestFile () |
297 | { | 270 | { |
298 | FILE *test_fd; | 271 | FILE *test_fd; |
@@ -320,6 +293,32 @@ setupTestFile () | |||
320 | return test_fd; | 293 | return test_fd; |
321 | } | 294 | } |
322 | 295 | ||
296 | /* perform a HTTP GET request via SSL/TLS */ | ||
297 | int | ||
298 | test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version) | ||
299 | { | ||
300 | int ret; | ||
301 | struct MHD_Daemon *d; | ||
302 | |||
303 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | ||
304 | MHD_USE_DEBUG, 42433, | ||
305 | NULL, NULL, &http_ahc, NULL, | ||
306 | MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, | ||
307 | MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, | ||
308 | MHD_OPTION_END); | ||
309 | |||
310 | if (d == NULL) | ||
311 | { | ||
312 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
313 | return -1; | ||
314 | } | ||
315 | |||
316 | ret = test_daemon_get (test_fd, cipher_suite, proto_version); | ||
317 | |||
318 | MHD_stop_daemon (d); | ||
319 | return ret; | ||
320 | } | ||
321 | |||
323 | int | 322 | int |
324 | main (int argc, char *const *argv) | 323 | main (int argc, char *const *argv) |
325 | { | 324 | { |
@@ -345,17 +344,13 @@ main (int argc, char *const *argv) | |||
345 | return -1; | 344 | return -1; |
346 | } | 345 | } |
347 | 346 | ||
348 | // errorCount += | 347 | errorCount += |
349 | // test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1); | 348 | test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1); |
350 | // errorCount += | 349 | errorCount += |
351 | // test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_SSLv3); | 350 | test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_SSLv3); |
352 | // errorCount += | ||
353 | // test_file_certificates (test_fd, "AES256-SHA", CURL_SSLVERSION_SSLv3); | ||
354 | /* TODO resolve cipher setting issue when compiling against GNU TLS */ | 351 | /* TODO resolve cipher setting issue when compiling against GNU TLS */ |
355 | errorCount += | 352 | errorCount += |
356 | test_cipher_option (test_fd, "DES-CBC3-SHA", CURL_SSLVERSION_TLSv1); | 353 | test_cipher_option (test_fd, "DES-CBC3-SHA", CURL_SSLVERSION_TLSv1); |
357 | /* errorCount += | ||
358 | test_kx_option (test_fd, "EDH-RSA-DES-CBC3-SHA", CURL_SSLVERSION_SSLv3); */ | ||
359 | 354 | ||
360 | 355 | ||
361 | curl_global_cleanup (); | 356 | curl_global_cleanup (); |
diff --git a/src/testcurl/https/tls_authentication_test.c b/src/testcurl/https/tls_authentication_test.c index 976044e0..900d20de 100644 --- a/src/testcurl/https/tls_authentication_test.c +++ b/src/testcurl/https/tls_authentication_test.c | |||
@@ -238,7 +238,7 @@ test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version) | |||
238 | } | 238 | } |
239 | 239 | ||
240 | /* perform a HTTP GET request via SSL/TLS */ | 240 | /* perform a HTTP GET request via SSL/TLS */ |
241 | int | 241 | static int |
242 | test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version) | 242 | test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version) |
243 | { | 243 | { |
244 | int ret; | 244 | int ret; |
@@ -264,7 +264,7 @@ test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version) | |||
264 | } | 264 | } |
265 | 265 | ||
266 | /* setup a temporary transfer test file */ | 266 | /* setup a temporary transfer test file */ |
267 | FILE * | 267 | static FILE * |
268 | setupTestFile () | 268 | setupTestFile () |
269 | { | 269 | { |
270 | FILE *test_fd; | 270 | FILE *test_fd; |
@@ -292,7 +292,7 @@ setupTestFile () | |||
292 | return test_fd; | 292 | return test_fd; |
293 | } | 293 | } |
294 | 294 | ||
295 | FILE * | 295 | static FILE * |
296 | setup_ca_cert () | 296 | setup_ca_cert () |
297 | { | 297 | { |
298 | FILE *fd; | 298 | FILE *fd; |
diff --git a/src/testcurl/https/tls_daemon_options_test.c b/src/testcurl/https/tls_daemon_options_test.c index 72214478..a0d8af97 100644 --- a/src/testcurl/https/tls_daemon_options_test.c +++ b/src/testcurl/https/tls_daemon_options_test.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include "gnutls.h" | 32 | #include "gnutls.h" |
33 | #include <curl/curl.h> | 33 | #include <curl/curl.h> |
34 | 34 | ||
35 | #define DEBUG_CURL_VERBOSE 1 | 35 | #define DEBUG_CURL_VERBOSE 0 |
36 | #define PAGE_NOT_FOUND "<html><head><title>File not found</title></head><body>File not found</body></html>" | 36 | #define PAGE_NOT_FOUND "<html><head><title>File not found</title></head><body>File not found</body></html>" |
37 | 37 | ||
38 | #define MHD_E_MEM "Error: memory error\n" | 38 | #define MHD_E_MEM "Error: memory error\n" |
diff --git a/src/testcurl/https/tls_multi_thread_mode_test.c b/src/testcurl/https/tls_multi_thread_mode_test.c new file mode 100644 index 00000000..5b0533fb --- /dev/null +++ b/src/testcurl/https/tls_multi_thread_mode_test.c | |||
@@ -0,0 +1,481 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007 Christian Grothoff | ||
4 | |||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libmicrohttpd is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libmicrohttpd; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file tls_thread_mode_test.c | ||
23 | * @brief Testcase for libmicrohttpd HTTPS GET operations | ||
24 | * @author Sagie Amir | ||
25 | * @author Christian Grothoff | ||
26 | * | ||
27 | * TODO: add test for external select! | ||
28 | */ | ||
29 | |||
30 | #include "platform.h" | ||
31 | #include "microhttpd.h" | ||
32 | |||
33 | #include <sys/stat.h> | ||
34 | #include <limits.h> | ||
35 | #include "gnutls.h" | ||
36 | #include <curl/curl.h> | ||
37 | |||
38 | #define DEBUG_CURL_VERBOSE 0 | ||
39 | #define PAGE_NOT_FOUND "<html><head><title>File not found</title></head><body>File not found</body></html>" | ||
40 | |||
41 | #define MHD_E_MEM "Error: memory error\n" | ||
42 | #define MHD_E_SERVER_INIT "Error: failed to start server\n" | ||
43 | #define MHD_E_TEST_FILE_CREAT "Error: failed to setup test file\n" | ||
44 | #define MHD_E_CERT_FILE_CREAT "Error: failed to setup test certificate\n" | ||
45 | #define MHD_E_KEY_FILE_CREAT "Error: failed to setup test certificate\n" | ||
46 | |||
47 | #include "tls_test_keys.h" | ||
48 | |||
49 | const char *test_file_name = "https_test_file"; | ||
50 | const char test_file_data[] = "Hello World\n"; | ||
51 | |||
52 | int curl_check_version (const char *req_version, ...); | ||
53 | |||
54 | struct CBC | ||
55 | { | ||
56 | char *buf; | ||
57 | size_t pos; | ||
58 | size_t size; | ||
59 | }; | ||
60 | |||
61 | struct https_test_data | ||
62 | { | ||
63 | FILE *test_fd; | ||
64 | char *cipher_suite; | ||
65 | int proto_version; | ||
66 | }; | ||
67 | |||
68 | struct CipherDef | ||
69 | { | ||
70 | int options[2]; | ||
71 | char *curlname; | ||
72 | }; | ||
73 | |||
74 | static size_t | ||
75 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | ||
76 | { | ||
77 | struct CBC *cbc = ctx; | ||
78 | |||
79 | if (cbc->pos + size * nmemb > cbc->size) | ||
80 | return 0; /* overflow */ | ||
81 | memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | ||
82 | cbc->pos += size * nmemb; | ||
83 | return size * nmemb; | ||
84 | } | ||
85 | |||
86 | static int | ||
87 | file_reader (void *cls, size_t pos, char *buf, int max) | ||
88 | { | ||
89 | FILE *file = cls; | ||
90 | fseek (file, pos, SEEK_SET); | ||
91 | return fread (buf, 1, max, file); | ||
92 | } | ||
93 | |||
94 | /* HTTP access handler call back */ | ||
95 | static int | ||
96 | http_ahc (void *cls, struct MHD_Connection *connection, | ||
97 | const char *url, const char *method, const char *upload_data, | ||
98 | const char *version, unsigned int *upload_data_size, void **ptr) | ||
99 | { | ||
100 | static int aptr; | ||
101 | struct MHD_Response *response; | ||
102 | int ret; | ||
103 | FILE *file; | ||
104 | struct stat buf; | ||
105 | |||
106 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) | ||
107 | return MHD_NO; /* unexpected method */ | ||
108 | if (&aptr != *ptr) | ||
109 | { | ||
110 | /* do never respond on first call */ | ||
111 | *ptr = &aptr; | ||
112 | return MHD_YES; | ||
113 | } | ||
114 | *ptr = NULL; /* reset when done */ | ||
115 | |||
116 | file = fopen (url, "r"); | ||
117 | if (file == NULL) | ||
118 | { | ||
119 | response = MHD_create_response_from_data (strlen (PAGE_NOT_FOUND), | ||
120 | (void *) PAGE_NOT_FOUND, | ||
121 | MHD_NO, MHD_NO); | ||
122 | ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response); | ||
123 | MHD_destroy_response (response); | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | stat (url, &buf); | ||
128 | response = MHD_create_response_from_callback (buf.st_size, 32 * 1024, /* 32k PAGE_NOT_FOUND size */ | ||
129 | &file_reader, file, | ||
130 | (MHD_ContentReaderFreeCallback) | ||
131 | & fclose); | ||
132 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | ||
133 | MHD_destroy_response (response); | ||
134 | } | ||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | |||
139 | |||
140 | /** | ||
141 | * test HTTPS transfer | ||
142 | * @param test_fd: file to attempt transfering | ||
143 | */ | ||
144 | static int | ||
145 | test_https_transfer (FILE * test_fd, char *cipher_suite, int proto_version) | ||
146 | { | ||
147 | CURL *c; | ||
148 | CURLcode errornum; | ||
149 | struct CBC cbc; | ||
150 | char *doc_path; | ||
151 | size_t doc_path_len; | ||
152 | char url[255]; | ||
153 | struct stat statb; | ||
154 | |||
155 | stat (test_file_name, &statb); | ||
156 | |||
157 | int len = statb.st_size; | ||
158 | |||
159 | /* used to memcmp local copy & deamon supplied copy */ | ||
160 | unsigned char *mem_test_file_local; | ||
161 | |||
162 | /* setup test file path, url */ | ||
163 | doc_path_len = PATH_MAX > 4096 ? 4096 : PATH_MAX; | ||
164 | if (NULL == (doc_path = malloc (doc_path_len))) | ||
165 | { | ||
166 | fclose (test_fd); | ||
167 | fprintf (stderr, MHD_E_MEM); | ||
168 | return -1; | ||
169 | } | ||
170 | if (getcwd (doc_path, doc_path_len) == NULL) | ||
171 | { | ||
172 | fclose (test_fd); | ||
173 | free (doc_path); | ||
174 | fprintf (stderr, "Error: failed to get working directory. %s\n", | ||
175 | strerror (errno)); | ||
176 | return -1; | ||
177 | } | ||
178 | |||
179 | if (NULL == (mem_test_file_local = malloc (len))) | ||
180 | { | ||
181 | fclose (test_fd); | ||
182 | free (doc_path); | ||
183 | fprintf (stderr, MHD_E_MEM); | ||
184 | return -1; | ||
185 | } | ||
186 | |||
187 | fseek (test_fd, 0, SEEK_SET); | ||
188 | if (fread (mem_test_file_local, sizeof (char), len, test_fd) != len) | ||
189 | { | ||
190 | fclose (test_fd); | ||
191 | free (doc_path); | ||
192 | fprintf (stderr, "Error: failed to read test file. %s\n", | ||
193 | strerror (errno)); | ||
194 | return -1; | ||
195 | } | ||
196 | |||
197 | if (NULL == (cbc.buf = malloc (len))) | ||
198 | { | ||
199 | fclose (test_fd); | ||
200 | free (doc_path); | ||
201 | free (mem_test_file_local); | ||
202 | fprintf (stderr, MHD_E_MEM); | ||
203 | return -1; | ||
204 | } | ||
205 | cbc.size = len; | ||
206 | cbc.pos = 0; | ||
207 | |||
208 | /* construct url - this might use doc_path */ | ||
209 | sprintf (url, "%s%s/%s", "https://localhost:42433", | ||
210 | doc_path, test_file_name); | ||
211 | |||
212 | c = curl_easy_init (); | ||
213 | #if DEBUG_CURL_VERBOSE | ||
214 | curl_easy_setopt (c, CURLOPT_VERBOSE, 1); | ||
215 | #endif | ||
216 | curl_easy_setopt (c, CURLOPT_URL, url); | ||
217 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
218 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 15L); | ||
219 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
220 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
221 | curl_easy_setopt (c, CURLOPT_FILE, &cbc); | ||
222 | |||
223 | /* TLS options */ | ||
224 | curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version); | ||
225 | curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, cipher_suite); | ||
226 | |||
227 | /* currently skip any peer authentication */ | ||
228 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0); | ||
229 | curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0); | ||
230 | |||
231 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
232 | |||
233 | /* NOTE: use of CONNECTTIMEOUT without also | ||
234 | setting NOSIGNAL results in really weird | ||
235 | crashes on my system! */ | ||
236 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
237 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
238 | { | ||
239 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", | ||
240 | curl_easy_strerror (errornum)); | ||
241 | curl_easy_cleanup (c); | ||
242 | free (cbc.buf); | ||
243 | free (mem_test_file_local); | ||
244 | free (doc_path); | ||
245 | return errornum; | ||
246 | } | ||
247 | |||
248 | curl_easy_cleanup (c); | ||
249 | |||
250 | if (memcmp (cbc.buf, mem_test_file_local, len) != 0) | ||
251 | { | ||
252 | fprintf (stderr, "Error: local file & received file differ.\n"); | ||
253 | free (cbc.buf); | ||
254 | free (mem_test_file_local); | ||
255 | free (doc_path); | ||
256 | return -1; | ||
257 | } | ||
258 | |||
259 | free (mem_test_file_local); | ||
260 | free (cbc.buf); | ||
261 | free (doc_path); | ||
262 | return 0; | ||
263 | } | ||
264 | |||
265 | /** | ||
266 | * used when spawning multiple threads executing curl server requests | ||
267 | * | ||
268 | */ | ||
269 | static void * | ||
270 | https_transfer_thread_adapter (void *args) | ||
271 | { | ||
272 | static int nonnull; | ||
273 | struct https_test_data *cargs = args; | ||
274 | int ret; | ||
275 | |||
276 | /* time spread incomming requests */ | ||
277 | usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX)); | ||
278 | ret = test_https_transfer (cargs->test_fd, | ||
279 | cargs->cipher_suite, cargs->proto_version); | ||
280 | if (ret == 0) | ||
281 | return NULL; | ||
282 | return &nonnull; | ||
283 | } | ||
284 | |||
285 | static FILE * | ||
286 | setupTestFile () | ||
287 | { | ||
288 | FILE *test_fd; | ||
289 | |||
290 | if (NULL == (test_fd = fopen (test_file_name, "w+"))) | ||
291 | { | ||
292 | fprintf (stderr, "Error: failed to open `%s': %s\n", | ||
293 | test_file_name, strerror (errno)); | ||
294 | return NULL; | ||
295 | } | ||
296 | if (fwrite (test_file_data, sizeof (char), strlen (test_file_data), test_fd) | ||
297 | != strlen (test_file_data)) | ||
298 | { | ||
299 | fprintf (stderr, "Error: failed to write `%s. %s'\n", | ||
300 | test_file_name, strerror (errno)); | ||
301 | return NULL; | ||
302 | } | ||
303 | if (fflush (test_fd)) | ||
304 | { | ||
305 | fprintf (stderr, "Error: failed to flush test file stream. %s\n", | ||
306 | strerror (errno)); | ||
307 | return NULL; | ||
308 | } | ||
309 | |||
310 | return test_fd; | ||
311 | } | ||
312 | |||
313 | static int | ||
314 | setup (struct MHD_Daemon **d, int daemon_flags, va_list arg_list) | ||
315 | { | ||
316 | *d = MHD_start_daemon_va (daemon_flags, 42433, | ||
317 | NULL, NULL, &http_ahc, NULL, arg_list); | ||
318 | |||
319 | if (*d == NULL) | ||
320 | { | ||
321 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
322 | return -1; | ||
323 | } | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static void | ||
329 | teardown (struct MHD_Daemon *d) | ||
330 | { | ||
331 | MHD_stop_daemon (d); | ||
332 | } | ||
333 | |||
334 | /* TODO test_wrap: change sig to (setup_func, test, va_list test_arg) & move to test_util.c */ | ||
335 | static int | ||
336 | test_wrap (char *test_name, int | ||
337 | (*test_function) (FILE * test_fd, char *cipher_suite, | ||
338 | int proto_version), FILE * test_fd, | ||
339 | int daemon_flags, char *cipher_suite, int proto_version, ...) | ||
340 | { | ||
341 | int ret; | ||
342 | va_list arg_list; | ||
343 | struct MHD_Daemon *d; | ||
344 | |||
345 | va_start (arg_list, proto_version); | ||
346 | if (setup (&d, daemon_flags, arg_list) != 0) | ||
347 | { | ||
348 | va_end (arg_list); | ||
349 | return -1; | ||
350 | } | ||
351 | |||
352 | fprintf (stdout, "running test: %s ", test_name); | ||
353 | ret = test_function (test_fd, cipher_suite, proto_version); | ||
354 | |||
355 | if (ret == 0) | ||
356 | { | ||
357 | fprintf (stdout, "[pass]\n"); | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | fprintf (stdout, "[fail]\n"); | ||
362 | } | ||
363 | |||
364 | teardown (d); | ||
365 | va_end (arg_list); | ||
366 | return ret; | ||
367 | } | ||
368 | |||
369 | /** | ||
370 | * Test non-parallel requests. | ||
371 | * | ||
372 | * @return: 0 upon all client requests returning '0', -1 otherwise. | ||
373 | * | ||
374 | * TODO : make client_count a parameter - numver of curl client threads to spawn | ||
375 | */ | ||
376 | static int | ||
377 | test_single_client (FILE * test_fd, char *cipher_suite, | ||
378 | int curl_proto_version) | ||
379 | { | ||
380 | void *client_thread_ret; | ||
381 | struct https_test_data client_args = | ||
382 | { test_fd, cipher_suite, curl_proto_version }; | ||
383 | |||
384 | client_thread_ret = https_transfer_thread_adapter (&client_args); | ||
385 | if (client_thread_ret != NULL) | ||
386 | return -1; | ||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | |||
391 | /** | ||
392 | * Test parallel request handling. | ||
393 | * | ||
394 | * @return: 0 upon all client requests returning '0', -1 otherwise. | ||
395 | * | ||
396 | * TODO : make client_count a parameter - numver of curl client threads to spawn | ||
397 | */ | ||
398 | static int | ||
399 | test_parallel_clients (FILE * test_fd, char *cipher_suite, | ||
400 | int curl_proto_version) | ||
401 | { | ||
402 | int i; | ||
403 | int client_count = 3; | ||
404 | void *client_thread_ret; | ||
405 | pthread_t client_arr[client_count]; | ||
406 | struct https_test_data client_args = | ||
407 | { test_fd, cipher_suite, curl_proto_version }; | ||
408 | |||
409 | for (i = 0; i < client_count; ++i) | ||
410 | { | ||
411 | if (pthread_create (&client_arr[i], NULL, | ||
412 | &https_transfer_thread_adapter, | ||
413 | &client_args) != 0) | ||
414 | { | ||
415 | fprintf (stderr, "Error: failed to spawn test client threads.\n"); | ||
416 | |||
417 | return -1; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | /* check all client requests fulfilled correctly */ | ||
422 | for (i = 0; i < client_count; ++i) | ||
423 | { | ||
424 | if ((pthread_join (client_arr[i], &client_thread_ret) != 0) || | ||
425 | (client_thread_ret != NULL)) | ||
426 | return -1; | ||
427 | } | ||
428 | |||
429 | return 0; | ||
430 | } | ||
431 | |||
432 | |||
433 | int | ||
434 | main (int argc, char *const *argv) | ||
435 | { | ||
436 | FILE *test_fd; | ||
437 | unsigned int errorCount = 0; | ||
438 | |||
439 | /* initialize random seed used by curl clients */ | ||
440 | unsigned int iseed = (unsigned int) time (NULL); | ||
441 | srand (iseed); | ||
442 | |||
443 | if (curl_check_version (MHD_REQ_CURL_VERSION)) | ||
444 | return -1; | ||
445 | |||
446 | if ((test_fd = setupTestFile ()) == NULL) | ||
447 | { | ||
448 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); | ||
449 | return -1; | ||
450 | } | ||
451 | |||
452 | if (0 != curl_global_init (CURL_GLOBAL_ALL)) | ||
453 | { | ||
454 | fprintf (stderr, "Error: %s\n", strerror (errno)); | ||
455 | return -1; | ||
456 | } | ||
457 | |||
458 | errorCount += | ||
459 | test_wrap ("multi threaded daemon, single client", &test_single_client, | ||
460 | test_fd, MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION, "AES256-SHA", | ||
461 | CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | ||
462 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | ||
463 | MHD_OPTION_END); | ||
464 | |||
465 | errorCount += | ||
466 | test_wrap ("multi threaded daemon, parallel client", | ||
467 | &test_parallel_clients, test_fd, MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION, | ||
468 | "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | ||
469 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | ||
470 | srv_self_signed_cert_pem, MHD_OPTION_END); | ||
471 | |||
472 | if (errorCount != 0) | ||
473 | fprintf (stderr, "Failed test: %s.\n", argv[0]); | ||
474 | |||
475 | curl_global_cleanup (); | ||
476 | fclose (test_fd); | ||
477 | |||
478 | remove (test_file_name); | ||
479 | |||
480 | return errorCount != 0; | ||
481 | } | ||
diff --git a/src/testcurl/https/tls_thread_mode_test.c b/src/testcurl/https/tls_thread_mode_test.c index a2f0de87..ed263e3f 100644 --- a/src/testcurl/https/tls_thread_mode_test.c +++ b/src/testcurl/https/tls_thread_mode_test.c | |||
@@ -179,6 +179,7 @@ test_https_transfer (FILE * test_fd, char *cipher_suite, int proto_version) | |||
179 | if (NULL == (mem_test_file_local = malloc (len))) | 179 | if (NULL == (mem_test_file_local = malloc (len))) |
180 | { | 180 | { |
181 | fclose (test_fd); | 181 | fclose (test_fd); |
182 | free (doc_path); | ||
182 | fprintf (stderr, MHD_E_MEM); | 183 | fprintf (stderr, MHD_E_MEM); |
183 | return -1; | 184 | return -1; |
184 | } | 185 | } |
@@ -187,14 +188,17 @@ test_https_transfer (FILE * test_fd, char *cipher_suite, int proto_version) | |||
187 | if (fread (mem_test_file_local, sizeof (char), len, test_fd) != len) | 188 | if (fread (mem_test_file_local, sizeof (char), len, test_fd) != len) |
188 | { | 189 | { |
189 | fclose (test_fd); | 190 | fclose (test_fd); |
191 | free (doc_path); | ||
190 | fprintf (stderr, "Error: failed to read test file. %s\n", | 192 | fprintf (stderr, "Error: failed to read test file. %s\n", |
191 | strerror (errno)); | 193 | strerror (errno)); |
192 | return -1; | 194 | return -1; |
193 | } | 195 | } |
194 | 196 | ||
195 | if (NULL == (cbc.buf = malloc (sizeof (char) * len))) | 197 | if (NULL == (cbc.buf = malloc (len))) |
196 | { | 198 | { |
197 | fclose (test_fd); | 199 | fclose (test_fd); |
200 | free (doc_path); | ||
201 | free (mem_test_file_local); | ||
198 | fprintf (stderr, MHD_E_MEM); | 202 | fprintf (stderr, MHD_E_MEM); |
199 | return -1; | 203 | return -1; |
200 | } | 204 | } |
@@ -235,6 +239,9 @@ test_https_transfer (FILE * test_fd, char *cipher_suite, int proto_version) | |||
235 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", | 239 | fprintf (stderr, "curl_easy_perform failed: `%s'\n", |
236 | curl_easy_strerror (errornum)); | 240 | curl_easy_strerror (errornum)); |
237 | curl_easy_cleanup (c); | 241 | curl_easy_cleanup (c); |
242 | free (cbc.buf); | ||
243 | free (mem_test_file_local); | ||
244 | free (doc_path); | ||
238 | return errornum; | 245 | return errornum; |
239 | } | 246 | } |
240 | 247 | ||
@@ -245,6 +252,7 @@ test_https_transfer (FILE * test_fd, char *cipher_suite, int proto_version) | |||
245 | fprintf (stderr, "Error: local file & received file differ.\n"); | 252 | fprintf (stderr, "Error: local file & received file differ.\n"); |
246 | free (cbc.buf); | 253 | free (cbc.buf); |
247 | free (mem_test_file_local); | 254 | free (mem_test_file_local); |
255 | free (doc_path); | ||
248 | return -1; | 256 | return -1; |
249 | } | 257 | } |
250 | 258 | ||
@@ -401,10 +409,11 @@ test_parallel_clients (FILE * test_fd, char *cipher_suite, | |||
401 | for (i = 0; i < client_count; ++i) | 409 | for (i = 0; i < client_count; ++i) |
402 | { | 410 | { |
403 | if (pthread_create (&client_arr[i], NULL, | 411 | if (pthread_create (&client_arr[i], NULL, |
404 | (void *) &https_transfer_thread_adapter, | 412 | &https_transfer_thread_adapter, |
405 | &client_args) != 0) | 413 | &client_args) != 0) |
406 | { | 414 | { |
407 | fprintf (stderr, "Error: failed to spawn test client threads.\n"); | 415 | fprintf (stderr, "Error: failed to spawn test client threads.\n"); |
416 | |||
408 | return -1; | 417 | return -1; |
409 | } | 418 | } |
410 | } | 419 | } |
@@ -447,27 +456,12 @@ main (int argc, char *const *argv) | |||
447 | } | 456 | } |
448 | 457 | ||
449 | errorCount += | 458 | errorCount += |
450 | test_wrap ("multi threaded daemon, single client", &test_single_client, | ||
451 | test_fd, MHD_USE_SSL | MHD_USE_DEBUG, "AES256-SHA", | ||
452 | CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | ||
453 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | ||
454 | MHD_OPTION_END); | ||
455 | |||
456 | errorCount += | ||
457 | test_wrap ("single threaded daemon, single client", &test_single_client, | 459 | test_wrap ("single threaded daemon, single client", &test_single_client, |
458 | test_fd, | 460 | test_fd, |
459 | MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG, | 461 | MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG, |
460 | "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | 462 | "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, |
461 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | 463 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, |
462 | srv_self_signed_cert_pem, MHD_OPTION_END); | 464 | srv_self_signed_cert_pem, MHD_OPTION_END); |
463 | |||
464 | errorCount += | ||
465 | test_wrap ("multi threaded daemon, parallel client", | ||
466 | &test_parallel_clients, test_fd, MHD_USE_SSL | MHD_USE_DEBUG, | ||
467 | "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY, | ||
468 | srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, | ||
469 | srv_self_signed_cert_pem, MHD_OPTION_END); | ||
470 | |||
471 | errorCount += | 465 | errorCount += |
472 | test_wrap ("single threaded daemon, parallel clients", | 466 | test_wrap ("single threaded daemon, parallel clients", |
473 | &test_parallel_clients, test_fd, | 467 | &test_parallel_clients, test_fd, |