netrc: use the NETRC environment variable (first) if set

Add test 755 to verify.

Proposed-by: Berthin Torres Callañaupa
URL: https://curl.se/mail/lib-2025-06/0015.html

Closes #17712
This commit is contained in:
Daniel Stenberg 2025-06-23 00:09:18 +02:00
parent cb9b1a4c4e
commit cb2a48bf5b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 111 additions and 39 deletions

59
tests/data/test755 Normal file
View file

@ -0,0 +1,59 @@
<testcase>
<info>
<keywords>
HTTP
netrc
</keywords>
</info>
#
# Server-side
<reply>
<data>
HTTP/1.1 200 OK
Date: Tue, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake swsclose
Content-Type: text/html
Funny-head: yesyes
Content-Length: 9
contents
</data>
</reply>
#
# Client-side
<client>
<server>
http
</server>
<name>
netrc with NETRC pointing out the file
</name>
<file name="%LOGDIR/netrc%TESTNUMBER">
machine foo.host login foo password alone-in-the-dark
</file>
<setenv>
NETRC=%LOGDIR/netrc%TESTNUMBER
</setenv>
<command>
http://foo.host/%TESTNUMBER --proxy %HOSTIP:%HTTPPORT -A "" --netrc
</command>
<features>
proxy
</features>
</client>
#
# Verify data after the test has been "shot"
<verify>
<protocol crlf="yes">
GET http://foo.host/%TESTNUMBER HTTP/1.1
Host: foo.host
Authorization: Basic %b64[foo:alone-in-the-dark]b64%
Accept: */*
Proxy-Connection: Keep-Alive
</protocol>
</verify>
</testcase>