Blame SOURCES/wget-1.19.5-no_proxy-tests.patch

4207c6
From dea0f6272889adcff846144fff5714c076067b16 Mon Sep 17 00:00:00 2001
4207c6
From: Tomas Hozza <thozza@redhat.com>
4207c6
Date: Thu, 7 Nov 2019 12:46:15 +0100
4207c6
Subject: [PATCH 1/3] testenv: HTTPTest.begin() should return exit value
4207c6
4207c6
* testenv/test/http_test.py: Ensure that HTTPTest.begin() always retuns a value
4207c6
4207c6
Previously the HTTPTest.begin() method always returned None. However this is not consistent with the begin() implementation of the parent class (BaseTest). This change ensures that HTTPTest.begin() returns a value.
4207c6
4207c6
Signed-off-by: Tomas Hozza <thozza@redhat.com>
4207c6
---
4207c6
 testenv/test/http_test.py | 2 +-
4207c6
 1 file changed, 1 insertion(+), 1 deletion(-)
4207c6
4207c6
diff --git a/testenv/test/http_test.py b/testenv/test/http_test.py
4207c6
index fef0c2ef..462ac6e7 100644
4207c6
--- a/testenv/test/http_test.py
4207c6
+++ b/testenv/test/http_test.py
4207c6
@@ -42,7 +42,7 @@ class HTTPTest(BaseTest):
4207c6
                 print_green("Test Passed.")
4207c6
             else:
4207c6
                 self.tests_passed = False
4207c6
-            super(HTTPTest, self).begin()
4207c6
+            return super(HTTPTest, self).begin()
4207c6
 
4207c6
     def instantiate_server_by(self, protocol):
