diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-09-15 23:51:42 +0400 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-09-16 19:01:32 +0400 |
commit | bf8756d6a2c42dc77b8a2de814a12e2ceb4487fd (patch) | |
tree | 4c14f928310dd422be2d259f3b1f3aaec956d778 /tests/online | |
parent | 41698f22f683d3452ef83de3b3e82f5cb178b0b3 (diff) |
ssh: add test for host key
Test that the certificate check callback gets the right fingerprint from
the host we're connecting to.
Diffstat (limited to 'tests/online')
-rw-r--r-- | tests/online/clone.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/online/clone.c b/tests/online/clone.c index cebe3b2ba..2e51364f6 100644 --- a/tests/online/clone.c +++ b/tests/online/clone.c @@ -464,6 +464,38 @@ void test_online_clone__ssh_cannot_change_username(void) cl_git_fail(git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options)); } +int ssh_certificate_check(git_cert_t type, void *data, size_t len, int valid, void *payload) +{ + git_cert_hostkey *key; + git_oid expected = {{0}}, actual = {{0}}; + const char *expected_str; + + GIT_UNUSED(len); + GIT_UNUSED(valid); + GIT_UNUSED(payload); + + expected_str = cl_getenv("GITTEST_REMOTE_SSH_FINGERPRINT"); + if (!expected_str) + cl_skip(); + + cl_git_pass(git_oid_fromstr(&expected, expected_str)); + cl_assert_equal_i(GIT_CERT_HOSTKEY_LIBSSH2, type); + + key = (git_cert_hostkey *) data; + git_oid_fromraw(&actual, key->hash); + + cl_assert(git_oid_equal(&expected, &actual)); + + return GIT_EUSER; +} + +void test_online_clone__ssh_cert(void) +{ + g_options.remote_callbacks.certificate_check = ssh_certificate_check; + + cl_git_fail_with(GIT_EUSER, git_clone(&g_repo, "ssh://localhost/foo", "./foo", &g_options)); +} + void test_online_clone__url_with_no_path_returns_EINVALIDSPEC(void) { cl_git_fail_with(git_clone(&g_repo, "http://github.com", "./foo", &g_options), |