gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12678 - libmicrohttpd/src/testcurl/https


From: gnunet
Subject: [GNUnet-SVN] r12678 - libmicrohttpd/src/testcurl/https
Date: Thu, 19 Aug 2010 15:55:26 +0200

Author: grothoff
Date: 2010-08-19 15:55:26 +0200 (Thu, 19 Aug 2010)
New Revision: 12678

Modified:
   libmicrohttpd/src/testcurl/https/mhds_get_test.c
   libmicrohttpd/src/testcurl/https/mhds_get_test_select.c
   libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c
   libmicrohttpd/src/testcurl/https/tls_authentication_test.c
   libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c
   libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c
   libmicrohttpd/src/testcurl/https/tls_test_common.c
   libmicrohttpd/src/testcurl/https/tls_test_common.h
   libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c
Log:
simplifying tests by not using file on disk for test data

Modified: libmicrohttpd/src/testcurl/https/mhds_get_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_get_test.c    2010-08-19 13:35:01 UTC 
(rev 12677)
+++ libmicrohttpd/src/testcurl/https/mhds_get_test.c    2010-08-19 13:55:26 UTC 
(rev 12678)
@@ -92,34 +92,25 @@
 int
 main (int argc, char *const *argv)
 {
-  FILE *test_fd;
   unsigned int errorCount = 0;
 
   if (!gcry_check_version (GCRYPT_VERSION))
     abort ();
-  if ((test_fd = setup_test_file ()) == NULL)
-    {
-      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
-      return -1;
-    }
   if (0 != curl_global_init (CURL_GLOBAL_ALL))
     {
       fprintf (stderr, "Error: %s\n", strerror (errno));
-      fclose (test_fd);
       return -1;
     }
   errorCount +=
-    test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1);
+    test_secure_get (NULL, "AES256-SHA", CURL_SSLVERSION_TLSv1);
   errorCount +=
-    test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_SSLv3);
+    test_secure_get (NULL, "AES256-SHA", CURL_SSLVERSION_SSLv3);
   errorCount +=
-    test_cipher_option (test_fd, "DES-CBC3-SHA", CURL_SSLVERSION_TLSv1);
+    test_cipher_option (NULL, "DES-CBC3-SHA", CURL_SSLVERSION_TLSv1);
 
   print_test_result (errorCount, argv[0]);
 
   curl_global_cleanup ();
-  fclose (test_fd);
-  remove (TEST_FILE_NAME);
 
   return errorCount != 0;
 }

Modified: libmicrohttpd/src/testcurl/https/mhds_get_test_select.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_get_test_select.c     2010-08-19 
13:35:01 UTC (rev 12677)
+++ libmicrohttpd/src/testcurl/https/mhds_get_test_select.c     2010-08-19 
13:55:26 UTC (rev 12678)
@@ -203,27 +203,18 @@
 int
 main (int argc, char *const *argv)
 {
-  FILE *test_fd;
   unsigned int errorCount = 0;
 
   gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
   if (!gcry_check_version (GCRYPT_VERSION))
     abort ();
-  if ((test_fd = setup_test_file ()) == NULL)
-    {
-      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
-      return -1;
-    }
   if (0 != curl_global_init (CURL_GLOBAL_ALL))
     {
       fprintf (stderr, "Error: %s\n", strerror (errno));
-      fclose (test_fd);
       return -1;
     }
   if (0 != (errorCount = testExternalGet ()))
     fprintf (stderr, "Fail: %d\n", errorCount);
   curl_global_cleanup ();
-  fclose (test_fd);
-  remove (TEST_FILE_NAME);
   return errorCount != 0;
 }

Modified: libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c   2010-08-19 
13:35:01 UTC (rev 12677)
+++ libmicrohttpd/src/testcurl/https/mhds_multi_daemon_test.c   2010-08-19 
13:55:26 UTC (rev 12678)
@@ -36,112 +36,12 @@
 extern const char srv_key_pem[];
 extern const char srv_self_signed_cert_pem[];
 
