Skip to content

Commit fd63401

Browse files
authored
Merge pull request libgit2#4556 from libgit2/ethomson/proxy_pass_in_env
online::clone: validate user:pass in HTTP_PROXY
2 parents 17339cb + e380eae commit fd63401

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)
@@ -741,3 +754,26 @@ void test_online_clone__proxy_credentials_in_url(void)
741754

742755
git_buf_free(&url);
743756
}
757+
758+
void test_online_clone__proxy_credentials_in_environment(void)
759+
{
760+
git_buf url = GIT_BUF_INIT;
761+
762+
if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass)
763+
cl_skip();
764+
765+
_orig_http_proxy = cl_getenv("HTTP_PROXY");
766+
_orig_https_proxy = cl_getenv("HTTPS_PROXY");
767+
_orig_proxies_need_reset = 1;
768+
769+
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
770+
771+
cl_git_pass(git_buf_printf(&url, "http://%s:%s@%s/", _remote_proxy_user, _remote_proxy_pass, _remote_proxy_url));
772+
773+
cl_setenv("HTTP_PROXY", url.ptr);
774+
cl_setenv("HTTPS_PROXY", url.ptr);
775+
776+
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
777+
778+
git_buf_free(&url);
779+
}

0 commit comments

Comments
 (0)