diff --git a/src/tests/client_server/libtest_convenience_client_request.c b/src/tests/client_server/libtest_convenience_client_request.c index 0f4ab913..ec488f0c 100644 --- a/src/tests/client_server/libtest_convenience_client_request.c +++ b/src/tests/client_server/libtest_convenience_client_request.c @@ -838,7 +838,7 @@ send_basic_auth (const char *cred, if (NULL == pass) return "invalid credential given"; user = strndup (cred, - pass - user); + pass - cred); pass++; c = curl_easy_init (); if (NULL == c) @@ -862,11 +862,11 @@ send_basic_auth (const char *cred, (CURLE_OK != curl_easy_setopt (c, CURLOPT_USERNAME, - "user")) || + user)) || (CURLE_OK != curl_easy_setopt (c, CURLOPT_PASSWORD, - "password")) ) + pass)) ) { curl_easy_cleanup (c); free (user); diff --git a/src/tests/client_server/libtest_convenience_server_reply.c b/src/tests/client_server/libtest_convenience_server_reply.c index 178156a5..87dab3ca 100644 --- a/src/tests/client_server/libtest_convenience_server_reply.c +++ b/src/tests/client_server/libtest_convenience_server_reply.c @@ -736,41 +736,38 @@ MHDT_server_reply_check_basic_auth ( const char *cred = cls; union MHD_RequestInfoDynamicData dd; enum MHD_StatusCode sc; - struct MHD_BasicAuthInfo *ba; - struct MHD_Connection *connection; // FIXME - suboptimal API - union MHD_RequestInfoFixedData rif; + const struct MHD_BasicAuthInfo *ba; -#define FIXME 1 -#if FIXME - sc = MHD_request_get_info_fixed (request, - MHD_REQUEST_INFO_FIXED_CONNECTION, - &rif); - if (MHD_SC_OK != sc) - return NULL; - connection = rif.v_connection; -#endif /* should not be needed, except to make gcc happy */ memset (&dd, 0, sizeof (dd)); sc = MHD_request_get_info_dynamic (request, - MHD_REQUEST_INFO_DYNAMIC_BAUTH_REQ_INFO, + MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS, &dd); if (MHD_SC_OK != sc) - return MHD_action_basic_auth_required_response ( - connection, // FIXME: I'd like to see 'request' here. + { + fprintf (stderr, + "No credentials?\n"); + return MHD_action_basic_auth_challenge_p ( + request, "test-realm", MHD_YES, MHD_response_from_empty ( - MHD_HTTP_STATUS_FORBIDDEN)); - ba = dd.v_bauth_info; + MHD_HTTP_STATUS_UNAUTHORIZED)); + } + ba = dd.v_auth_basic_creds; if (NULL == ba) - return MHD_action_basic_auth_required_response ( - connection, // FIXME: I'd like to see 'request' here. + { + fprintf (stderr, + "No credentials??\n"); + return MHD_action_basic_auth_challenge_p ( + request, "test-realm", MHD_YES, MHD_response_from_empty ( - MHD_HTTP_STATUS_FORBIDDEN)); + MHD_HTTP_STATUS_UNAUTHORIZED)); + } if ( (0 != strncmp (ba->username.cstr, cred, ba->username.len)) || @@ -778,12 +775,19 @@ MHDT_server_reply_check_basic_auth ( (NULL == ba->password.cstr) || (0 != strcmp (ba->password.cstr, &cred[ba->username.len + 1])) ) - return MHD_action_basic_auth_required_response ( - connection, // FIXME: I'd like to see 'request' here. + { + fprintf (stderr, + "Wrong credentials (Got: %s/%s Want: %s)!\n", + ba->username.cstr, + ba->password.cstr, + cred); + return MHD_action_basic_auth_challenge_p ( + request, "test-realm", MHD_YES, MHD_response_from_empty ( - MHD_HTTP_STATUS_FORBIDDEN)); + MHD_HTTP_STATUS_UNAUTHORIZED)); + } return MHD_action_from_response ( request, MHD_response_from_empty (