summaryrefslogtreecommitdiff
path: root/tests/online
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-07-04 10:00:39 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-07-07 14:51:51 +0200
commitd4256ed554fa64f762d53cb2a64663e5095d3eb5 (patch)
tree45a5b926a5a04f346a0feb10242012a2677e8d62 /tests/online
parent9b87998c97fedcf0c22cef28bb0839ecd68c1efd (diff)
downloadlibgit2-d4256ed554fa64f762d53cb2a64663e5095d3eb5.tar.gz
ssh: provide a factory function for setting ssh pathscmn/ssh-factory-for-paths
git allows you to set which paths to use for the git server programs when connecting over ssh; and we want to provide something similar. We do this by providing a factory function which can be set as the remote's transport callback which will set the given paths upon creation.
Diffstat (limited to 'tests/online')
-rw-r--r--tests/online/clone.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 2e2e97675..b672a099a 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -288,8 +288,73 @@ void test_online_clone__can_cancel(void)
git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), 4321);
}
+static int cred_cb(git_cred **cred, const char *url, const char *user_from_url,
+ unsigned int allowed_types, void *payload)
+{
+ const char *remote_user = cl_getenv("GITTEST_REMOTE_USER");
+ const char *pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY");
+ const char *privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY");
+ const char *passphrase = cl_getenv("GITTEST_REMOTE_SSH_PASSPHRASE");
+
+ GIT_UNUSED(url); GIT_UNUSED(user_from_url); GIT_UNUSED(payload);
+
+ if (allowed_types & GIT_CREDTYPE_SSH_KEY)
+ return git_cred_ssh_key_new(cred, remote_user, pubkey, privkey, passphrase);
+
+ giterr_set(GITERR_NET, "unexpected cred type");
+ return -1;
+}
+
+static int custom_remote_ssh_with_paths(
+ git_remote **out,
+ git_repository *repo,
+ const char *name,
+ const char *url,
+ void *payload)
+{
+ int error;
+
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+
+ if ((error = git_remote_create(out, repo, name, url)) < 0)
+ return error;
+
+ if ((error = git_remote_set_transport(*out, git_transport_ssh_with_paths, payload)) < 0)
+ return error;
+ callbacks.credentials = cred_cb;
+ git_remote_set_callbacks(*out, &callbacks);
+ return 0;
+}
+
+void test_online_clone__ssh_with_paths(void)
+{
+ char *bad_paths[] = {
+ "/bin/yes",
+ "/bin/false",
+ };
+ char *good_paths[] = {
+ "/usr/bin/git-upload-pack",
+ "/usr/bin/git-receive-pack",
+ };
+ git_strarray arr = {
+ bad_paths,
+ 2,
+ };
+
+ const char *remote_url = cl_getenv("GITTEST_REMOTE_URL");
+ const char *remote_user = cl_getenv("GITTEST_REMOTE_USER");
+
+ if (!remote_url || !remote_user)
+ clar__skip();
+
+ g_options.remote_cb = custom_remote_ssh_with_paths;
+ g_options.remote_cb_payload = &arr;
+ cl_git_fail(git_clone(&g_repo, remote_url, "./foo", &g_options));
+ arr.strings = good_paths;
+ cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
+}