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 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/appveyor.yml b/appveyor.yml
index e0c7b9b..1c4c1af 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -52,9 +52,7 @@ test_script:
$env:GITTEST_REMOTE_USER="libgit2test"
ctest -V -R libgit2_clar-cred_callback
Receive-Job -Job $proxyJob
- $env:GITTEST_REMOTE_PROXY_URL = "http://foo:bar@localhost:8080"
- ctest -V -R libgit2_clar-proxy_credentials_in_url
- $env:GITTEST_REMOTE_PROXY_URL = "http://localhost:8080"
+ $env:GITTEST_REMOTE_PROXY_URL = "localhost:8080"
$env:GITTEST_REMOTE_PROXY_USER = "foo"
$env:GITTEST_REMOTE_PROXY_PASS = "bar"
- ctest -V -R libgit2_clar-proxy_credentials_request
+ ctest -V -R libgit2_clar-proxy_credentials
diff --git a/script/cibuild.sh b/script/cibuild.sh
index 1c28baa..c06de19 100755
--- a/script/cibuild.sh
+++ b/script/cibuild.sh
@@ -90,7 +90,10 @@ export GITTEST_REMOTE_USER=$USER
export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa"
export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub"
export GITTEST_REMOTE_SSH_PASSPHRASE=""
-
+# Use the proxy we started at the beginning
+export GITTEST_REMOTE_PROXY_URL="localhost:8080"
+export GITTEST_REMOTE_PROXY_USER="foo"
+export GITTEST_REMOTE_PROXY_PASS="bar"
if [ -e ./libgit2_clar ]; then
./libgit2_clar -sonline::push -sonline::clone::ssh_cert &&
@@ -99,14 +102,7 @@ if [ -e ./libgit2_clar ]; then
./libgit2_clar -sonline::clone::cred_callback || exit $?
fi
- # Use the proxy we started at the beginning
- export GITTEST_REMOTE_PROXY_URL="http://foo:bar@localhost:8080/"
- ./libgit2_clar -sonline::clone::proxy_credentials_in_url || exit $?
- export GITTEST_REMOTE_PROXY_URL="http://localhost:8080/"
- export GITTEST_REMOTE_PROXY_USER="foo"
- export GITTEST_REMOTE_PROXY_PASS="bar"
- ./libgit2_clar -sonline::clone::proxy_credentials_request || exit $?
-
+ ctest -V -R libgit2_clar-proxy_credentials || exit $?
fi
kill $(cat "$HOME/sshd/pid")
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4606fe9..2d18391 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -61,5 +61,4 @@ ENDIF ()
# Add a test target which runs the cred callback tests, to be
# called after setting the url and user
ADD_TEST(libgit2_clar-cred_callback "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::cred_callback)
-ADD_TEST(libgit2_clar-proxy_credentials_in_url "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url)
-ADD_TEST(libgit2_clar-proxy_credentials_request "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_request)
+ADD_TEST(libgit2_clar-proxy_credentials "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 5eda73f..b670986 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -677,24 +677,34 @@ static int proxy_creds(git_cred **out, const char *url, const char *username, un
void test_online_clone__proxy_credentials_request(void)
{
+ git_buf url = GIT_BUF_INIT;
+
if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
+ cl_git_pass(git_buf_printf(&url, "http://%s/", _remote_proxy_url));
+
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
- g_options.fetch_opts.proxy_opts.url = _remote_proxy_url;
+ g_options.fetch_opts.proxy_opts.url = url.ptr;
g_options.fetch_opts.proxy_opts.credentials = proxy_creds;
called_proxy_creds = 0;
cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options));
cl_assert(called_proxy_creds);
+
+ git_buf_free(&url);
}
void test_online_clone__proxy_credentials_in_url(void)
{
- if (!_remote_proxy_url)
+ git_buf url = GIT_BUF_INIT;
+
+ if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass)
cl_skip();
+ cl_git_pass(git_buf_printf(&url, "http://%s:%s@%s/", _remote_proxy_user, _remote_proxy_pass, _remote_proxy_url));
+
g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED;
- g_options.fetch_opts.proxy_opts.url = _remote_proxy_url;
+ g_options.fetch_opts.proxy_opts.url = url.ptr;
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);