online::clone: validate user:pass in HTTP_PROXY Validate using the http://user:pass@host/ format in HTTP_PROXY and HTTPS_PROXY environment variables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/tests/online/clone.c b/tests/online/clone.c
index af6b305..0dc48f5 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);
+}