aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-07-25 07:17:26 +0000
committerChristian Grothoff <christian@grothoff.org>2010-07-25 07:17:26 +0000
commit67851b280ee6c5b9fcc4f82402c1dad12887e224 (patch)
treeab370f6b808e782e9846eb489151ea9e57128c5d /src/testcurl
parent58d06b22557a9d06dfeff5975c8241def4f88680 (diff)
downloadlibmicrohttpd-67851b280ee6c5b9fcc4f82402c1dad12887e224.tar.gz
libmicrohttpd-67851b280ee6c5b9fcc4f82402c1dad12887e224.zip
GHM hacking
Diffstat (limited to 'src/testcurl')
-rw-r--r--src/testcurl/https/Makefile.am11
-rw-r--r--src/testcurl/https/mhds_get_test.c8
-rw-r--r--src/testcurl/https/mhds_get_test_select.c243
-rw-r--r--src/testcurl/https/tls_daemon_options_test.c16
-rw-r--r--src/testcurl/https/tls_thread_mode_test.c5
5 files changed, 269 insertions, 14 deletions
diff --git a/src/testcurl/https/Makefile.am b/src/testcurl/https/Makefile.am
index 42791bdc..7c9c99eb 100644
--- a/src/testcurl/https/Makefile.am
+++ b/src/testcurl/https/Makefile.am
@@ -14,6 +14,7 @@ check_PROGRAMS = \
14 tls_authentication_test \ 14 tls_authentication_test \
15 mhds_multi_daemon_test \ 15 mhds_multi_daemon_test \
16 mhds_get_test \ 16 mhds_get_test \
17 mhds_get_test_select \
17 mhds_session_info_test \ 18 mhds_session_info_test \
18 tls_thread_mode_test \ 19 tls_thread_mode_test \
19 tls_multi_thread_mode_test \ 20 tls_multi_thread_mode_test \
@@ -28,6 +29,7 @@ TESTS = \
28 tls_daemon_options_test \ 29 tls_daemon_options_test \
29 mhds_multi_daemon_test \ 30 mhds_multi_daemon_test \
30 mhds_get_test \ 31 mhds_get_test \
32 mhds_get_test_select \
31 mhds_session_info_test \ 33 mhds_session_info_test \
32 tls_thread_mode_test \ 34 tls_thread_mode_test \
33 tls_multi_thread_mode_test \ 35 tls_multi_thread_mode_test \
@@ -116,3 +118,12 @@ mhds_get_test_LDADD = \
116 $(top_builddir)/src/testcurl/libcurl_version_check.a \ 118 $(top_builddir)/src/testcurl/libcurl_version_check.a \
117 $(top_builddir)/src/daemon/libmicrohttpd.la \ 119 $(top_builddir)/src/daemon/libmicrohttpd.la \
118 @LIBCURL@ 120 @LIBCURL@
121
122
123mhds_get_test_select_SOURCES = \
124 mhds_get_test_select.c \
125 tls_test_common.c
126mhds_get_test_select_LDADD = \
127 $(top_builddir)/src/testcurl/libcurl_version_check.a \
128 $(top_builddir)/src/daemon/libmicrohttpd.la \
129 @LIBCURL@
diff --git a/src/testcurl/https/mhds_get_test.c b/src/testcurl/https/mhds_get_test.c
index a32b2cff..0f5f06a1 100644
--- a/src/testcurl/https/mhds_get_test.c
+++ b/src/testcurl/https/mhds_get_test.c
@@ -29,6 +29,7 @@
29#include <limits.h> 29#include <limits.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31#include <curl/curl.h> 31#include <curl/curl.h>
32#include <gcrypt.h>
32#include "tls_test_common.h" 33#include "tls_test_common.h"
33 34
34int curl_check_version (const char *req_version, ...); 35int curl_check_version (const char *req_version, ...);
@@ -89,6 +90,8 @@ test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version)
89 return ret; 90 return ret;
90} 91}
91 92
93GCRY_THREAD_OPTION_PTHREAD_IMPL;
94
92int 95int
93main (int argc, char *const *argv) 96main (int argc, char *const *argv)
94{ 97{
@@ -96,11 +99,14 @@ main (int argc, char *const *argv)
96 unsigned int errorCount = 0; 99 unsigned int errorCount = 0;
97 100
98 /* gnutls_global_set_log_level(11); */ 101 /* gnutls_global_set_log_level(11); */
99
100 if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_OPENSSL_VERSION)) 102 if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_OPENSSL_VERSION))
101 { 103 {
102 return -1; 104 return -1;
103 } 105 }
106 gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
107
108 if (!gcry_check_version (GCRYPT_VERSION))
109 abort ();
104 110
105 if ((test_fd = setup_test_file ()) == NULL) 111 if ((test_fd = setup_test_file ()) == NULL)
106 { 112 {
diff --git a/src/testcurl/https/mhds_get_test_select.c b/src/testcurl/https/mhds_get_test_select.c
new file mode 100644
index 00000000..01a92cd0
--- /dev/null
+++ b/src/testcurl/https/mhds_get_test_select.c
@@ -0,0 +1,243 @@
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 mhds_get_test.c
23 * @brief Testcase for libmicrohttpd HTTPS GET operations
24 * @author Sagie Amir
25 */
26
27#include "platform.h"
28#include "microhttpd.h"
29#include <limits.h>
30#include <sys/stat.h>
31#include <curl/curl.h>
32#include <gcrypt.h>
33#include "tls_test_common.h"
34
35int curl_check_version (const char *req_version, ...);
36extern const char srv_key_pem[];
37extern const char srv_self_signed_cert_pem[];
38extern const char srv_signed_cert_pem[];
39extern const char srv_signed_key_pem[];
40
41static int oneone;
42
43static int
44ahc_echo (void *cls,
45 struct MHD_Connection *connection,
46 const char *url,
47 const char *method,
48 const char *version,
49 const char *upload_data, size_t *upload_data_size,
50 void **unused)
51{
52 static int ptr;
53 const char *me = cls;
54 struct MHD_Response *response;
55 int ret;
56
57 if (0 != strcmp (me, method))
58 return MHD_NO; /* unexpected method */
59 if (&ptr != *unused)
60 {
61 *unused = &ptr;
62 fprintf (stderr, "received %s\n", method);
63 return MHD_YES;
64 }
65 *unused = NULL;
66 response = MHD_create_response_from_data (strlen (url),
67 (void *) url, MHD_NO, MHD_YES);
68 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
69 fprintf (stderr, "sending reply\n");
70 MHD_destroy_response (response);
71 if (ret == MHD_NO)
72 abort ();
73 return ret;
74}
75
76static int
77testExternalGet ()
78{
79 struct MHD_Daemon *d;
80 CURL *c;
81 char buf[2048];
82 struct CBC cbc;
83 CURLM *multi;
84 CURLMcode mret;
85 fd_set rs;
86 fd_set ws;
87 fd_set es;
88 int max;
89 int running;
90 struct CURLMsg *msg;
91 time_t start;
92 struct timeval tv;
93
94 multi = NULL;
95 cbc.buf = buf;
96 cbc.size = 2048;
97 cbc.pos = 0;
98 d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL,
99 1082, NULL, NULL, &ahc_echo, "GET",
100 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
101 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
102 MHD_OPTION_END);
103 if (d == NULL)
104 return 256;
105 c = curl_easy_init ();
106 curl_easy_setopt (c, CURLOPT_URL, "https://localhost:1082/hello_world");
107 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
108 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
109 curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
110 curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
111 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
112 if (oneone)
113 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
114 else
115 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
116 curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
117 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
118 /* NOTE: use of CONNECTTIMEOUT without also
119 setting NOSIGNAL results in really weird
120 crashes on my system! */
121 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
122
123
124 multi = curl_multi_init ();
125 if (multi == NULL)
126 {
127 curl_easy_cleanup (c);
128 MHD_stop_daemon (d);
129 return 512;
130 }
131 mret = curl_multi_add_handle (multi, c);
132 if (mret != CURLM_OK)
133 {
134 curl_multi_cleanup (multi);
135 curl_easy_cleanup (c);
136 MHD_stop_daemon (d);
137 return 1024;
138 }
139 start = time (NULL);
140 while ((time (NULL) - start < 5) && (multi != NULL))
141 {
142 max = 0;
143 FD_ZERO (&rs);
144 FD_ZERO (&ws);
145 FD_ZERO (&es);
146 curl_multi_perform (multi, &running);
147 mret = curl_multi_fdset (multi, &rs, &ws, &es, &max);
148 if (mret != CURLM_OK)
149 {
150 curl_multi_remove_handle (multi, c);
151 curl_multi_cleanup (multi);
152 curl_easy_cleanup (c);
153 MHD_stop_daemon (d);
154 return 2048;
155 }
156 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
157 {
158 curl_multi_remove_handle (multi, c);
159 curl_multi_cleanup (multi);
160 curl_easy_cleanup (c);
161 MHD_stop_daemon (d);
162 return 4096;
163 }
164 tv.tv_sec = 0;
165 tv.tv_usec = 1000;
166 select (max + 1, &rs, &ws, &es, &tv);
167 curl_multi_perform (multi, &running);
168 if (running == 0)
169 {
170 msg = curl_multi_info_read (multi, &running);
171 if (msg == NULL)
172 break;
173 if (msg->msg == CURLMSG_DONE)
174 {
175 if (msg->data.result != CURLE_OK)
176 printf ("%s failed at %s:%d: `%s'\n",
177 "curl_multi_perform",
178 __FILE__,
179 __LINE__, curl_easy_strerror (msg->data.result));
180 curl_multi_remove_handle (multi, c);
181 curl_multi_cleanup (multi);
182 curl_easy_cleanup (c);
183 c = NULL;
184 multi = NULL;
185 }
186 }
187 MHD_run (d);
188 }
189 if (multi != NULL)
190 {
191 curl_multi_remove_handle (multi, c);
192 curl_easy_cleanup (c);
193 curl_multi_cleanup (multi);
194 }
195 MHD_stop_daemon (d);
196 if (cbc.pos != strlen ("/hello_world"))
197 return 8192;
198 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
199 return 16384;
200 return 0;
201}
202
203GCRY_THREAD_OPTION_PTHREAD_IMPL;
204
205int
206main (int argc, char *const *argv)
207{
208 FILE *test_fd;
209 unsigned int errorCount = 0;
210
211 /* gnutls_global_set_log_level(11); */
212 if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_OPENSSL_VERSION))
213 {
214 return -1;
215 }
216 gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
217
218 if (!gcry_check_version (GCRYPT_VERSION))
219 abort ();
220
221 if ((test_fd = setup_test_file ()) == NULL)
222 {
223 fprintf (stderr, MHD_E_TEST_FILE_CREAT);
224 return -1;
225 }
226
227 if (0 != curl_global_init (CURL_GLOBAL_ALL))
228 {
229 fprintf (stderr, "Error: %s\n", strerror (errno));
230 fclose (test_fd);
231 return -1;
232 }
233
234 if (0 != (errorCount = testExternalGet ()))
235 fprintf (stderr, "Fail: %d\n", errorCount);
236
237
238 curl_global_cleanup ();
239 fclose (test_fd);
240 remove (TEST_FILE_NAME);
241
242 return errorCount != 0;
243}
diff --git a/src/testcurl/https/tls_daemon_options_test.c b/src/testcurl/https/tls_daemon_options_test.c
index e7d07964..05ee6aed 100644
--- a/src/testcurl/https/tls_daemon_options_test.c
+++ b/src/testcurl/https/tls_daemon_options_test.c
@@ -104,12 +104,6 @@ main (int argc, char *const *argv)
104 return -1; 104 return -1;
105 } 105 }
106 106
107 int p_ssl3[] = { GNUTLS_SSL3, 0 };
108 int p_tls[] = { GNUTLS_TLS1_2,
109 GNUTLS_TLS1_1,
110 GNUTLS_TLS1_0, 0
111 };
112
113 struct CipherDef ciphers[] = { 107 struct CipherDef ciphers[] = {
114 {{GNUTLS_CIPHER_AES_128_CBC, 0}, "AES128-SHA"}, 108 {{GNUTLS_CIPHER_AES_128_CBC, 0}, "AES128-SHA"},
115 {{GNUTLS_CIPHER_ARCFOUR_128, 0}, "RC4-SHA"}, 109 {{GNUTLS_CIPHER_ARCFOUR_128, 0}, "RC4-SHA"},
@@ -129,8 +123,7 @@ main (int argc, char *const *argv)
129 CURL_SSLVERSION_TLSv1, 123 CURL_SSLVERSION_TLSv1,
130 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 124 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
131 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 125 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
132 MHD_OPTION_PROTOCOL_VERSION, p_tls, 126 MHD_OPTION_CIPHER_ALGORITHM, "NORMAL",
133 MHD_OPTION_CIPHER_ALGORITHM, ciphers[cpos].options,
134 MHD_OPTION_END); 127 MHD_OPTION_END);
135 cpos++; 128 cpos++;
136 } 129 }
@@ -146,8 +139,7 @@ main (int argc, char *const *argv)
146 CURL_SSLVERSION_SSLv3, 139 CURL_SSLVERSION_SSLv3,
147 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 140 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
148 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 141 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
149 MHD_OPTION_PROTOCOL_VERSION, p_ssl3, 142 MHD_OPTION_CIPHER_ALGORITHM, "NORMAL",
150 MHD_OPTION_CIPHER_ALGORITHM, ciphers[cpos].options,
151 MHD_OPTION_END); 143 MHD_OPTION_END);
152 cpos++; 144 cpos++;
153 } 145 }
@@ -164,14 +156,14 @@ main (int argc, char *const *argv)
164 test_fd, daemon_flags, "AES256-SHA", CURL_SSLVERSION_TLSv1, 156 test_fd, daemon_flags, "AES256-SHA", CURL_SSLVERSION_TLSv1,
165 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 157 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
166 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 158 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
167 MHD_OPTION_PROTOCOL_VERSION, p_ssl3, MHD_OPTION_END); 159 MHD_OPTION_CIPHER_ALGORITHM, "SSL3", MHD_OPTION_END);
168#endif 160#endif
169 errorCount += 161 errorCount +=
170 test_wrap ("unmatching version: TLS vs. SSL3", &test_unmatching_ssl_version, 162 test_wrap ("unmatching version: TLS vs. SSL3", &test_unmatching_ssl_version,
171 test_fd, daemon_flags, "AES256-SHA", CURL_SSLVERSION_SSLv3, 163 test_fd, daemon_flags, "AES256-SHA", CURL_SSLVERSION_SSLv3,
172 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, 164 MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
173 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, 165 MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
174 MHD_OPTION_PROTOCOL_VERSION, p_tls, MHD_OPTION_END); 166 MHD_OPTION_CIPHER_ALGORITHM, "SSL3", MHD_OPTION_END);
175 curl_global_cleanup (); 167 curl_global_cleanup ();
176 fclose (test_fd); 168 fclose (test_fd);
177 remove (TEST_FILE_NAME); 169 remove (TEST_FILE_NAME);
diff --git a/src/testcurl/https/tls_thread_mode_test.c b/src/testcurl/https/tls_thread_mode_test.c
index fdf8840e..ecb61bca 100644
--- a/src/testcurl/https/tls_thread_mode_test.c
+++ b/src/testcurl/https/tls_thread_mode_test.c
@@ -32,6 +32,7 @@
32#include <sys/stat.h> 32#include <sys/stat.h>
33#include <limits.h> 33#include <limits.h>
34#include <curl/curl.h> 34#include <curl/curl.h>
35#include <gcrypt.h>
35#include "tls_test_common.h" 36#include "tls_test_common.h"
36 37
37extern const char srv_key_pem[]; 38extern const char srv_key_pem[];
@@ -119,6 +120,8 @@ test_parallel_clients (FILE * test_fd, char *cipher_suite,
119 return 0; 120 return 0;
120} 121}
121 122
123GCRY_THREAD_OPTION_PTHREAD_IMPL;
124
122int 125int
123main (int argc, char *const *argv) 126main (int argc, char *const *argv)
124{ 127{
@@ -128,7 +131,7 @@ main (int argc, char *const *argv)
128 /* initialize random seed used by curl clients */ 131 /* initialize random seed used by curl clients */
129 unsigned int iseed = (unsigned int) time (NULL); 132 unsigned int iseed = (unsigned int) time (NULL);
130 srand (iseed); 133 srand (iseed);
131 134 gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
132 if (curl_check_version (MHD_REQ_CURL_VERSION)) 135 if (curl_check_version (MHD_REQ_CURL_VERSION))
133 return -1; 136 return -1;
134 137