1
0
mirror of https://github.com/mirror/wget.git synced 2025-04-24 12:10:16 +08:00

Add command line option to disable use of .netrc

Although internally code uses option for (not) reading .netrc for
credentials, it was not possible to turn this behavior off on command
line. Note that it was possible to turn it off using wgetrc.

Idea for this change came from Bruce Jerrick (bmj001@gmail.com).
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1425097

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2017-05-12 19:17:32 +02:00 committed by Tim Rühsen
parent f8c3df1f40
commit 876def8ebe
4 changed files with 69 additions and 0 deletions

View File

@ -703,6 +703,12 @@ Before (over)writing a file, back up an existing file by adding a
files are rotated to @samp{.2}, @samp{.3}, and so on, up to
@var{backups} (and lost beyond that).
@cindex authentication credentials
@item --no-netrc
Do not try to obtain credentials from @file{.netrc} file. By default
@file{.netrc} file is searched for credentials in case none have been
passed on command line and authentication is required.
@cindex continue retrieval
@cindex incomplete downloads
@cindex resume download

View File

@ -359,6 +359,7 @@ static struct cmdline_option option_data[] =
#endif
{ "method", 0, OPT_VALUE, "method", -1 },
{ "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
{ "netrc", 0, OPT_BOOLEAN, "netrc", -1 },
{ "no", 'n', OPT__NO, NULL, required_argument },
{ "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 },
{ "no-config", 0, OPT_BOOLEAN, "noconfig", -1},
@ -628,6 +629,8 @@ Download:\n"),
N_("\
-nc, --no-clobber skip downloads that would download to\n\
existing files (overwriting them)\n"),
N_("\
--no-netrc don't try to obtain credentials from .netrc\n"),
N_("\
-c, --continue resume getting a partially-downloaded file\n"),
N_("\

View File

@ -78,6 +78,7 @@ if HAVE_PYTHON3
Test-auth-basic-netrc.py \
Test-auth-basic-netrc-user-given.py \
Test-auth-basic-netrc-pass-given.py \
Test-auth-basic-no-netrc-fail.py \
Test-auth-both.py \
Test-auth-digest.py \
Test-auth-no-challenge.py \

View File

@ -0,0 +1,59 @@
#!/usr/bin/env python3
from sys import exit
from test.http_test import HTTPTest
from misc.wget_file import WgetFile
"""
This test ensures that Wget will not use credentials from .netrc
when --no-netrc option is specified and Basic authentication is required
and fails.
"""
############# File Definitions ###############################################
File1 = "I am an invisble man."
User = "Sauron"
Password = "TheEye"
File1_rules = {
"Authentication" : {
"Type" : "Basic",
"User" : User,
"Pass" : Password
}
}
Netrc = "machine 127.0.0.1\n\tlogin {0}\n\tpassword {1}".format(User, Password)
A_File = WgetFile ("File1", File1, rules=File1_rules)
Netrc_File = WgetFile (".netrc", Netrc)
WGET_OPTIONS = "--no-netrc"
WGET_URLS = [["File1"]]
Files = [[A_File]]
LocalFiles = [Netrc_File]
ExpectedReturnCode = 6
ExpectedDownloadedFiles = [Netrc_File]
################ Pre and Post Test Hooks #####################################
pre_test = {
"ServerFiles" : Files,
"LocalFiles" : LocalFiles
}
test_options = {
"WgetCommands" : WGET_OPTIONS,
"Urls" : WGET_URLS
}
post_test = {
"ExpectedFiles" : ExpectedDownloadedFiles,
"ExpectedRetcode" : ExpectedReturnCode
}
err = HTTPTest (
pre_hook=pre_test,
test_params=test_options,
post_hook=post_test
).begin ()
exit (err)