4207c6
         server = {HTTP: HTTPd,
4207c6
-- 
4207c6
2.21.0
4207c6
4207c6
4207c6
From 7fba12cf25ff7cc352f0f5df7d91670df7035823 Mon Sep 17 00:00:00 2001
4207c6
From: Tomas Hozza <thozza@redhat.com>
4207c6
Date: Thu, 7 Nov 2019 13:01:44 +0100
4207c6
Subject: [PATCH 2/3] testenv: Allow definition of environment variables for
4207c6
 wget execuion
4207c6
4207c6
* testenv/README: Added description for new EnvironmentVariable hook
4207c6
* testenv/conf/environment_variable.py: Added implementation of EnvironmentVariable hook
4207c6
* testenv/test/base_test.py: Modified exec_wget() to enable use of EnvironmentVariable hook
4207c6
4207c6
Added new test hook called EnvironmentVariables, for defining environment variables when wget is executed in tests. This is handy for testing environment variables, which are accepted by wget.
4207c6
4207c6
Signed-off-by: Tomas Hozza <thozza@redhat.com>
4207c6
---
4207c6
 testenv/README                        |  3 +++
4207c6
 testenv/conf/environment_variables.py | 14 ++++++++++++++
4207c6
 testenv/test/base_test.py             |  6 +++++-
4207c6
 3 files changed, 22 insertions(+), 1 deletion(-)
4207c6
 create mode 100644 testenv/conf/environment_variables.py
4207c6
4207c6
diff --git a/testenv/README b/testenv/README
4207c6
index aca8cdda..d4fabddd 100644
4207c6
--- a/testenv/README
4207c6
+++ b/testenv/README
4207c6
@@ -224,6 +224,9 @@ executed. The currently supported options are:
4207c6
     file. While all Download URL's are passed to Urls, a notable exception is
4207c6
     when in-url authentication is used. In such a case, the URL is specified in
4207c6
     the WgetCommands string.
4207c6
+    * EnvironmentVariables: A dictionary with key-value items, which will be
4207c6
+    defined as environment variables during the execution of wget command in
4207c6
+    test.
4207c6
 
4207c6
 Post-Test Hooks:
4207c6
 ================================================================================
4207c6
diff --git a/testenv/conf/environment_variables.py b/testenv/conf/environment_variables.py
4207c6
new file mode 100644
4207c6
index 00000000..323c051c
4207c6
--- /dev/null
4207c6
+++ b/testenv/conf/environment_variables.py
4207c6
@@ -0,0 +1,14 @@
4207c6
+from conf import hook
4207c6
+
4207c6
+""" Test Option: EnvironmentVariables
4207c6
+This hook is used to define environment variables used for execution of wget
4207c6
+command in test."""
4207c6
+
4207c6
+
4207c6
+@hook(alias='EnvironmentVariables')
4207c6
+class URLs:
4207c6
+    def __init__(self, envs):
4207c6
+        self.envs = envs
4207c6
+
4207c6
+    def __call__(self, test_obj):
4207c6
+        test_obj.envs.update(**self.envs)
4207c6
diff --git a/testenv/test/base_test.py b/testenv/test/base_test.py
4207c6
index dbf4678f..04a6f748 100644
4207c6
--- a/testenv/test/base_test.py
4207c6
+++ b/testenv/test/base_test.py
4207c6
@@ -51,6 +51,7 @@ class BaseTest:
4207c6
 
4207c6
         self.wget_options = ''
4207c6
         self.urls = []
4207c6
+        self.envs = dict()
4207c6
 
4207c6
         self.tests_passed = True
4207c6
         self.ready = False
4207c6
@@ -97,12 +98,15 @@ class BaseTest:
4207c6
         cmd_line = self.gen_cmd_line()
4207c6
         params = shlex.split(cmd_line)
4207c6
         print(params)
4207c6
+        envs = {"HOME": os.getcwd()}
4207c6
+        envs.update(**self.envs)
4207c6
+        print(envs)
4207c6
 
4207c6
         if os.getenv("SERVER_WAIT"):
4207c6
             time.sleep(float(os.getenv("SERVER_WAIT")))
4207c6
 
4207c6
         try:
4207c6
-            ret_code = call(params, env={"HOME": os.getcwd()})
4207c6
+            ret_code = call(params, env=envs)
4207c6
         except FileNotFoundError:
4207c6
             raise TestFailed("The Wget Executable does not exist at the "
4207c6
                              "expected path.")
4207c6
-- 
4207c6
2.21.0
4207c6
4207c6
4207c6
From 0d50becc19ba07f34157b2842ca97675cc95fc1a Mon Sep 17 00:00:00 2001
4207c6
From: Tomas Hozza <thozza@redhat.com>
4207c6
Date: Thu, 7 Nov 2019 13:11:30 +0100
4207c6
Subject: [PATCH 3/3] testenv: Add test for handling of no_proxy environment
4207c6
 variable
4207c6
4207c6
* testenv/Test-no_proxy-env.py: Added new test for no_proxy env
4207c6
4207c6
Added new test with 5 cases, which are testing various combinations of no_proxy environment variable definition and requested URLs
4207c6
4207c6
Signed-off-by: Tomas Hozza <thozza@redhat.com>
4207c6
---
4207c6
 testenv/Test-no_proxy-env.py | 142 +++++++++++++++++++++++++++++++++++
4207c6
 1 file changed, 142 insertions(+)
4207c6
 create mode 100755 testenv/Test-no_proxy-env.py
4207c6
4207c6
diff --git a/testenv/Test-no_proxy-env.py b/testenv/Test-no_proxy-env.py
4207c6
new file mode 100755
4207c6
index 00000000..ea7f38c4
4207c6
--- /dev/null
4207c6
+++ b/testenv/Test-no_proxy-env.py
4207c6
@@ -0,0 +1,142 @@
4207c6
+#!/usr/bin/env python3
4207c6
+from sys import exit
4207c6
+from test.http_test import HTTPTest
4207c6
+from test.base_test import HTTP
4207c6
+from misc.wget_file import WgetFile
4207c6
+
4207c6
+"""
4207c6
+    This test ensures, that domains with and without leftmost dot defined in
4207c6
+    no_proxy environment variable are accepted by wget. The idea is to use
4207c6
+    non-existing proxy server address and detect whether files are downloaded
4207c6
+    when proxy settings are omitted based on no_proxy environment variable
4207c6
+    value.
4207c6
+
4207c6
+    current wget's behavior:
4207c6
+    - "no_proxy=.mit.edu"
4207c6
+      - will match the domain and subdomains e.g. "www.mit.edu" or "www.subdomain.mit.edu" (Case #4)
4207c6
+      - will NOT match the host "mit.edu" (Case #3)
4207c6
+    - "no_proxy=mit.edu"
4207c6
+      - will match the domain and subdomains e.g. "www.mit.edu" or "www.subdomain.mit.edu" (Case #2)
4207c6
+      - will match the host "mit.edu" (Case #1)
4207c6
+    - downside: can not match only the host
4207c6
+"""
4207c6
+# File Definitions
4207c6
+File1 = "Would you like some Tea?"
4207c6
+File2 = "With lemon or cream?"
4207c6
+
4207c6
+A_File = WgetFile ("File1", File1)
4207c6
+B_File = WgetFile ("File2", File2)
4207c6
+
4207c6
+WGET_URLS = [["File1", "File2"]]
4207c6
+WGET_ENVS = {
4207c6
+    "http_proxy": "nonexisting.localhost:8080",
4207c6
+    "no_proxy": "working1.localhost,.working2.localhost"
4207c6
+}
4207c6
+
4207c6
+Servers = [HTTP]
4207c6
+Files = [[A_File, B_File]]
4207c6
+
4207c6
+ExpectedReturnCodeWorking = 0
4207c6
+ExpectedReturnCodeNotWorking = 4  # network error (non-existing proxy address)
4207c6
+
4207c6
+ExpectedDownloadedFilesWorking = [A_File, B_File]
4207c6
+
4207c6
+# Pre and Post Test Hooks
4207c6
+test_options = {
4207c6
+    "Urls"                : WGET_URLS,
4207c6
+    "EnvironmentVariables": WGET_ENVS
4207c6
+}
4207c6
+post_test_working = {
4207c6
+    "ExpectedFiles"     : ExpectedDownloadedFilesWorking,
4207c6
+    "ExpectedRetcode"   : ExpectedReturnCodeWorking
4207c6
+}
4207c6
+post_test_not_working = {
4207c6
+    "ExpectedRetcode"   : ExpectedReturnCodeNotWorking
4207c6
+}
4207c6
+
4207c6
+# Case #1:
4207c6
+# - Requested domain matches exactly the domain definition in no_proxy.
4207c6
+# - Domain definition in no_proxy is NOT dot-prefixed
4207c6
+# Expected result: proxy settings don't apply and files are downloaded.
4207c6
+pre_case_1 = {
4207c6
+    "ServerFiles"       : Files,
4207c6
+    "Domains"           : ["working1.localhost"]
4207c6
+}
4207c6
+
4207c6
+err_case_1 = HTTPTest (
4207c6
+    pre_hook=pre_case_1,
4207c6
+    test_params=test_options,
4207c6
+    post_hook=post_test_working,
4207c6
+    protocols=Servers
4207c6
+).begin ()
4207c6
+
4207c6
+# Case #2:
4207c6
+# - Requested domain is sub-domain of a domain definition in no_proxy.
4207c6
+# - Domain definition in no_proxy is NOT dot-prefixed
4207c6
+# Expected result: proxy settings don't apply and files are downloaded.
4207c6
+pre_case_2 = {
4207c6
+    "ServerFiles"       : Files,
4207c6
+    "Domains"           : ["www.working1.localhost"]
4207c6
+}
4207c6
+
4207c6
+err_case_2 = HTTPTest (
4207c6
+    pre_hook=pre_case_2,
4207c6
+    test_params=test_options,
4207c6
+    post_hook=post_test_working,
4207c6
+    protocols=Servers
4207c6
+).begin ()
4207c6
+
4207c6
+# Case #3:
4207c6
+# - Requested domain matches exactly the domain definition in no_proxy,
4207c6
+#   except for the leftmost dot (".") in no_proxy domain definition.
4207c6
+# - Domain definition in no_proxy IS dot-prefixed
4207c6
+# Expected result: proxy settings apply and files are downloaded. This is
4207c6
+#                  due to the mismatch in leftmost dot.
4207c6
+# NOTE: This is inconsistent with curl's behavior, but has less drawbacks.
4207c6
+pre_case_3 = {
4207c6
+    "ServerFiles"       : Files,
4207c6
+    "Domains"           : ["working2.localhost"]
4207c6
+}
4207c6
+
4207c6
+err_case_3 = HTTPTest (
4207c6
+    pre_hook=pre_case_3,
4207c6
+    test_params=test_options,
4207c6
+    post_hook=post_test_not_working,
4207c6
+    protocols=Servers
4207c6
+).begin ()
4207c6
+
4207c6
+# Case #4:
4207c6
+# - Requested domain is sub-domain of a domain definition in no_proxy.
4207c6
+# - Domain definition in no_proxy IS dot-prefixed
4207c6
+# Expected result: proxy settings don't apply and files are downloaded.
4207c6
+pre_case_4 = {
4207c6
+    "ServerFiles"       : Files,
4207c6
+    "Domains"           : ["www.working2.localhost"]
4207c6
+}
4207c6
+
4207c6
+err_case_4 = HTTPTest (
4207c6
+    pre_hook=pre_case_4,
4207c6
+    test_params=test_options,
4207c6
+    post_hook=post_test_working,
4207c6
+    protocols=Servers
4207c6
+).begin ()
4207c6
+
4207c6
+# Case #5
4207c6
+# - Requested domain does not match a domain definition in no_proxy.
4207c6
+# - Requested domain is NOT sub-domain of a domain definition in no_proxy.
4207c6
+# Expected result: proxy settings apply and files are NOT downloaded due to
4207c6
+#                  network error when using proxy with non-existing URL.
4207c6
+pre_case_5 = {
4207c6
+    "ServerFiles"       : Files,
4207c6
+    "Domains"           : ["www.example.localhost"]
4207c6
+}
4207c6
+
4207c6
+err_case_5 = HTTPTest (
4207c6
+    pre_hook=pre_case_5,
4207c6
+    test_params=test_options,
4207c6
+    post_hook=post_test_not_working,
4207c6
+    protocols=Servers
4207c6
+).begin ()
4207c6
+
4207c6
+# Combine error codes from all test cases
4207c6
+exit (max(err_case_1, err_case_2, err_case_3, err_case_4, err_case_5))
4207c6
-- 
4207c6
2.21.0
4207c6