Skip to content

Commit adaa037

Browse files
committed
remote: test honoring configuration option
Test that we honor `http.followRedirects` when set to initial or false.
1 parent fda59a7 commit adaa037

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

tests/online/fetch.c

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ static char *_remote_proxy_scheme = NULL;
77
static char *_remote_proxy_host = NULL;
88
static char *_remote_proxy_user = NULL;
99
static char *_remote_proxy_pass = NULL;
10+
static char *_remote_redirect_initial = NULL;
11+
static char *_remote_redirect_subsequent = NULL;
1012

1113
void test_online_fetch__initialize(void)
1214
{
1315
cl_git_pass(git_repository_init(&_repo, "./fetch", 0));
1416

15-
_remote_proxy_scheme = cl_getenv("GITTEST_REMOTE_PROXY_SCHEME");
16-
_remote_proxy_host = cl_getenv("GITTEST_REMOTE_PROXY_HOST");
17-
_remote_proxy_user = cl_getenv("GITTEST_REMOTE_PROXY_USER");
18-
_remote_proxy_pass = cl_getenv("GITTEST_REMOTE_PROXY_PASS");
17+
_remote_proxy_scheme = cl_getenv("GITTEST_REMOTE_PROXY_SCHEME");
18+
_remote_proxy_host = cl_getenv("GITTEST_REMOTE_PROXY_HOST");
19+
_remote_proxy_user = cl_getenv("GITTEST_REMOTE_PROXY_USER");
20+
_remote_proxy_pass = cl_getenv("GITTEST_REMOTE_PROXY_PASS");
21+
_remote_redirect_initial = cl_getenv("GITTEST_REMOTE_REDIRECT_INITIAL");
22+
_remote_redirect_subsequent = cl_getenv("GITTEST_REMOTE_REDIRECT_SUBSEQUENT");
1923
}
2024

2125
void test_online_fetch__cleanup(void)
@@ -24,11 +28,14 @@ void test_online_fetch__cleanup(void)
2428
_repo = NULL;
2529

2630
cl_fixture_cleanup("./fetch");
27-
28-
git__free(_remote_proxy_scheme);
29-
git__free(_remote_proxy_host);
30-
git__free(_remote_proxy_user);
31-
git__free(_remote_proxy_pass);
31+
cl_fixture_cleanup("./redirected");
32+
33+
git__free(_remote_proxy_scheme);
34+
git__free(_remote_proxy_host);
35+
git__free(_remote_proxy_user);
36+
git__free(_remote_proxy_pass);
37+
git__free(_remote_redirect_initial);
38+
git__free(_remote_redirect_subsequent);
3239
}
3340

3441
static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
@@ -247,3 +254,44 @@ void test_online_fetch__proxy(void)
247254
git_remote_free(remote);
248255
git_str_dispose(&url);
249256
}
257+
258+
static int do_redirected_fetch(const char *url, const char *name, const char *config)
259+
{
260+
git_repository *repo;
261+
git_remote *remote;
262+
int error;
263+
264+
cl_git_pass(git_repository_init(&repo, "./redirected", 0));
265+
cl_fixture_cleanup(name);
266+
267+
if (config)
268+
cl_repo_set_string(repo, "http.followRedirects", config);
269+
270+
cl_git_pass(git_remote_create(&remote, repo, name, url));
271+
error = git_remote_fetch(remote, NULL, NULL, NULL);
272+
273+
git_remote_free(remote);
274+
git_repository_free(repo);
275+
276+
cl_fixture_cleanup("./redirected");
277+
278+
return error;
279+
}
280+
281+
void test_online_fetch__redirect_config(void)
282+
{
283+
if (!_remote_redirect_initial || !_remote_redirect_subsequent)
284+
cl_skip();
285+
286+
/* config defaults */
287+
cl_git_pass(do_redirected_fetch(_remote_redirect_initial, "initial", NULL));
288+
cl_git_fail(do_redirected_fetch(_remote_redirect_subsequent, "subsequent", NULL));
289+
290+
/* redirect=initial */
291+
cl_git_pass(do_redirected_fetch(_remote_redirect_initial, "initial", "initial"));
292+
cl_git_fail(do_redirected_fetch(_remote_redirect_subsequent, "subsequent", "initial"));
293+
294+
/* redirect=false */
295+
cl_git_fail(do_redirected_fetch(_remote_redirect_initial, "initial", "false"));
296+
cl_git_fail(do_redirected_fetch(_remote_redirect_subsequent, "subsequent", "false"));
297+
}

0 commit comments

Comments
 (0)