ssh: adjust clone and push test credentials to the split user+pass method For urls where we do not specify a username, we must handle the case where the ssh transport asks us for the username. Test also that switching username fails.
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
diff --git a/tests/online/clone.c b/tests/online/clone.c
index de838e6..ffa414a 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -351,17 +351,45 @@ void test_online_clone__can_cancel(void)
static int check_ssh_auth_methods(git_cred **cred, const char *url, const char *username_from_url,
unsigned int allowed_types, void *data)
{
+ int *with_user = (int *) data;
GIT_UNUSED(cred); GIT_UNUSED(url); GIT_UNUSED(username_from_url); GIT_UNUSED(data);
- cl_assert_equal_i(GIT_CREDTYPE_SSH_KEY | GIT_CREDTYPE_SSH_CUSTOM, allowed_types);
+ if (!*with_user)
+ cl_assert_equal_i(GIT_CREDTYPE_USERNAME, allowed_types);
+ else
+ cl_assert(!(allowed_types & GIT_CREDTYPE_USERNAME));
return GIT_EUSER;
}
void test_online_clone__ssh_auth_methods(void)
{
+ int with_user;
+
g_options.remote_callbacks.credentials = check_ssh_auth_methods;
+ g_options.remote_callbacks.payload = &with_user;
+ with_user = 0;
cl_git_fail_with(GIT_EUSER,
git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options));
+
+ with_user = 1;
+ cl_git_fail_with(GIT_EUSER,
+ git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options));
+}
+
+static int cred_foo_bar(git_cred **cred, const char *url, const char *username_from_url,
+ unsigned int allowed_types, void *data)
+
+{
+ GIT_UNUSED(url); GIT_UNUSED(username_from_url); GIT_UNUSED(allowed_types); GIT_UNUSED(data);
+
+ return git_cred_userpass_plaintext_new(cred, "foo", "bar");
+}
+
+void test_online_clone__ssh_cannot_change_username(void)
+{
+ g_options.remote_callbacks.credentials = cred_foo_bar;
+
+ cl_git_fail(git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options));
}
diff --git a/tests/online/push.c b/tests/online/push.c
index 6da27bb..50419ef 100644
--- a/tests/online/push.c
+++ b/tests/online/push.c
@@ -50,6 +50,15 @@ static int cred_acquire_cb(
GIT_UNUSED(user_from_url);
GIT_UNUSED(payload);
+ if (GIT_CREDTYPE_USERNAME & allowed_types) {
+ if (!_remote_user) {
+ printf("GITTEST_REMOTE_USER must be set\n");
+ return -1;
+ }
+
+ return git_cred_username_new(cred, _remote_user);
+ }
+
if (GIT_CREDTYPE_DEFAULT & allowed_types) {
if (!_remote_default) {
printf("GITTEST_REMOTE_DEFAULT must be set to use NTLM/Negotiate credentials\n");