summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-02-21 15:15:59 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-03-03 16:21:17 +0100
commit66a6e5186ffd12679b8c3ca6980e11efd74d2f00 (patch)
tree82d731d046ac5ca4205b1b66b3b8df21dd7fed60 /test
parent2f5654b7f81ac40d7764de59f0e2f343d9e76a0a (diff)
downloadjustbuild-66a6e5186ffd12679b8c3ca6980e11efd74d2f00.tar.gz
test: Add tests for reading in Git proxy settings
Diffstat (limited to 'test')
-rw-r--r--test/other_tools/git_operations/TARGETS15
-rw-r--r--test/other_tools/git_operations/git_config_proxy.sh328
-rw-r--r--test/other_tools/git_operations/git_config_run.test.cpp20
3 files changed, 360 insertions, 3 deletions
diff --git a/test/other_tools/git_operations/TARGETS b/test/other_tools/git_operations/TARGETS
index 4b4c43ee..8515d680 100644
--- a/test/other_tools/git_operations/TARGETS
+++ b/test/other_tools/git_operations/TARGETS
@@ -56,13 +56,26 @@
}
, "git_config_ssl":
{ "type": ["@", "rules", "shell/test", "script"]
+ , "tainted": ["test"]
, "name": ["git_config_ssl"]
, "test": ["git_config_ssl.sh"]
, "deps": ["git_config_run"]
}
+, "git_config_proxy":
+ { "type": ["@", "rules", "shell/test", "script"]
+ , "tainted": ["test"]
+ , "name": ["git_config_proxy"]
+ , "test": ["git_config_proxy.sh"]
+ , "deps": ["git_config_run"]
+ }
, "TESTS":
{ "type": "install"
, "tainted": ["test"]
- , "deps": ["critical_git_ops_mp", "git_repo_remote", "git_config_ssl"]
+ , "deps":
+ [ "critical_git_ops_mp"
+ , "git_repo_remote"
+ , "git_config_ssl"
+ , "git_config_proxy"
+ ]
}
}
diff --git a/test/other_tools/git_operations/git_config_proxy.sh b/test/other_tools/git_operations/git_config_proxy.sh
new file mode 100644
index 00000000..a162513c
--- /dev/null
+++ b/test/other_tools/git_operations/git_config_proxy.sh
@@ -0,0 +1,328 @@
+#!/bin/sh
+# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -eu
+
+###
+# Run Git config proxy settings retrieval tests for various scenarios
+#
+# Expected Git config (relative) file path: gitconfig
+##
+
+readonly ROOT=`pwd`
+readonly TESTEXEC="${ROOT}/src/git_config_run_test"
+
+# ensure clean env for this type of test
+unset all_proxy
+unset ALL_PROXY
+unset no_proxy
+unset NO_PROXY
+unset http_proxy
+unset https_proxy
+unset HTTPS_PROXY
+
+# Set up the test scenarios to be run in parallel
+k=1 # scenarios counter
+
+echo
+echo "Scenario $k: default (clean env and missing config)"
+k=$((k+1))
+envcmd=""
+url="https://192.0.2.1"
+result=""
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: proxy from all_proxy envariable"
+k=$((k+1))
+envcmd="all_proxy=198.51.100.1:50000"
+url="https://example.com" # scheme must match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: proxy from ALL_PROXY envariable"
+k=$((k+1))
+envcmd="ALL_PROXY=198.51.100.1:50000"
+url="https://example.com" # scheme must match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: lowercase all_proxy envariable priority"
+k=$((k+1))
+envcmd="all_proxy=198.51.100.1:50000 ALL_PROXY=192.0.2.1:50505"
+url="https://example.com" # scheme does not match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: proxy from http_proxy"
+k=$((k+1))
+envcmd="http_proxy=198.51.100.1:50000"
+url="http://example.com" # scheme must match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: proxy from https_proxy"
+k=$((k+1))
+envcmd="https_proxy=198.51.100.1:50000"
+url="https://example.com" # scheme must match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: proxy from HTTPS_PROXY"
+k=$((k+1))
+envcmd="HTTPS_PROXY=198.51.100.1:50000"
+url="https://example.com" # scheme must match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: scheme mismatch in envariable"
+k=$((k+1))
+envcmd="https_proxy=198.51.100.1:50000"
+url="http://example.com" # scheme does not match envariable
+result=""
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: lowercase http_proxy envariable priority"
+k=$((k+1))
+envcmd="https_proxy=198.51.100.1:50000 HTTPS_PROXY=192.0.2.1:50505"
+url="https://example.com" # scheme does not match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: specific and generic envariables priority"
+k=$((k+1))
+envcmd="http_proxy=198.51.100.1:50000 all_proxy=192.0.2.1:50505"
+url="http://example.com" # scheme must match envariable
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: proxy via http.proxy config entry"
+k=$((k+1))
+envcmd=""
+url="https://example.com"
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: proxy via http.<url>.proxy config entry"
+k=$((k+1))
+envcmd=""
+url="https://example.com"
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http "https://example.com"]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: config entry specificity priority"
+k=$((k+1))
+envcmd=""
+url="https://example.com"
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http]
+ proxy = 192.0.2.1:50505
+[http "https://example.com"]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: config entry last best match wins"
+k=$((k+1))
+envcmd=""
+url="https://example.com.org" # url needs two subdomains with same length
+result="http://198.51.100.1:50000/" # proxy default scheme is http
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http "https://example.*.org"]
+ proxy = 192.0.2.1:50505
+[http "https://example.com.*"]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: disable proxy via http.<url>.proxy config entry"
+k=$((k+1))
+envcmd=""
+url="https://example.com"
+result="" # no proxy
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http]
+ proxy = 192.0.2.1:50505
+[http "https://example.com"]
+ proxy =
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: ignored empty http.proxy config entry"
+k=$((k+1))
+envcmd=""
+url="https://example.com"
+result="http://198.51.100.1:50000/" # no proxy
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http]
+ proxy =
+[http "https://example.com"]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: disable proxy with NO_PROXY envariable"
+k=$((k+1))
+envcmd="NO_PROXY=foo,.com"
+url="https://example.com"
+result="" # no proxy
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: disable proxy with no_proxy envariable"
+k=$((k+1))
+envcmd="no_proxy=foo,.example.com"
+url="http://example.com"
+result="" # no proxy
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
+
+echo
+echo "Scenario $k: unmatched no_proxy envariables fallthrough"
+k=$((k+1))
+envcmd="no_proxy=.com:50505 NO_PROXY=*.com" # port must match; wildcard misuse
+url="http://example.com"
+result="http://198.51.100.1:50000/"
+$(
+cd $(mktemp -d)
+cat > gitconfig <<INNER
+[http]
+ proxy = 198.51.100.1:50000
+INNER
+eval "${envcmd} ${TESTEXEC} proxy ${url} ${result}"
+cd ${ROOT}
+)
+echo "PASSED"
diff --git a/test/other_tools/git_operations/git_config_run.test.cpp b/test/other_tools/git_operations/git_config_run.test.cpp
index 9a9af9b9..8ffd744a 100644
--- a/test/other_tools/git_operations/git_config_run.test.cpp
+++ b/test/other_tools/git_operations/git_config_run.test.cpp
@@ -93,8 +93,24 @@ auto main(int argc, char* argv[]) -> int {
}
}
else if (test_type == "proxy") {
- Logger::Log(LogLevel::Error, "Proxy tests not yet implemented");
- return 1;
+ auto proxy_info =
+ GitConfigSettings::GetProxySettings(cfg, test_url, logger);
+ if (not proxy_info) {
+ Logger::Log(LogLevel::Error, "Missing proxy_info");
+ return 1;
+ }
+ // check expected result
+ auto expected_result =
+ (argc >= 4) ? std::make_optional<std::string>(args[3])
+ : std::nullopt;
+ auto actual_result = proxy_info.value();
+ if (actual_result != expected_result) {
+ Logger::Log(LogLevel::Error,
+ "Expected test result {}, but obtained {}",
+ expected_result ? *expected_result : "nullopt",
+ actual_result ? *actual_result : "nullopt");
+ return 1;
+ }
}
else {
Logger::Log(LogLevel::Error,