summaryrefslogtreecommitdiff
path: root/tests/network
diff options
context:
space:
mode:
authorErik Aigner <aigner.erik@gmail.com>2019-04-08 15:54:25 +0200
committerEtienne Samson <samson.etienne@gmail.com>2019-05-21 14:11:08 +0200
commit59647e1ad095f80112918971b7bbe05adfaf8c3c (patch)
tree5e2ce79da3ad292505f58a6962047d2baba9f887 /tests/network
parent4aa36ff2c0fe2e7b29220737c757ffff99e00059 (diff)
downloadlibgit2-59647e1ad095f80112918971b7bbe05adfaf8c3c.tar.gz
remote: add callback to resolve URLs before connecting
Since libssh2 doesn't read host configuration from the config file, this callback can be used to hand over URL resolving to the client without touching the SSH implementation itself.
Diffstat (limited to 'tests/network')
-rw-r--r--tests/network/remote/remotes.c85
1 files changed, 77 insertions, 8 deletions
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index 10517957d..a29281d37 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -28,28 +28,97 @@ void test_network_remote_remotes__cleanup(void)
void test_network_remote_remotes__parsing(void)
{
+ git_buf url = GIT_BUF_INIT;
git_remote *_remote2 = NULL;
cl_assert_equal_s(git_remote_name(_remote), "test");
cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
cl_assert(git_remote_pushurl(_remote) == NULL);
- cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_FETCH),
- "git://github.com/libgit2/libgit2");
- cl_assert_equal_s(git_remote__urlfordirection(_remote, GIT_DIRECTION_PUSH),
- "git://github.com/libgit2/libgit2");
+ cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, NULL));
+ cl_assert_equal_s(url.ptr, "git://github.com/libgit2/libgit2");
+
+ cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, NULL));
+ cl_assert_equal_s(url.ptr, "git://github.com/libgit2/libgit2");
cl_git_pass(git_remote_lookup(&_remote2, _repo, "test_with_pushurl"));
cl_assert_equal_s(git_remote_name(_remote2), "test_with_pushurl");
cl_assert_equal_s(git_remote_url(_remote2), "git://github.com/libgit2/fetchlibgit2");
cl_assert_equal_s(git_remote_pushurl(_remote2), "git://github.com/libgit2/pushlibgit2");
- cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_FETCH),
- "git://github.com/libgit2/fetchlibgit2");
- cl_assert_equal_s(git_remote__urlfordirection(_remote2, GIT_DIRECTION_PUSH),
- "git://github.com/libgit2/pushlibgit2");
+ cl_git_pass(git_remote__urlfordirection(&url, _remote2, GIT_DIRECTION_FETCH, NULL));
+ cl_assert_equal_s(url.ptr, "git://github.com/libgit2/fetchlibgit2");
+
+ cl_git_pass(git_remote__urlfordirection(&url, _remote2, GIT_DIRECTION_PUSH, NULL));
+ cl_assert_equal_s(url.ptr, "git://github.com/libgit2/pushlibgit2");
git_remote_free(_remote2);
+ git_buf_dispose(&url);
+}
+
+static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
+{
+ cl_assert(strcmp(url, "git://github.com/libgit2/libgit2") == 0);
+ cl_assert(strcmp(payload, "payload") == 0);
+ cl_assert(url_resolved->size == 0);
+
+ if (direction == GIT_DIRECTION_PUSH)
+ git_buf_sets(url_resolved, "pushresolve");
+ if (direction == GIT_DIRECTION_FETCH)
+ git_buf_sets(url_resolved, "fetchresolve");
+
+ return GIT_OK;
+}
+
+void test_network_remote_remotes__urlresolve(void)
+{
+ git_buf url = GIT_BUF_INIT;
+
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ callbacks.resolve_url = urlresolve_callback;
+ callbacks.payload = "payload";
+
+ cl_assert_equal_s(git_remote_name(_remote), "test");
+ cl_assert_equal_s(git_remote_url(_remote), "git://github.com/libgit2/libgit2");
+ cl_assert(git_remote_pushurl(_remote) == NULL);
+
+ cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
+ cl_assert_equal_s(url.ptr, "fetchresolve");
+
+ cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
+ cl_assert_equal_s(url.ptr, "pushresolve");
+
+ git_buf_dispose(&url);
+}
+
+static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
+{
+ GIT_UNUSED(url_resolved);
+ GIT_UNUSED(url);
+ GIT_UNUSED(direction);
+ GIT_UNUSED(payload);
+ return GIT_PASSTHROUGH;
+}
+
+void test_network_remote_remotes__urlresolve_passthrough(void)
+{
+ git_buf url = GIT_BUF_INIT;
+ const char *orig_url = "git://github.com/libgit2/libgit2";
+
+ git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
+ callbacks.resolve_url = urlresolve_passthrough_callback;
+
+ cl_assert_equal_s(git_remote_name(_remote), "test");
+ cl_assert_equal_s(git_remote_url(_remote), orig_url);
+ cl_assert(git_remote_pushurl(_remote) == NULL);
+
+ cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_FETCH, &callbacks));
+ cl_assert_equal_s(url.ptr, orig_url);
+
+ cl_git_pass(git_remote__urlfordirection(&url, _remote, GIT_DIRECTION_PUSH, &callbacks));
+ cl_assert_equal_s(url.ptr, orig_url);
+
+ git_buf_dispose(&url);
}
void test_network_remote_remotes__pushurl(void)