Skip to content

Commit e380eae

Browse files
committed
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 parent 17bef3b commit e380eae

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/online/clone.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ static char *_remote_proxy_url = NULL;
2828
static char *_remote_proxy_user = NULL;
2929
static char *_remote_proxy_pass = NULL;
3030

31+
static int _orig_proxies_need_reset = 0;
32+
static char *_orig_http_proxy = NULL;
33+
static char *_orig_https_proxy = NULL;
3134

3235
void test_online_clone__initialize(void)
3336
{
@@ -52,6 +55,8 @@ void test_online_clone__initialize(void)
5255
_remote_proxy_url = cl_getenv("GITTEST_REMOTE_PROXY_URL");
5356
_remote_proxy_user = cl_getenv("GITTEST_REMOTE_PROXY_USER");
5457
_remote_proxy_pass = cl_getenv("GITTEST_REMOTE_PROXY_PASS");
58+
59+
_orig_proxies_need_reset = 0;
5560
}
5661

5762
void test_online_clone__cleanup(void)
@@ -72,6 +77,14 @@ void test_online_clone__cleanup(void)
7277
git__free(_remote_proxy_url);
7378
git__free(_remote_proxy_user);
7479
git__free(_remote_proxy_pass);
80+
81+
if (_orig_proxies_need_reset) {
82+
cl_setenv("HTTP_PROXY", _orig_http_proxy);
83+
cl_setenv("HTTPS_PROXY", _orig_https_proxy);
84+
85+
git__free(_orig_http_proxy);
86+
git__free(_orig_https_proxy);
87+
}
7588
}
7689

7790
void test_online_clone__network_full(void)
@@ -711,3 +724,26 @@ void test_online_clone__proxy_credentials_in_url(void)
711724

712725
git_buf_free(&url);
713726
}
727+
728+
void test_online_clone__proxy_credentials_in_environment(void)
729+
{
730+
git_buf url = GIT_BUF_INIT;
731+
732+
if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass)
733+
cl_skip();
734+
735+
_orig_http_proxy = cl_getenv("HTTP_PROXY");
736+
_orig_https_proxy = cl_getenv("HTTPS_PROXY");
737+
_orig_proxies_need_reset = 1;
738+
739+
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
740+
741+
cl_git_pass(git_buf_printf(&url, "http://%s:%s@%s/", _remote_proxy_user, _remote_proxy_pass, _remote_proxy_url));
742+
743+
cl_setenv("HTTP_PROXY", url.ptr);
744+
cl_setenv("HTTPS_PROXY", url.ptr);
745+
746+
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
747+
748+
git_buf_free(&url);
749+
}

0 commit comments

Comments
 (0)