Commit 00c62ab0 by Edward Thomson

http: test proxies in url and host:port format

Test proxies specified by both host:port format in configuration
options, environment variables, and `http.proxy` configuration.
parent 7a901fb4
......@@ -43,7 +43,6 @@ static char *_github_ssh_privkey = NULL;
static char *_github_ssh_passphrase = NULL;
static char *_github_ssh_remotehostkey = NULL;
static int _orig_proxies_need_reset = 0;
static char *_orig_http_proxy = NULL;
static char *_orig_https_proxy = NULL;
static char *_orig_no_proxy = NULL;
......@@ -99,10 +98,12 @@ void test_online_clone__initialize(void)
_github_ssh_passphrase = cl_getenv("GITTEST_GITHUB_SSH_PASSPHRASE");
_github_ssh_remotehostkey = cl_getenv("GITTEST_GITHUB_SSH_REMOTE_HOSTKEY");
_orig_http_proxy = cl_getenv("HTTP_PROXY");
_orig_https_proxy = cl_getenv("HTTPS_PROXY");
_orig_no_proxy = cl_getenv("NO_PROXY");
if (_remote_expectcontinue)
git_libgit2_opts(GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, 1);
_orig_proxies_need_reset = 0;
}
void test_online_clone__cleanup(void)
......@@ -140,15 +141,13 @@ void test_online_clone__cleanup(void)
git__free(_github_ssh_passphrase);
git__free(_github_ssh_remotehostkey);
if (_orig_proxies_need_reset) {
cl_setenv("HTTP_PROXY", _orig_http_proxy);
cl_setenv("HTTPS_PROXY", _orig_https_proxy);
cl_setenv("NO_PROXY", _orig_no_proxy);
cl_setenv("HTTP_PROXY", _orig_http_proxy);
cl_setenv("HTTPS_PROXY", _orig_https_proxy);
cl_setenv("NO_PROXY", _orig_no_proxy);
git__free(_orig_http_proxy);
git__free(_orig_https_proxy);
git__free(_orig_no_proxy);
}
git__free(_orig_http_proxy);
git__free(_orig_https_proxy);
git__free(_orig_no_proxy);
git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, NULL, NULL);
git_libgit2_opts(GIT_OPT_SET_SERVER_TIMEOUT, 0);
......@@ -968,6 +967,79 @@ static int proxy_cert_cb(git_cert *cert, int valid, const char *host, void *payl
return valid ? 0 : GIT_ECERTIFICATE;
}
void test_online_clone__proxy_http_host_port_in_opts(void)
{
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
if (_remote_proxy_scheme && strcmp(_remote_proxy_scheme, "http") != 0)
cl_skip();
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
g_options.fetch_opts.proxy_opts.url = _remote_proxy_host;
g_options.fetch_opts.proxy_opts.credentials = proxy_cred_cb;
called_proxy_creds = 0;
cl_git_pass(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 1);
}
void test_online_clone__proxy_http_host_port_in_env(void)
{
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
if (_remote_proxy_scheme && strcmp(_remote_proxy_scheme, "http") != 0)
cl_skip();
cl_setenv("HTTP_PROXY", _remote_proxy_host);
cl_setenv("HTTPS_PROXY", _remote_proxy_host);
cl_setenv("NO_PROXY", NULL);
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
g_options.fetch_opts.proxy_opts.credentials = proxy_cred_cb;
called_proxy_creds = 0;
cl_git_pass(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 1);
}
static int repository_create_with_proxy(
git_repository **out,
const char *path,
int bare,
void *payload)
{
git_repository *repo;
git_config *config;
char *value = (char *)payload;
cl_git_pass(git_repository_init(&repo, path, bare));
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "http.proxy", value));
git_config_free(config);
*out = repo;
return 0;
}
void test_online_clone__proxy_http_host_port_in_config(void)
{
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
g_options.fetch_opts.proxy_opts.credentials = proxy_cred_cb;
g_options.repository_cb = repository_create_with_proxy;
g_options.repository_cb_payload = _remote_proxy_host;
called_proxy_creds = 0;
cl_git_pass(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 1);
}
void test_online_clone__proxy_invalid_url(void)
{
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
......@@ -1003,7 +1075,7 @@ void test_online_clone__proxy_credentials_request(void)
git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_url(void)
void test_online_clone__proxy_credentials_in_well_formed_url(void)
{
git_str url = GIT_STR_INIT;
......@@ -1024,17 +1096,35 @@ void test_online_clone__proxy_credentials_in_url(void)
git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_environment(void)
void test_online_clone__proxy_credentials_in_host_port_format(void)
{
git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
_orig_http_proxy = cl_getenv("HTTP_PROXY");
_orig_https_proxy = cl_getenv("HTTPS_PROXY");
_orig_no_proxy = cl_getenv("NO_PROXY");
_orig_proxies_need_reset = 1;
if (_remote_proxy_scheme && strcmp(_remote_proxy_scheme, "http") != 0)
cl_skip();
cl_git_pass(git_str_printf(&url, "%s:%s@%s",
_remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
g_options.fetch_opts.proxy_opts.url = url.ptr;
g_options.fetch_opts.proxy_opts.certificate_check = proxy_cert_cb;
called_proxy_creds = 0;
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds == 0);
git_str_dispose(&url);
}
void test_online_clone__proxy_credentials_in_environment(void)
{
git_str url = GIT_STR_INIT;
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_AUTO;
g_options.fetch_opts.proxy_opts.certificate_check = proxy_cert_cb;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment