mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-21 12:24:58 +00:00
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.
This commit is contained in:
parent
ccb85c8fa1
commit
e26b08d32c
@ -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)
|
||||
{
|
||||
g_options.remote_callbacks.credentials = check_ssh_auth_methods;
|
||||
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));
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user