getinfo: provide info which auth was used for HTTP and proxy

CURLINFO_HTTPAUTH_USED and CURLINFO_PROXYAUTH_USED

Tested in 590 and 694

Ref: #12668
Idea-by: Ganesh Viswanathan
Closes #15450
This commit is contained in:
Daniel Stenberg 2024-10-29 16:53:32 +01:00
parent f3efab1bb4
commit 9d5ecc9613
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
15 changed files with 409 additions and 9 deletions

View file

@ -101,7 +101,7 @@ test652 test653 test654 test655 test656 test658 test659 test660 test661 \
test662 test663 test664 test665 test666 test667 test668 test669 test670 \
test671 test672 test673 test674 test675 test676 test677 test678 test679 \
test680 test681 test682 test683 test684 test685 test686 test687 test688 \
test689 test690 test691 test692 test693 \
test689 test690 test691 test692 test693 test694 \
\
test700 test701 test702 test703 test704 test705 test706 test707 test708 \
test709 test710 test711 test712 test713 test714 test715 test716 test717 \

127
tests/data/test694 Normal file
View file

@ -0,0 +1,127 @@
<testcase>
<info>
<keywords>
HTTP
HTTP POST
POST callback
HTTP proxy
HTTP proxy NTLM auth
NTLM
</keywords>
</info>
# Server-side
<reply>
<data>
HTTP/1.1 401 Authorization Required
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
Content-Type: text/html; charset=iso-8859-1
Content-Length: 26
This is not the real page
</data>
# this is returned first since we get no proxy-auth
<data1001>
HTTP/1.1 401 Authorization Required
WWW-Authenticate: NTLM TlRMTVNTUAACAAAAAgACADAAAACGggEAc51AYVDgyNcAAAAAAAAAAG4AbgAyAAAAQ0MCAAQAQwBDAAEAEgBFAEwASQBTAEEAQgBFAFQASAAEABgAYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAwAsAGUAbABpAHMAYQBiAGUAdABoAC4AYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAAAAAA==
Content-Length: 34
Hey you, authenticate or go away!
</data1001>
# This is supposed to be returned when the server gets the second
# Authorization: NTLM line passed-in from the client
<data1002>
HTTP/1.1 200 Things are fine
Server: Microsoft-IIS/5.0
Content-Type: text/html; charset=iso-8859-1
Content-Length: 42
Contents of that page you requested, sir.
</data1002>
# This is supposed to be returned when the server gets the second
# request.
<data10>
HTTP/1.1 200 Things are fine
Content-Type: yeah/maybe
Content-Length: 42
Contents of that second request. Differn.
</data10>
<datacheck>
HTTP/1.1 401 Authorization Required
Server: Apache/1.3.27 (Darwin) PHP/4.1.2
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
Content-Type: text/html; charset=iso-8859-1
Content-Length: 26
HTTP/1.1 401 Authorization Required
WWW-Authenticate: NTLM TlRMTVNTUAACAAAAAgACADAAAACGggEAc51AYVDgyNcAAAAAAAAAAG4AbgAyAAAAQ0MCAAQAQwBDAAEAEgBFAEwASQBTAEEAQgBFAFQASAAEABgAYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAwAsAGUAbABpAHMAYQBiAGUAdABoAC4AYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAAAAAA==
Content-Length: 34
HTTP/1.1 200 Things are fine
Server: Microsoft-IIS/5.0
Content-Type: text/html; charset=iso-8859-1
Content-Length: 42
Contents of that page you requested, sir.
HTTP/1.1 200 Things are fine
Content-Type: yeah/maybe
Content-Length: 42
Contents of that second request. Differn.
</datacheck>
</reply>
# Client-side
<client>
<server>
http
</server>
# tool to use
<tool>
lib%TESTNUMBER
</tool>
<features>
NTLM
!SSPI
</features>
<name>
HTTP with NTLM twice, verify CURLINFO_HTTPAUTH_USED
</name>
<command>
http://%HOSTIP:%HTTPPORT/path/mine http://%HOSTIP:%HTTPPORT/path/%TESTNUMBER0010
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<protocol crlf="yes">
GET /path/mine HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
GET /path/mine HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Authorization: NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=
Accept: */*
GET /path/mine HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAAAAABwAAAAAgACAHAAAAALAAsAcgAAAAAAAAAAAAAAhoIBAAQt1KW5CgG4YdWWcfXyfXBz1ZMCzYp37xYjBiAizmw58O6eQS7yR66eqYGWeSwl9W1lV09SS1NUQVRJT04=
Accept: */*
GET /path/6940010 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
</protocol>
</verify>
</testcase>

View file

@ -48,7 +48,7 @@ LIBTESTPROGS = libauthretry libntlmconnect libprereq \
lib599 \
lib643 lib645 lib650 lib651 lib652 lib653 lib654 lib655 lib658 \
lib659 lib661 lib666 lib667 lib668 \
lib670 lib671 lib672 lib673 lib674 lib676 lib677 lib678 \
lib670 lib671 lib672 lib673 lib674 lib676 lib677 lib678 lib694 \
lib1156 \
lib1301 \
lib1485 \
@ -338,6 +338,8 @@ lib677_LDADD = $(TESTUTIL_LIBS)
lib678_SOURCES = lib678.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) $(MULTIBYTE)
lib678_LDADD = $(TESTUTIL_LIBS)
lib694_SOURCES = lib694.c $(SUPPORTFILES)
lib1301_SOURCES = lib1301.c $(SUPPORTFILES) $(TESTUTIL)
lib1301_LDADD = $(TESTUTIL_LIBS)

View file

@ -42,6 +42,7 @@ CURLcode test(char *URL)
{
CURLcode res;
CURL *curl;
long usedauth = 0;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
@ -64,6 +65,11 @@ CURLcode test(char *URL)
res = curl_easy_perform(curl);
res = curl_easy_getinfo(curl, CURLINFO_PROXYAUTH_USED, &usedauth);
if(CURLAUTH_NTLM != usedauth) {
printf("CURLINFO_PROXYAUTH_USED did not say NTLM\n");
}
test_cleanup:
curl_easy_cleanup(curl);

73
tests/libtest/lib694.c Normal file
View file

@ -0,0 +1,73 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "test.h"
#include "memdebug.h"
CURLcode test(char *URL)
{
CURLcode res;
CURL *curl;
long usedauth = 0;
int count = 0;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
fprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_HEADER, 1L);
test_setopt(curl, CURLOPT_VERBOSE, 1L);
test_setopt(curl, CURLOPT_HTTPAUTH,
(long) (CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_NTLM));
test_setopt(curl, CURLOPT_USERPWD, "me:password");
do {
res = curl_easy_perform(curl);
res = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_USED, &usedauth);
if(CURLAUTH_NTLM != usedauth) {
printf("CURLINFO_HTTPAUTH_USED did not say NTLM\n");
}
/* set a new URL for the second, so that we don't restart NTLM */
test_setopt(curl, CURLOPT_URL, libtest_arg2);
} while(!res && ++count < 2);
test_cleanup:
curl_easy_cleanup(curl);
curl_global_cleanup();
return res;
}