-/* TODO mv to common */
-/**
- * perform cURL request for file
- * @param test_fd: file to attempt transferring
- */
-static int
-test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version,
-                 int port)
-{
-  CURL *c;
-  struct CBC cbc;
-  CURLcode errornum;
-  char url[255];
-  size_t len;
-  struct stat file_stat;
-
-  stat (TEST_FILE_NAME, &file_stat);
-  len = file_stat.st_size;
-
-  /* used to memcmp local copy & deamon supplied copy */
-  unsigned char *mem_test_file_local;
-
-  mem_test_file_local = malloc (len);
-  fseek (test_fd, 0, SEEK_SET);
-  if (fread (mem_test_file_local, sizeof (char), len, test_fd) != len)
-    {
-      fprintf (stderr, "Error: failed to read test file. %s\n",
-               strerror (errno));
-      free (mem_test_file_local);
-      return -1;
-    }
-
-  if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
-    {
-      fprintf (stderr, "Error: failed to read test file. %s\n",
-               strerror (errno));
-      free (mem_test_file_local);
-      return -1;
-    }
-  cbc.size = len;
-  cbc.pos = 0;
-
-  if (gen_test_file_url (url, port))
-    {
-      free (mem_test_file_local);
-      free (cbc.buf);
-      return -1;
-    }
-
-  c = curl_easy_init ();
-#if DEBUG_HTTPS_TEST
-  curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
-#endif
-  curl_easy_setopt (c, CURLOPT_URL, url);
-  curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
-  curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L);
-  curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
-  curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
-  curl_easy_setopt (c, CURLOPT_FILE, &cbc);
-
-  /* TLS options */
-  curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version);
-  curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, cipher_suite);
-
-  /* currently skip any peer authentication */
-  curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 0);
-  curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
-
-  curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
-
-  // NOTE: use of CONNECTTIMEOUT without also
-  //   setting NOSIGNAL results in really weird
-  //   crashes on my system!
-  curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
-  if (CURLE_OK != (errornum = curl_easy_perform (c)))
-    {
-      fprintf (stderr, "curl_easy_perform failed: `%s'\n",
-               curl_easy_strerror (errornum));
-      curl_easy_cleanup (c);
-      free (mem_test_file_local);
-      free (cbc.buf);
-      return errornum;
-    }
-
-  curl_easy_cleanup (c);
-
-  /* compare received file and local reference */
-  if (memcmp (cbc.buf, mem_test_file_local, len) != 0)
-    {
-      fprintf (stderr, "Error: local file & received file differ.\n");
-      free (mem_test_file_local);
-      free (cbc.buf);
-      return -1;
-    }
-
-  free (mem_test_file_local);
-  free (cbc.buf);
-  return 0;
-}
-
 /*
  * assert initiating two separate daemons and having one shut down
  * doesn't affect the other
  */
 int
-test_concurent_daemon_pair (FILE * test_fd, char *cipher_suite,
+test_concurent_daemon_pair (void * cls, char *cipher_suite,
                             int proto_version)
 {
 
@@ -176,14 +76,14 @@
     }
 
   ret =
-    test_daemon_get (test_fd, cipher_suite, proto_version, DEAMON_TEST_PORT);
+    test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
   ret +=
-    test_daemon_get (test_fd, cipher_suite, proto_version,
-                     DEAMON_TEST_PORT + 1);
+    test_daemon_get (NULL, cipher_suite, proto_version,
+                     DEAMON_TEST_PORT + 1, 0);
 
   MHD_stop_daemon (d2);
   ret +=
-    test_daemon_get (test_fd, cipher_suite, proto_version, DEAMON_TEST_PORT);
+    test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 0);
   MHD_stop_daemon (d1);
   return ret;
 }
@@ -191,29 +91,29 @@
 int
 main (int argc, char *const *argv)
 {
-  FILE *test_fd;
   unsigned int errorCount = 0;
+  FILE *cert;
 
-  if ((test_fd = setup_test_file ()) == NULL)
-    {
-      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
-      return -1;
-    }
   if (0 != curl_global_init (CURL_GLOBAL_ALL))
     {
       fprintf (stderr, "Error (code: %u). l:%d f:%s\n", errorCount, __LINE__,
                __FUNCTION__);
-      fclose (test_fd);
       return -1;
     }
+  if ((cert = setup_ca_cert ()) == NULL)
+    {
+      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
+      return -1;
+    }
+
+  
   errorCount +=
-    test_concurent_daemon_pair (test_fd, "AES256-SHA", CURL_SSLVERSION_SSLv3);
+    test_concurent_daemon_pair (NULL, "AES256-SHA", CURL_SSLVERSION_SSLv3);
 
   print_test_result (errorCount, "concurent_daemon_pair");
 
   curl_global_cleanup ();
-  fclose (test_fd);
-
-  remove (TEST_FILE_NAME);
+  fclose (cert);
+  remove (ca_cert_file_name);
   return errorCount != 0;
 }

Modified: libmicrohttpd/src/testcurl/https/tls_authentication_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_authentication_test.c  2010-08-19 
13:35:01 UTC (rev 12677)
+++ libmicrohttpd/src/testcurl/https/tls_authentication_test.c  2010-08-19 
13:55:26 UTC (rev 12678)
@@ -40,112 +40,11 @@
 extern const char srv_signed_cert_pem[];
 extern const char srv_signed_key_pem[];
 
