summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurence McGlashan <laurence.mcglashan@gmail.com>2021-09-16 11:44:04 +0100
committerLaurence McGlashan <laurence.mcglashan@gmail.com>2021-09-16 11:44:04 +0100
commiteb41276fe08eeedd27509f69d9465cfbdd6cb7f7 (patch)
tree5079cd4216d7b7568edf5947be6e8a3199d01c29 /tests
parent7d195b9c3ddffb9f9af94dcabaeb4fc77fafa378 (diff)
downloadlibgit2-eb41276fe08eeedd27509f69d9465cfbdd6cb7f7.tar.gz
Allow proxy options when connecting with a detached remote.
Diffstat (limited to 'tests')
-rw-r--r--tests/remote/httpproxy.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/remote/httpproxy.c b/tests/remote/httpproxy.c
index 097db4cd5..803ef11ad 100644
--- a/tests/remote/httpproxy.c
+++ b/tests/remote/httpproxy.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
-#include "remote.h"
+#include "futils.h"
#include "net.h"
+#include "remote.h"
static git_repository *repo;
static git_net_url url = GIT_NET_URL_INIT;
@@ -105,6 +106,45 @@ void test_remote_httpproxy__config_empty_overrides(void)
assert_config_match("remote.lg2.proxy", "");
}
+void assert_global_config_match(const char *config, const char *expected)
+{
+ git_remote *remote;
+ char *proxy;
+ git_config* cfg;
+
+ if (config) {
+ cl_git_pass(git_config_open_default(&cfg));
+ git_config_set_string(cfg, config, expected);
+ git_config_free(cfg);
+ }
+
+ cl_git_pass(git_remote_create_detached(&remote, "https://github.com/libgit2/libgit2"));
+ cl_git_pass(git_remote__http_proxy(&proxy, remote, &url));
+
+ if (expected)
+ cl_assert_equal_s(proxy, expected);
+ else
+ cl_assert_equal_p(proxy, expected);
+
+ git_remote_free(remote);
+ git__free(proxy);
+}
+
+void test_remote_httpproxy__config_overrides_detached_remote(void)
+{
+ cl_fake_home();
+
+ assert_global_config_match(NULL, NULL);
+ assert_global_config_match("http.proxy", "http://localhost:1/");
+ assert_global_config_match("http.https://github.com.proxy", "http://localhost:2/");
+ assert_global_config_match("http.https://github.com/.proxy", "http://localhost:3/");
+ assert_global_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/");
+ assert_global_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/");
+ assert_global_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/");
+
+ cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
+}
+
void test_remote_httpproxy__env(void)
{
orig_http_proxy = cl_getenv("HTTP_PROXY");