34da3b1
From 876def8ebe56d483921cf645371d277b615373e5 Mon Sep 17 00:00:00 2001
34da3b1
From: Tomas Hozza <thozza@redhat.com>
34da3b1
Date: Fri, 12 May 2017 19:17:32 +0200
34da3b1
Subject: [PATCH 3/4] Add command line option to disable use of .netrc
34da3b1
34da3b1
Although internally code uses option for (not) reading .netrc for
34da3b1
credentials, it was not possible to turn this behavior off on command
34da3b1
line. Note that it was possible to turn it off using wgetrc.
34da3b1
34da3b1
Idea for this change came from Bruce Jerrick (bmj001@gmail.com).
34da3b1
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1425097
34da3b1
34da3b1
Signed-off-by: Tomas Hozza <thozza@redhat.com>
34da3b1
---
34da3b1
 doc/wget.texi                            |  6 ++++
34da3b1
 src/main.c                               |  3 ++
34da3b1
 testenv/Makefile.am                      |  1 +
34da3b1
 testenv/Test-auth-basic-no-netrc-fail.py | 59 ++++++++++++++++++++++++++++++++
34da3b1
 4 files changed, 69 insertions(+)
34da3b1
 create mode 100755 testenv/Test-auth-basic-no-netrc-fail.py
34da3b1
34da3b1
diff --git a/doc/wget.texi b/doc/wget.texi
34da3b1
index a2bf9dc..e4e0bf6 100644
34da3b1
--- a/doc/wget.texi
34da3b1
+++ b/doc/wget.texi
34da3b1
@@ -703,6 +703,12 @@ Before (over)writing a file, back up an existing file by adding a
34da3b1
 files are rotated to @samp{.2}, @samp{.3}, and so on, up to
34da3b1
 @var{backups} (and lost beyond that).
34da3b1
 
34da3b1
+@cindex authentication credentials
34da3b1
+@item --no-netrc
34da3b1
+Do not try to obtain credentials from @file{.netrc} file. By default
34da3b1
+@file{.netrc} file is searched for credentials in case none have been
34da3b1
+passed on command line and authentication is required.
34da3b1
+
34da3b1
 @cindex continue retrieval
34da3b1
 @cindex incomplete downloads
34da3b1
 @cindex resume download
34da3b1
diff --git a/src/main.c b/src/main.c
34da3b1
index 8e9d6e9..297499e 100644
34da3b1
--- a/src/main.c
34da3b1
+++ b/src/main.c
34da3b1
@@ -359,6 +359,7 @@ static struct cmdline_option option_data[] =
34da3b1
 #endif
34da3b1
     { "method", 0, OPT_VALUE, "method", -1 },
34da3b1
     { "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
34da3b1
+    { "netrc", 0, OPT_BOOLEAN, "netrc", -1 },
34da3b1
     { "no", 'n', OPT__NO, NULL, required_argument },
34da3b1
     { "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 },
34da3b1
     { "no-config", 0, OPT_BOOLEAN, "noconfig", -1},
34da3b1
@@ -629,6 +630,8 @@ Download:\n"),
34da3b1
   -nc, --no-clobber                skip downloads that would download to\n\
34da3b1
                                      existing files (overwriting them)\n"),
34da3b1
     N_("\
34da3b1
+       --no-netrc                  don't try to obtain credentials from .netrc\n"),
34da3b1
+    N_("\
34da3b1
   -c,  --continue                  resume getting a partially-downloaded file\n"),
34da3b1
     N_("\
34da3b1
        --start-pos=OFFSET          start downloading from zero-based position OFFSET\n"),
34da3b1
diff --git a/testenv/Makefile.am b/testenv/Makefile.am
34da3b1
index 7104314..ef4158a 100644
34da3b1
--- a/testenv/Makefile.am
34da3b1
+++ b/testenv/Makefile.am
34da3b1
@@ -78,6 +78,7 @@ if HAVE_PYTHON3
34da3b1
     Test-auth-basic-netrc.py                        \
34da3b1
     Test-auth-basic-netrc-user-given.py             \
34da3b1
     Test-auth-basic-netrc-pass-given.py             \
34da3b1
+    Test-auth-basic-no-netrc-fail.py                \
34da3b1
     Test-auth-both.py                               \
34da3b1
     Test-auth-digest.py                             \
34da3b1
     Test-auth-no-challenge.py                       \
34da3b1
diff --git a/testenv/Test-auth-basic-no-netrc-fail.py b/testenv/Test-auth-basic-no-netrc-fail.py
34da3b1
new file mode 100755
34da3b1
index 0000000..fad15e9
34da3b1
--- /dev/null
34da3b1
+++ b/testenv/Test-auth-basic-no-netrc-fail.py
34da3b1
@@ -0,0 +1,59 @@
34da3b1
+#!/usr/bin/env python3
34da3b1
+from sys import exit
34da3b1
+from test.http_test import HTTPTest
34da3b1
+from misc.wget_file import WgetFile
34da3b1
+
34da3b1
+"""
34da3b1
+    This test ensures that Wget will not use credentials from .netrc
34da3b1
+    when --no-netrc option is specified and Basic authentication is required
34da3b1
+    and fails.
34da3b1
+"""
34da3b1
+############# File Definitions ###############################################
34da3b1
+File1 = "I am an invisble man."
34da3b1
+
34da3b1
+User = "Sauron"
34da3b1
+Password = "TheEye"
34da3b1
+
34da3b1
+File1_rules = {
34da3b1
+    "Authentication"    : {
34da3b1
+        "Type"          : "Basic",
34da3b1
+        "User"          : User,
34da3b1
+        "Pass"          : Password
34da3b1
+    }
34da3b1
+}
34da3b1
+
34da3b1
+Netrc = "machine 127.0.0.1\n\tlogin {0}\n\tpassword {1}".format(User, Password)
34da3b1
+
34da3b1
+A_File = WgetFile ("File1", File1, rules=File1_rules)
34da3b1
+Netrc_File = WgetFile (".netrc", Netrc)
34da3b1
+
34da3b1
+WGET_OPTIONS = "--no-netrc"
34da3b1
+WGET_URLS = [["File1"]]
34da3b1
+
34da3b1
+Files = [[A_File]]
34da3b1
+LocalFiles = [Netrc_File]
34da3b1
+
34da3b1
+ExpectedReturnCode = 6
34da3b1
+ExpectedDownloadedFiles = [Netrc_File]
34da3b1
+
34da3b1
+################ Pre and Post Test Hooks #####################################
34da3b1
+pre_test = {
34da3b1
+    "ServerFiles"       : Files,
34da3b1
+    "LocalFiles"        : LocalFiles
34da3b1
+}
34da3b1
+test_options = {
34da3b1
+    "WgetCommands"      : WGET_OPTIONS,
34da3b1
+    "Urls"              : WGET_URLS
34da3b1
+}
34da3b1
+post_test = {
34da3b1
+    "ExpectedFiles"     : ExpectedDownloadedFiles,
34da3b1
+    "ExpectedRetcode"   : ExpectedReturnCode
34da3b1
+}
34da3b1
+
34da3b1
+err = HTTPTest (
34da3b1
+                pre_hook=pre_test,
34da3b1
+                test_params=test_options,
34da3b1
+                post_hook=post_test
34da3b1
+).begin ()
34da3b1
+
34da3b1
+exit (err)
34da3b1
-- 
34da3b1
2.7.5
34da3b1