-const char *ca_cert_file_name = "tmp_ca_cert.pem";
 
-/*
- * test HTTPS transfer
- * @param test_fd: file to attempt transfering
- */
-static int
-test_daemon_get (FILE * test_fd, char *cipher_suite, int proto_version)
-{
-  CURL *c;
-  struct CBC cbc;
-  CURLcode errornum;
-  char url[255];
-  struct stat statb;
 
-  stat (TEST_FILE_NAME, &statb);
-
-  int len = statb.st_size;
-
-  /* used to memcmp local copy & deamon supplied copy */
-  unsigned char *mem_test_file_local;
-
-  if (NULL == (mem_test_file_local = malloc (len)))
-    {
-      fprintf (stderr, MHD_E_MEM);
-      return -1;
-    }
-
-  fseek (test_fd, 0, SEEK_SET);
-  if (fread (mem_test_file_local, sizeof (char), len, test_fd) != len)
-    {
-      fprintf (stderr, "Error: failed to read test file. %s\n",
-               strerror (errno));
-      free (mem_test_file_local);
-      return -1;
-    }
-
-  if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
-    {
-      fprintf (stderr, MHD_E_MEM);
-      free (mem_test_file_local);
-      return -1;
-    }
-  cbc.size = len;
-  cbc.pos = 0;
-
-  /* construct url - this might use doc_path */
-  gen_test_file_url (url, DEAMON_TEST_PORT);
-
-  c = curl_easy_init ();
-#if DEBUG_HTTPS_TEST
-  curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
-#endif
-  curl_easy_setopt (c, CURLOPT_URL, url);
-  curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
-  curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L);
-  curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
-  curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
-  curl_easy_setopt (c, CURLOPT_FILE, &cbc);
-
-  /* TLS options */
-  curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version);
-  curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, cipher_suite);
-
-  /* perform peer authentication */
-  /* TODO merge into send_curl_req */
-  curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, 1);
-  curl_easy_setopt (c, CURLOPT_CAINFO, ca_cert_file_name);
-  curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
-
-  curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
-
-  curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
-
-  /* NOTE: use of CONNECTTIMEOUT without also
-     setting NOSIGNAL results in really weird
-     crashes on my system! */
-  curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
-  if (CURLE_OK != (errornum = curl_easy_perform (c)))
-    {
-      fprintf (stderr, "curl_easy_perform failed: `%s'\n",
-               curl_easy_strerror (errornum));
-      curl_easy_cleanup (c);
-      free (mem_test_file_local);
-      free (cbc.buf);
-      return errornum;
-    }
-
-  curl_easy_cleanup (c);
-
-  if (memcmp (cbc.buf, mem_test_file_local, len) != 0)
-    {
-      fprintf (stderr, "Error: local file & received file differ.\n");
-      free (cbc.buf);
-      free (mem_test_file_local);
-      return -1;
-    }
-
-  free (mem_test_file_local);
-  free (cbc.buf);
-  return 0;
-}
-
 /* perform a HTTP GET request via SSL/TLS */
 static int
-test_secure_get (FILE * test_fd, char *cipher_suite, int proto_version)
+test_secure_get (void * cls, char *cipher_suite, int proto_version)
 {
   int ret;
   struct MHD_Daemon *d;
@@ -163,49 +62,19 @@
       return -1;
     }
 
-  ret = test_daemon_get (test_fd, cipher_suite, proto_version);
+  ret = test_daemon_get (NULL, cipher_suite, proto_version, DEAMON_TEST_PORT, 
1);
 
   MHD_stop_daemon (d);
   return ret;
 }
 
