Add test for fetch proxy memleak
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/fetch.c b/tests/online/fetch.c
index f939a16..67dfd69 100644
--- a/tests/online/fetch.c
+++ b/tests/online/fetch.c
@@ -3,9 +3,19 @@
static git_repository *_repo;
static int counter;
+static char *_remote_proxy_scheme = NULL;
+static char *_remote_proxy_host = NULL;
+static char *_remote_proxy_user = NULL;
+static char *_remote_proxy_pass = NULL;
+
void test_online_fetch__initialize(void)
{
cl_git_pass(git_repository_init(&_repo, "./fetch", 0));
+
+ _remote_proxy_scheme = cl_getenv("GITTEST_REMOTE_PROXY_SCHEME");
+ _remote_proxy_host = cl_getenv("GITTEST_REMOTE_PROXY_HOST");
+ _remote_proxy_user = cl_getenv("GITTEST_REMOTE_PROXY_USER");
+ _remote_proxy_pass = cl_getenv("GITTEST_REMOTE_PROXY_PASS");
}
void test_online_fetch__cleanup(void)
@@ -14,6 +24,11 @@ void test_online_fetch__cleanup(void)
_repo = NULL;
cl_fixture_cleanup("./fetch");
+
+ git__free(_remote_proxy_scheme);
+ git__free(_remote_proxy_host);
+ git__free(_remote_proxy_user);
+ git__free(_remote_proxy_pass);
}
static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
@@ -207,3 +222,28 @@ void test_online_fetch__twice(void)
git_remote_free(remote);
}
+
+void test_online_fetch__proxy(void)
+{
+ git_remote *remote;
+ git_buf url = GIT_BUF_INIT;
+ git_fetch_options fetch_opts;
+
+ if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass)
+ cl_skip();
+
+ cl_git_pass(git_buf_printf(&url, "%s://%s:%s@%s/",
+ _remote_proxy_scheme ? _remote_proxy_scheme : "http",
+ _remote_proxy_user, _remote_proxy_pass, _remote_proxy_host));
+
+ cl_git_pass(git_fetch_options_init(&fetch_opts, GIT_FETCH_OPTIONS_VERSION));
+ fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
+ fetch_opts.proxy_opts.url = url.ptr;
+
+ cl_git_pass(git_remote_create(&remote, _repo, "test", "https://github.com/libgit2/TestGitRepository.git"));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH, NULL, &fetch_opts.proxy_opts, NULL));
+ cl_git_pass(git_remote_fetch(remote, NULL, &fetch_opts, NULL));
+
+ git_remote_free(remote);
+ git_buf_dispose(&url);
+}