libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 56b131d9ec5f04f9d16b42886fb942eb378bfd16
parent 02ed59e79c67be98ea7e6b4174221467a15d7df5
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue,  7 Jun 2022 16:19:25 +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.

Diffstat:
Msrc/testcurl/.gitignore | 1+
Msrc/testcurl/Makefile.am | 5++++-
Msrc/testcurl/test_basicauth.c | 22+++++++++++++++++++++-
3 files changed, 26 insertions(+), 2 deletions(-)

diff --git 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 @@ -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 @@ -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