-static FILE *
-setup_ca_cert ()
-{
-  FILE *cert_fd;
 
-  if (NULL == (cert_fd = fopen (ca_cert_file_name, "wb+")))
-    {
-      fprintf (stderr, "Error: failed to open `%s': %s\n",
-               ca_cert_file_name, strerror (errno));
-      return NULL;
-    }
-  if (fwrite (ca_cert_pem, sizeof (char), strlen (ca_cert_pem), cert_fd)
-      != strlen (ca_cert_pem))
-    {
-      fprintf (stderr, "Error: failed to write `%s. %s'\n",
-               ca_cert_file_name, strerror (errno));
-      fclose (cert_fd);
-      return NULL;
-    }
-  if (fflush (cert_fd))
-    {
-      fprintf (stderr, "Error: failed to flush ca cert file stream. %s\n",
-               strerror (errno));
-      fclose (cert_fd);
-      return NULL;
-    }
-
-  return cert_fd;
-}
-
 int
 main (int argc, char *const *argv)
 {
-  FILE *test_fd;
   unsigned int errorCount = 0;
 
-  if ((test_fd = setup_test_file ()) == NULL || setup_ca_cert () == NULL)
+  if (setup_ca_cert () == NULL)
     {
       fprintf (stderr, MHD_E_TEST_FILE_CREAT);
       return -1;
@@ -214,19 +83,15 @@
   if (0 != curl_global_init (CURL_GLOBAL_ALL))
     {
       fprintf (stderr, "Error (code: %u)\n", errorCount);
-      fclose (test_fd);
       return -1;
     }
 
   errorCount +=
-    test_secure_get (test_fd, "AES256-SHA", CURL_SSLVERSION_TLSv1);
+    test_secure_get (NULL, "AES256-SHA", CURL_SSLVERSION_TLSv1);
 
   print_test_result (errorCount, argv[0]);
 
   curl_global_cleanup ();
-  fclose (test_fd);
-
-  remove (TEST_FILE_NAME);
   remove (ca_cert_file_name);
   return errorCount != 0;
 }

Modified: libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c  2010-08-19 
13:35:01 UTC (rev 12677)
+++ libmicrohttpd/src/testcurl/https/tls_daemon_options_test.c  2010-08-19 
13:55:26 UTC (rev 12678)
@@ -42,7 +42,7 @@
  */
 /* TODO rm test_fd */
 int
-test_unmatching_ssl_version (FILE * test_fd, char *cipher_suite,
+test_unmatching_ssl_version (void * cls, char *cipher_suite,
                              int curl_req_ssl_version)
 {
   struct CBC cbc;
@@ -78,7 +78,6 @@
 int
 main (int argc, char *const *argv)
 {
-  FILE *test_fd;
   unsigned int errorCount = 0;
 
   int daemon_flags =
@@ -90,22 +89,14 @@
       return -1;
     }
 
-  if ((test_fd = setup_test_file ()) == NULL)
-    {
-      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
-      return -1;
-    }
-
   if (0 != curl_global_init (CURL_GLOBAL_ALL))
     {
-      fclose (test_fd);
-      remove (TEST_FILE_NAME);
       fprintf (stderr, "Error: %s\n", strerror (errno));
       return -1;
     }
   errorCount +=
     test_wrap ("TLS1.0-AES-SHA1",
-              &test_https_transfer, test_fd, daemon_flags,
+              &test_https_transfer, NULL, daemon_flags,
               "AES128-SHA1",
               CURL_SSLVERSION_TLSv1,
               MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -114,7 +105,7 @@
               MHD_OPTION_END);
   errorCount +=
     test_wrap ("TLS1.0-AES-SHA1",
-              &test_https_transfer, test_fd, daemon_flags,
+              &test_https_transfer, NULL, daemon_flags,
               "AES128-SHA1",
               CURL_SSLVERSION_SSLv3,
               MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -124,7 +115,7 @@
 
   errorCount +=
     test_wrap ("SSL3.0-AES-SHA1",
-              &test_https_transfer, test_fd, daemon_flags,
+              &test_https_transfer, NULL, daemon_flags,
               "AES128-SHA1",
               CURL_SSLVERSION_SSLv3,
               MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -141,7 +132,7 @@
      test is commented out here... */
   errorCount +=
     test_wrap ("unmatching version: SSL3 vs. TLS", 
&test_unmatching_ssl_version,
-               test_fd, daemon_flags, "AES256-SHA", CURL_SSLVERSION_TLSv1,
+               NULL, daemon_flags, "AES256-SHA", CURL_SSLVERSION_TLSv1,
                MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
                MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem,
                MHD_OPTION_CIPHER_ALGORITHM, "SSL3", MHD_OPTION_END);
@@ -149,7 +140,7 @@
 
   errorCount +=
     test_wrap ("TLS1.0 vs SSL3",
-              &test_unmatching_ssl_version, test_fd, daemon_flags,
+              &test_unmatching_ssl_version, NULL, daemon_flags,
               "AES256-SHA",
               CURL_SSLVERSION_SSLv3,
               MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem,
@@ -157,8 +148,6 @@
               MHD_OPTION_HTTPS_PRIORITIES, 
"NONE:+VERS-TLS1.0:+AES-256-CBC:+SHA1:+RSA:+COMP-NULL",
               MHD_OPTION_END);
   curl_global_cleanup ();
-  fclose (test_fd);
-  remove (TEST_FILE_NAME);
 
   return errorCount != 0;
 }

Modified: libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c       
2010-08-19 13:35:01 UTC (rev 12677)
+++ libmicrohttpd/src/testcurl/https/tls_multi_thread_mode_test.c       
2010-08-19 13:55:26 UTC (rev 12678)
@@ -52,7 +52,7 @@
 
   /* time spread incomming requests */
   usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
-  ret = test_https_transfer (cargs->test_fd,
+  ret = test_https_transfer (cargs->cls,
                              cargs->cipher_suite, cargs->proto_version);
   if (ret == 0)
     return NULL;
@@ -67,12 +67,12 @@
  * TODO : make client_count a parameter - numver of curl client threads to 
spawn
  */
 static int
-test_single_client (FILE * test_fd, char *cipher_suite,
+test_single_client (void *cls, char *cipher_suite,
                     int curl_proto_version)
 {
   void *client_thread_ret;
   struct https_test_data client_args =
-    { test_fd, cipher_suite, curl_proto_version };
+    { NULL, cipher_suite, curl_proto_version };
 
   client_thread_ret = https_transfer_thread_adapter (&client_args);
   if (client_thread_ret != NULL)
@@ -89,7 +89,7 @@
  * TODO : make client_count a parameter - numver of curl client threads to 
spawn
  */
 static int
-test_parallel_clients (FILE * test_fd, char *cipher_suite,
+test_parallel_clients (void *cls, char *cipher_suite,
                        int curl_proto_version)
 {
   int i;
@@ -97,7 +97,7 @@
   void *client_thread_ret;
   pthread_t client_arr[client_count];
   struct https_test_data client_args =
-    { test_fd, cipher_suite, curl_proto_version };
+    { NULL, cipher_suite, curl_proto_version };
 
   for (i = 0; i < client_count; ++i)
     {
@@ -125,28 +125,20 @@
 int
 main (int argc, char *const *argv)
 {
-  FILE *test_fd;
   unsigned int errorCount = 0;
 
   /* initialize random seed used by curl clients */
   unsigned int iseed = (unsigned int) time (NULL);
   srand (iseed);
-  if ((test_fd = setup_test_file ()) == NULL)
-    {
-      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
-      return -1;
-    }
-
   if (0 != curl_global_init (CURL_GLOBAL_ALL))
     {
       fprintf (stderr, "Error: %s\n", strerror (errno));
-      fclose (test_fd);
       return -1;
     }
 
   errorCount +=
     test_wrap ("multi threaded daemon, single client", &test_single_client,
-               test_fd,
+               NULL,
                MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION,
                "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
@@ -154,7 +146,7 @@
 
   errorCount +=
     test_wrap ("multi threaded daemon, parallel client",
-               &test_parallel_clients, test_fd,
+               &test_parallel_clients, NULL,
                MHD_USE_SSL | MHD_USE_DEBUG | MHD_USE_THREAD_PER_CONNECTION,
                "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
@@ -164,9 +156,5 @@
     fprintf (stderr, "Failed test: %s.\n", argv[0]);
 
   curl_global_cleanup ();
-  fclose (test_fd);
-
-  remove (TEST_FILE_NAME);
-
   return errorCount != 0;
 }

Modified: libmicrohttpd/src/testcurl/https/tls_test_common.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_test_common.c  2010-08-19 13:35:01 UTC 
(rev 12677)
+++ libmicrohttpd/src/testcurl/https/tls_test_common.c  2010-08-19 13:55:26 UTC 
(rev 12678)
@@ -26,10 +26,114 @@
 #include "tls_test_common.h"
 #include "tls_test_keys.h"
 
-const char test_file_data[] = "Hello World\n";
 
 int curl_check_version (const char *req_version, ...);
 
+FILE *
+setup_ca_cert ()
+{
+  FILE *cert_fd;
+
+  if (NULL == (cert_fd = fopen (ca_cert_file_name, "wb+")))
+    {
+      fprintf (stderr, "Error: failed to open `%s': %s\n",
+               ca_cert_file_name, strerror (errno));
+      return NULL;
+    }
+  if (fwrite (ca_cert_pem, sizeof (char), strlen (ca_cert_pem), cert_fd)
+      != strlen (ca_cert_pem))
+    {
+      fprintf (stderr, "Error: failed to write `%s. %s'\n",
+               ca_cert_file_name, strerror (errno));
+      fclose (cert_fd);
+      return NULL;
+    }
+  if (fflush (cert_fd))
+    {
+      fprintf (stderr, "Error: failed to flush ca cert file stream. %s\n",
+               strerror (errno));
+      fclose (cert_fd);
+      return NULL;
+    }
+  return cert_fd;
+}
+
+
+/*
+ * test HTTPS transfer
+ */
+int
+test_daemon_get (void *cls, char *cipher_suite, int proto_version,
+                int port,
+                int ver_peer)
+{
+  CURL *c;
+  struct CBC cbc;
+  CURLcode errornum;
+  char url[255];
+  size_t len;
+
+  len = strlen (test_data);
+  if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
+    {
+      fprintf (stderr, MHD_E_MEM);
+      return -1;
+    }
+  cbc.size = len;
+  cbc.pos = 0;
+
+  /* construct url - this might use doc_path */
+  gen_test_file_url (url, port);
+
+  c = curl_easy_init ();
+#if DEBUG_HTTPS_TEST
+  curl_easy_setopt (c, CURLOPT_VERBOSE, 1);
+#endif
+  curl_easy_setopt (c, CURLOPT_URL, url);
+  curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
+  curl_easy_setopt (c, CURLOPT_TIMEOUT, 10L);
+  curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 10L);
+  curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
+  curl_easy_setopt (c, CURLOPT_FILE, &cbc);
+
+  /* TLS options */
+  curl_easy_setopt (c, CURLOPT_SSLVERSION, proto_version);
+  curl_easy_setopt (c, CURLOPT_SSL_CIPHER_LIST, cipher_suite);
+
+  /* perform peer authentication */
+  /* TODO merge into send_curl_req */
+  curl_easy_setopt (c, CURLOPT_SSL_VERIFYPEER, ver_peer);
+  curl_easy_setopt (c, CURLOPT_CAINFO, ca_cert_file_name);
+  curl_easy_setopt (c, CURLOPT_SSL_VERIFYHOST, 0);
+  curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
+  
+  /* NOTE: use of CONNECTTIMEOUT without also
+     setting NOSIGNAL results in really weird
+     crashes on my system! */
+  curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
+  if (CURLE_OK != (errornum = curl_easy_perform (c)))
+    {
+      fprintf (stderr, "curl_easy_perform failed: `%s'\n",
+               curl_easy_strerror (errornum));
+      curl_easy_cleanup (c);
+      free (cbc.buf);
+      return errornum;
+    }
+
+  curl_easy_cleanup (c);
+
+  if (memcmp (cbc.buf, test_data, len) != 0)
+    {
+      fprintf (stderr, "Error: local file & received file differ.\n");
+      free (cbc.buf);
+      return -1;
+    }
+
+  free (cbc.buf);
+  return 0;
+}
+
+
 void
 print_test_result (int test_outcome, char *test_name)
 {
@@ -53,14 +157,6 @@
   return size * nmemb;
 }
 
-static int
-file_reader (void *cls, uint64_t pos, char *buf, int max)
-{
-  FILE *file = cls;
-  fseek (file, pos, SEEK_SET);
-  return fread (buf, 1, max, file);
-}
-
 /**
  *  HTTP access handler call back
  */
@@ -72,8 +168,6 @@
   static int aptr;
   struct MHD_Response *response;
   int ret;
-  FILE *file;
-  struct stat buf;
 
   if (0 != strcmp (method, MHD_HTTP_METHOD_GET))
     return MHD_NO;              /* unexpected method */
@@ -84,26 +178,11 @@
       return MHD_YES;
     }
   *ptr = NULL;                  /* reset when done */
-
-  file = fopen (url, "rb");
-  if (file == NULL)
-    {
-      response = MHD_create_response_from_data (strlen (PAGE_NOT_FOUND),
-                                                (void *) PAGE_NOT_FOUND,
-                                                MHD_NO, MHD_NO);
-      ret = MHD_queue_response (connection, MHD_HTTP_NOT_FOUND, response);
-      MHD_destroy_response (response);
-    }
-  else
-    {
-      stat (url, &buf);
-      response = MHD_create_response_from_callback (buf.st_size, 32 * 1024,    
 /* 32k PAGE_NOT_FOUND size */
-                                                    &file_reader, file,
-                                                    
(MHD_ContentReaderFreeCallback)
-                                                    & fclose);
-      ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
-      MHD_destroy_response (response);
-    }
+  response = MHD_create_response_from_data (strlen (test_data),
+                                           (void *) test_data,
+                                           MHD_NO, MHD_NO);
+  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+  MHD_destroy_response (response);
   return ret;
 }
 
@@ -199,7 +278,7 @@
     }
   /* construct url - this might use doc_path */
   if (sprintf (url, "%s:%d%s/%s", "https://localhost";, port,
-               doc_path, TEST_FILE_NAME) < 0)
+               doc_path, "urlpath") < 0)
     ret = -1;
 
   free (doc_path);
@@ -208,47 +287,20 @@
 
 /**
  * test HTTPS file transfer
- * @param test_fd: file to attempt transferring
  */
 int
-test_https_transfer (FILE * test_fd, char *cipher_suite, int proto_version)
+test_https_transfer (void *cls, char *cipher_suite, int proto_version)
 {
-  int len, ret = 0;
+  int len;
+  int ret = 0;
   struct CBC cbc;
   char url[255];
-  struct stat statb;
-  /* used to memcmp local copy & deamon supplied copy */
-  unsigned char *mem_test_file_local;
 
-  if (0 != stat (TEST_FILE_NAME, &statb))
-    {
-      fprintf (stderr, "Failed to stat `%s': %s\n",
-              TEST_FILE_NAME, strerror(errno));
-      return -1;
-    }
-  len = statb.st_size;
-  cbc.buf = NULL;
-  if (NULL == (mem_test_file_local = malloc (len)))
-    {
-      fprintf (stderr, MHD_E_MEM);
-      ret = -1;
-      goto cleanup;
-    }
-
-  fseek (test_fd, 0, SEEK_SET);
-  if (fread (mem_test_file_local, sizeof (char), len, test_fd) != len)
-    {
-      fprintf (stderr, "Error: failed to read test file. %s\n",
-               strerror (errno));
-      ret = -1;
-      goto cleanup;
-    }
-
+  len = strlen (test_data);
   if (NULL == (cbc.buf = malloc (sizeof (char) * len)))
     {
       fprintf (stderr, MHD_E_MEM);
-      ret = -1;
-      goto cleanup;
+      return -1;
     }
   cbc.size = len;
   cbc.pos = 0;
@@ -266,53 +318,20 @@
     }
 
   /* compare test file & daemon responce */
-  if (memcmp (cbc.buf, mem_test_file_local, len) != 0)
+  if ( (len != strlen (test_data)) ||
+       (memcmp (cbc.buf, 
+               test_data, 
+               len) != 0) )
     {
       fprintf (stderr, "Error: local file & received file differ.\n");
       ret = -1;
     }
-
 cleanup:
-  free (mem_test_file_local);
-  if (cbc.buf != NULL)
-    free (cbc.buf);
+  free (cbc.buf);
   return ret;
 }
 
 /**
- * setup a mock test file which is requested from the running daemon
- * @return open file descriptor to the test file
- */
-FILE *
-setup_test_file ()
-{
-  FILE *test_fd;
-
-  if (NULL == (test_fd = fopen (TEST_FILE_NAME, "wb+")))
-    {
-      fprintf (stderr, "Error: failed to open `%s': %s\n",
-               TEST_FILE_NAME, strerror (errno));
-      return NULL;
-    }
-  if (fwrite (test_file_data, sizeof (char), strlen (test_file_data), test_fd)
-      != strlen (test_file_data))
-    {
-      fprintf (stderr, "Error: failed to write `%s. %s'\n",
-               TEST_FILE_NAME, strerror (errno));
-      fclose (test_fd);
-      return NULL;
-    }
-  if (fflush (test_fd))
-    {
-      fprintf (stderr, "Error: failed to flush test file stream. %s\n",
-               strerror (errno));
-      fclose (test_fd);
-      return NULL;
-    }
-  return test_fd;
-}
-
-/**
  * setup test case
  *
  * @param d
@@ -390,8 +409,8 @@
 /* TODO test_wrap: change sig to (setup_func, test, va_list test_arg) */
 int
 test_wrap (char *test_name, int
-           (*test_function) (FILE * test_fd, char *cipher_suite,
-                             int proto_version), FILE * test_fd,
+           (*test_function) (void * cls, char *cipher_suite,
+                             int proto_version), void * cls,
            int daemon_flags, char *cipher_suite, int proto_version, ...)
 {
   int ret;
@@ -407,7 +426,7 @@
 #if 0
   fprintf (stdout, "running test: %s ", test_name);
 #endif
-  ret = test_function (test_fd, cipher_suite, proto_version);
+  ret = test_function (NULL, cipher_suite, proto_version);
 #if 0
   if (ret == 0)
     {

Modified: libmicrohttpd/src/testcurl/https/tls_test_common.h
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_test_common.h  2010-08-19 13:35:01 UTC 
(rev 12677)
+++ libmicrohttpd/src/testcurl/https/tls_test_common.h  2010-08-19 13:55:26 UTC 
(rev 12678)
@@ -34,7 +34,8 @@
 
 #define DEAMON_TEST_PORT 42433
 
-#define TEST_FILE_NAME "https_test_file"
+#define test_data "Hello World\n"
+#define ca_cert_file_name "tmp_ca_cert.pem"
 
 #define EMPTY_PAGE "<html><head><title>Empty page</title></head><body>Empty 
page</body></html>"
 #define PAGE_NOT_FOUND "<html><head><title>File not 
found</title></head><body>File not found</body></html>"
@@ -49,7 +50,7 @@
 /* TODO rm if unused */
 struct https_test_data
 {
-  FILE *test_fd;
+  void *cls;
   char *cipher_suite;
   int proto_version;
 };
@@ -67,6 +68,17 @@
   char *curlname;
 };
 
+
+FILE *
+setup_ca_cert ();
+
+/**
+ * perform cURL request for file
+ */
+int
+test_daemon_get (void * cls, char *cipher_suite, int proto_version,
+                 int port, int ver_peer);
+
 void print_test_result (int test_outcome, char *test_name);
 
 size_t copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx);
@@ -89,10 +101,8 @@
                int proto_version);
 
 int
-test_https_transfer (FILE * test_fd, char *cipher_suite, int proto_version);
+test_https_transfer (void *cls, char *cipher_suite, int proto_version);
 
-FILE *setup_test_file ();
-
 int
 setup_testcase (struct MHD_Daemon **d, int daemon_flags, va_list arg_list);
 
@@ -112,7 +122,7 @@
 
 int
 test_wrap (char *test_name, int
-           (*test_function) (FILE * test_fd, char *cipher_suite,
-                             int proto_version), FILE * test_fd,
+           (*test_function) (void * cls, char *cipher_suite,
+                             int proto_version), void *test_function_cls,
            int daemon_flags, char *cipher_suite, int proto_version, ...);
 #endif /* TLS_TEST_COMMON_H_ */

Modified: libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c
===================================================================
--- libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c     2010-08-19 
13:35:01 UTC (rev 12677)
+++ libmicrohttpd/src/testcurl/https/tls_thread_mode_test.c     2010-08-19 
13:55:26 UTC (rev 12678)
@@ -53,7 +53,7 @@
 
   /* time spread incomming requests */
   usleep ((useconds_t) 10.0 * ((double) rand ()) / ((double) RAND_MAX));
-  ret = test_https_transfer (cargs->test_fd,
+  ret = test_https_transfer (NULL,
                              cargs->cipher_suite, cargs->proto_version);
   if (ret == 0)
     return NULL;
@@ -68,12 +68,12 @@
  * TODO : make client_count a parameter - numver of curl client threads to 
spawn
  */
 static int
-test_single_client (FILE * test_fd, char *cipher_suite,
+test_single_client (void *cls, char *cipher_suite,
                     int curl_proto_version)
 {
   void *client_thread_ret;
   struct https_test_data client_args =
-    { test_fd, cipher_suite, curl_proto_version };
+    { NULL, cipher_suite, curl_proto_version };
 
   client_thread_ret = https_transfer_thread_adapter (&client_args);
   if (client_thread_ret != NULL)
@@ -89,7 +89,7 @@
  * TODO : make client_count a parameter - numver of curl client threads to 
spawn
  */
 static int
-test_parallel_clients (FILE * test_fd, char *cipher_suite,
+test_parallel_clients (void * cls, char *cipher_suite,
                        int curl_proto_version)
 {
   int i;
@@ -97,7 +97,7 @@
   void *client_thread_ret;
   pthread_t client_arr[client_count];
   struct https_test_data client_args =
-    { test_fd, cipher_suite, curl_proto_version };
+    { NULL, cipher_suite, curl_proto_version };
 
   for (i = 0; i < client_count; ++i)
     {
@@ -124,31 +124,22 @@
 
 int
 main (int argc, char *const *argv)
-{
-  FILE *test_fd;
+{  
   unsigned int errorCount = 0;
 
   /* initialize random seed used by curl clients */
   unsigned int iseed = (unsigned int) time (NULL);
   srand (iseed);
   gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
-  if ((test_fd = setup_test_file ()) == NULL)
-    {
-      fprintf (stderr, MHD_E_TEST_FILE_CREAT);
-      return -1;
-    }
-
   if (0 != curl_global_init (CURL_GLOBAL_ALL))
     {
       fprintf (stderr, "Error: %s\n", strerror (errno));
-      fclose (test_fd);
-      remove (TEST_FILE_NAME);
       return -1;
     }
 
   errorCount +=
     test_wrap ("single threaded daemon, single client", &test_single_client,
-               test_fd,
+               NULL,
                MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
                "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
@@ -156,15 +147,12 @@
 
   errorCount +=
     test_wrap ("single threaded daemon, parallel clients",
-               &test_parallel_clients, test_fd,
+               &test_parallel_clients, NULL,
                MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL | MHD_USE_DEBUG,
                "AES256-SHA", CURL_SSLVERSION_TLSv1, MHD_OPTION_HTTPS_MEM_KEY,
                srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT,
                srv_self_signed_cert_pem, MHD_OPTION_END);
 
   curl_global_cleanup ();
-  fclose (test_fd);
-  remove (TEST_FILE_NAME);
-
   return errorCount != 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]