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

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