summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-02-28 16:10:53 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2018-02-28 16:42:08 +0000
commite380eae059ed13a693d46ff3b98f23903818dd09 (patch)
treef13f35082e2c5e2da09976fb4d2a9ed7db09ff1f
parent17bef3b8363e1b6c12e8506b21715b00f82c3a82 (diff)
downloadlibgit2-ethomson/proxy_pass_in_env.tar.gz
online::clone: validate user:pass in HTTP_PROXYethomson/proxy_pass_in_env
Validate using the http://user:pass@host/ format in HTTP_PROXY and HTTPS_PROXY environment variables.
-rw-r--r--tests/online/clone.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/online/clone.c b/tests/online/clone.c
index af6b30580..0dc48f5cf 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -28,6 +28,9 @@ static char *_remote_proxy_url = NULL;
static char *_remote_proxy_user = NULL;
static char *_remote_proxy_pass = NULL;
+static int _orig_proxies_need_reset = 0;
+static char *_orig_http_proxy = NULL;
+static char *_orig_https_proxy = NULL;
void test_online_clone__initialize(void)
{
@@ -52,6 +55,8 @@ void test_online_clone__initialize(void)
_remote_proxy_url = cl_getenv("GITTEST_REMOTE_PROXY_URL");
_remote_proxy_user = cl_getenv("GITTEST_REMOTE_PROXY_USER");
_remote_proxy_pass = cl_getenv("GITTEST_REMOTE_PROXY_PASS");
+
+ _orig_proxies_need_reset = 0;
}
void test_online_clone__cleanup(void)
@@ -72,6 +77,14 @@ void test_online_clone__cleanup(void)
git__free(_remote_proxy_url);
git__free(_remote_proxy_user);
git__free(_remote_proxy_pass);
+
+ if (_orig_proxies_need_reset) {
+ cl_setenv("HTTP_PROXY", _orig_http_proxy);
+ cl_setenv("HTTPS_PROXY", _orig_https_proxy);
+
+ git__free(_orig_http_proxy);
+ git__free(_orig_https_proxy);
+ }
}
void test_online_clone__network_full(void)
@@ -711,3 +724,26 @@ void test_online_clone__proxy_credentials_in_url(void)
git_buf_free(&url);
}
+
+void test_online_clone__proxy_credentials_in_environment(void)
+{
+ git_buf url = GIT_BUF_INIT;
+
+ if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass)
+ cl_skip();
+
+ _orig_http_proxy = cl_getenv("HTTP_PROXY");
+ _orig_https_proxy = cl_getenv("HTTPS_PROXY");
+ _orig_proxies_need_reset = 1;
+
+ g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
+
+ cl_git_pass(git_buf_printf(&url, "http://%s:%s@%s/", _remote_proxy_user, _remote_proxy_pass, _remote_proxy_url));
+
+ cl_setenv("HTTP_PROXY", url.ptr);
+ cl_setenv("HTTPS_PROXY", url.ptr);
+
+ cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
+
+ git_buf_free(&url);
+}