gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 03/03: Added one more test for Basic Auth


From: gnunet
Subject: [libmicrohttpd] 03/03: Added one more test for Basic Auth
Date: Tue, 07 Jun 2022 18:34:06 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 56b131d9ec5f04f9d16b42886fb942eb378bfd16
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Tue Jun 7 16:19:25 2022 +0300

    Added one more test for Basic Auth
    
    By default libcurl sends Basic Authentication header without checking
    whether authentication is required. New test forces libcrul to try
    without authentication at first to test MHD's "auth fail response"
    function.
---
 src/testcurl/.gitignore       |  1 +
 src/testcurl/Makefile.am      |  5 ++++-
 src/testcurl/test_basicauth.c | 22 +++++++++++++++++++++-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/testcurl/.gitignore b/src/testcurl/.gitignore
index d67154d5..cf6a4bc3 100644
--- a/src/testcurl/.gitignore
+++ b/src/testcurl/.gitignore
@@ -152,3 +152,4 @@ core
 /test_digestauth_concurrent
 /test_basicauth
 /test_parse_cookies_invalid
+/test_basicauth_preauth
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am
index ed585527..aeeabb6b 100644
--- a/src/testcurl/Makefile.am
+++ b/src/testcurl/Makefile.am
@@ -153,7 +153,7 @@ endif
 
 if ENABLE_BAUTH
 check_PROGRAMS += \
-  test_basicauth
+  test_basicauth test_basicauth_preauth
 endif
 
 if HAVE_POSTPROCESSOR
@@ -236,6 +236,9 @@ perf_get_concurrent11_LDADD = \
 test_basicauth_SOURCES = \
   test_basicauth.c
 
+test_basicauth_preauth_SOURCES = \
+  test_basicauth.c
+
 test_digestauth_SOURCES = \
   test_digestauth.c
 test_digestauth_LDADD = \
diff --git a/src/testcurl/test_basicauth.c b/src/testcurl/test_basicauth.c
index 1b84ac15..c7f1df84 100644
--- a/src/testcurl/test_basicauth.c
+++ b/src/testcurl/test_basicauth.c
@@ -42,6 +42,7 @@
 #endif
 
 #include "mhd_has_param.h"
+#include "mhd_has_in_name.h"
 
 #ifndef MHD_STATICSTR_LEN_
 /**
@@ -249,6 +250,7 @@ struct CBC
 };
 
 static int verbose;
+static int preauth;
 
 static size_t
 copyBuffer (void *ptr,
@@ -384,10 +386,19 @@ setupCURL (void *cbc, int port, char *errbuf)
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_PORT, ((long) port))) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_URL, url)))
     libcurlErrorExitDesc ("curl_easy_setopt() failed");
+#if CURL_AT_LEAST_VERSION(7,21,3)
+  if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTPAUTH,
+                                     CURLAUTH_BASIC |
+                                     (preauth ? 0 : CURLAUTH_ONLY))) ||
+      (CURLE_OK != curl_easy_setopt (c, CURLOPT_USERPWD,
+                                     USERNAME ":" PASSWORD)))
+    libcurlErrorExitDesc ("curl_easy_setopt() authorization options failed");
+#else  /* libcurl version before 7.21.3 */
   if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC)) ||
       (CURLE_OK != curl_easy_setopt (c, CURLOPT_USERPWD,
                                      USERNAME ":" PASSWORD)))
     libcurlErrorExitDesc ("curl_easy_setopt() authorization options failed");
+#endif /* libcurl version before 7.21.3 */
   return c;
 }
 
@@ -617,8 +628,17 @@ main (int argc, char *const *argv)
                has_param (argc, argv, "--quiet") ||
                has_param (argc, argv, "-s") ||
                has_param (argc, argv, "--silent"));
+  preauth = has_in_name (argv[0], "_preauth");
+#if ! CURL_AT_LEAST_VERSION (7,21,3)
+  if (preauth)
+  {
+    fprintf (stderr, "libcurl version 7.21.3 or later is "
+             "required to run this test.\n");
+    return 77;
+  }
+#endif /* libcurl version before 7.21.3 */
 
-  #ifdef MHD_HTTPS_REQUIRE_GRYPT
+#ifdef MHD_HTTPS_REQUIRE_GRYPT
 #ifdef HAVE_GCRYPT_H
   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
 #ifdef GCRYCTL_INITIALIZATION_FINISHED

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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