Skip to content

Commit fea6092

Browse files
committed
tests: online::clone: construct credential-URL from environment
We support two types of passing credentials to the proxy, either via the URL or explicitly by specifying user and password. We test these types by modifying the proxy URL and executing the tests twice, which is in fact unnecessary and requires us to maintain the list of environment variables and test executions across multiple CI infrastructures. To fix the situation, we can just always pass the host, port, user and password to the tests. The tests can then assemble the complete URL either with or without included credentials, allowing us to test both cases in-process.
1 parent 543ec14 commit fea6092

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

appveyor.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ test_script:
5252
$env:GITTEST_REMOTE_USER="libgit2test"
5353
ctest -V -R libgit2_clar-cred_callback
5454
Receive-Job -Job $proxyJob
55-
$env:GITTEST_REMOTE_PROXY_URL = "http://foo:bar@localhost:8080"
56-
ctest -V -R libgit2_clar-proxy_credentials_in_url
57-
$env:GITTEST_REMOTE_PROXY_URL = "http://localhost:8080"
55+
$env:GITTEST_REMOTE_PROXY_URL = "localhost:8080"
5856
$env:GITTEST_REMOTE_PROXY_USER = "foo"
5957
$env:GITTEST_REMOTE_PROXY_PASS = "bar"
60-
ctest -V -R libgit2_clar-proxy_credentials_request
58+
ctest -V -R libgit2_clar-proxy_credentials

script/cibuild.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export GITTEST_REMOTE_USER=$USER
9090
export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa"
9191
export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub"
9292
export GITTEST_REMOTE_SSH_PASSPHRASE=""
93-
93+
# Use the proxy we started at the beginning
94+
export GITTEST_REMOTE_PROXY_URL="localhost:8080"
95+
export GITTEST_REMOTE_PROXY_USER="foo"
96+
export GITTEST_REMOTE_PROXY_PASS="bar"
9497

9598
if [ -e ./libgit2_clar ]; then
9699
./libgit2_clar -sonline::push -sonline::clone::ssh_cert &&
@@ -99,14 +102,7 @@ if [ -e ./libgit2_clar ]; then
99102
./libgit2_clar -sonline::clone::cred_callback || exit $?
100103
fi
101104

102-
# Use the proxy we started at the beginning
103-
export GITTEST_REMOTE_PROXY_URL="http://foo:bar@localhost:8080/"
104-
./libgit2_clar -sonline::clone::proxy_credentials_in_url || exit $?
105-
export GITTEST_REMOTE_PROXY_URL="http://localhost:8080/"
106-
export GITTEST_REMOTE_PROXY_USER="foo"
107-
export GITTEST_REMOTE_PROXY_PASS="bar"
108-
./libgit2_clar -sonline::clone::proxy_credentials_request || exit $?
109-
105+
ctest -V -R libgit2_clar-proxy_credentials || exit $?
110106
fi
111107

112108
kill $(cat "$HOME/sshd/pid")

tests/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,4 @@ ENDIF ()
6161
# Add a test target which runs the cred callback tests, to be
6262
# called after setting the url and user
6363
ADD_TEST(libgit2_clar-cred_callback "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::cred_callback)
64-
ADD_TEST(libgit2_clar-proxy_credentials_in_url "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url)
65-
ADD_TEST(libgit2_clar-proxy_credentials_request "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_request)
64+
ADD_TEST(libgit2_clar-proxy_credentials "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)

tests/online/clone.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,24 +677,34 @@ static int proxy_creds(git_cred **out, const char *url, const char *username, un
677677

678678
void test_online_clone__proxy_credentials_request(void)
679679
{
680+
git_buf url = GIT_BUF_INIT;
681+
680682
if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass)
681683
cl_skip();
682684

685+
cl_git_pass(git_buf_printf(&url, "http://%s/", _remote_proxy_url));
686+
683687
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
684-
g_options.fetch_opts.proxy_opts.url = _remote_proxy_url;
688+
g_options.fetch_opts.proxy_opts.url = url.ptr;
685689
g_options.fetch_opts.proxy_opts.credentials = proxy_creds;
686690
called_proxy_creds = 0;
687691
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
688692
cl_assert(called_proxy_creds);
693+
694+
git_buf_free(&url);
689695
}
690696

691697
void test_online_clone__proxy_credentials_in_url(void)
692698
{
693-
if (!_remote_proxy_url)
699+
git_buf url = GIT_BUF_INIT;
700+
701+
if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass)
694702
cl_skip();
695703

704+
cl_git_pass(git_buf_printf(&url, "http://%s:%s@%s/", _remote_proxy_user, _remote_proxy_pass, _remote_proxy_url));
705+
696706
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
697-
g_options.fetch_opts.proxy_opts.url = _remote_proxy_url;
707+
g_options.fetch_opts.proxy_opts.url = url.ptr;
698708
called_proxy_creds = 0;
699709
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
700710
cl_assert(called_proxy_creds == 0);

0 commit comments

Comments
 (0)