diff options
Diffstat (limited to 'src/testcurl/https/test_https_multi_daemon.c')
-rw-r--r-- | src/testcurl/https/test_https_multi_daemon.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/testcurl/https/test_https_multi_daemon.c b/src/testcurl/https/test_https_multi_daemon.c new file mode 100644 index 00000000..4713f1ea --- /dev/null +++ b/src/testcurl/https/test_https_multi_daemon.c | |||
@@ -0,0 +1,124 @@ | |||
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_multi_daemon_test.c | ||
23 | * @brief Testcase for libmicrohttpd multiple HTTPS daemon scenario | ||
24 | * @author Sagie Amir | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "microhttpd.h" | ||
29 | #include <curl/curl.h> | ||
30 | #include <limits.h> | ||
31 | #include <sys/stat.h> | ||
32 | |||
33 | #include "tls_test_common.h" | ||
34 | |||
35 | extern int curl_check_version (const char *req_version, ...); | ||
36 | extern const char srv_key_pem[]; | ||
37 | extern const char srv_self_signed_cert_pem[]; | ||
38 | |||
39 | /* | ||
40 | * assert initiating two separate daemons and having one shut down | ||
41 | * doesn't affect the other | ||
42 | */ | ||
43 | int | ||
44 | test_concurent_daemon_pair (void * cls, char *cipher_suite, | ||
45 | int proto_version) | ||
46 | { | ||
47 | |||
48 | int ret; | ||
49 | struct MHD_Daemon *d1; | ||
50 | struct MHD_Daemon *d2; | ||
51 | d1 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | ||
52 | MHD_USE_DEBUG, DEAMON_TEST_PORT, | ||
53 | NULL, NULL, &http_ahc, NULL, | ||
54 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | ||
55 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | ||
56 | MHD_OPTION_END); | ||
57 | |||
58 | if (d1 == NULL) | ||
59 | { | ||
60 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
61 | return -1; | ||
62 | } | ||
63 | |||
64 | d2 = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | ||
65 | MHD_USE_DEBUG, DEAMON_TEST_PORT + 1, | ||
66 | NULL, NULL, &http_ahc, NULL, | ||
67 | MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, | ||
68 | MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, | ||
69 | MHD_OPTION_END); | ||
70 | |||
71 | if (d2 == NULL) | ||
72 | { | ||
73 | MHD_stop_daemon (d1); | ||
74 | fprintf (stderr, MHD_E_SERVER_INIT); | ||
75 | return -1; | ||
76 | } | ||
77 | |||
78 | ret = | ||
79 | test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0); | ||
80 | ret += | ||
81 | test_daemon_get (NULL, cipher_suite, proto_version, | ||
82 | DEAMON_TEST_PORT + 1, 0); | ||
83 | |||
84 | MHD_stop_daemon (d2); | ||
85 | ret += | ||
86 | test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0); | ||
87 | MHD_stop_daemon (d1); | ||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | int | ||
92 | main (int argc, char *const *argv) | ||
93 | { | ||
94 | unsigned int errorCount = 0; | ||
95 | FILE *cert; | ||
96 | |||
97 | if (0 != curl_global_init (CURL_GLOBAL_ALL)) | ||
98 | { | ||
99 | fprintf (stderr, "Error (code: %u). l:%d f:%s\n", errorCount, __LINE__, | ||
100 | __FUNCTION__); | ||
101 | return -1; | ||
102 | } | ||
103 | if ((cert = setup_ca_cert ()) == NULL) | ||
104 | { | ||
105 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); | ||
106 | return -1; | ||
107 | } | ||
108 | |||
109 | char *aes256_sha = "AES256-SHA"; | ||
110 | if (curl_uses_nss_ssl() == 0) | ||
111 | { | ||
112 | aes256_sha = "rsa_aes_256_sha"; | ||
113 | } | ||
114 | |||
115 | errorCount += | ||
116 | test_concurent_daemon_pair (NULL, aes256_sha, CURL_SSLVERSION_SSLv3); | ||
117 | |||
118 | print_test_result (errorCount, "concurent_daemon_pair"); | ||
119 | |||
120 | curl_global_cleanup (); | ||
121 | fclose (cert); | ||
122 | remove (ca_cert_file_name); | ||
123 | return errorCount != 0; | ||
124 | } | ||