Exemplo n.º 1
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");

#ifndef GIT_SSH
    clar__skip();
#endif
    if (!remote_url || !remote_user || strncmp(remote_url, "ssh://", 5) != 0)
        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));
}
Exemplo n.º 2
0
static int ssh_memory_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_path = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY");
	const char *privkey_path = 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_USERNAME)
		return git_cred_username_new(cred, remote_user);

	if (allowed_types & GIT_CREDTYPE_SSH_KEY)
	{
		char *pubkey = read_key_file(pubkey_path);
		char *privkey = read_key_file(privkey_path);

		int ret = git_cred_ssh_key_memory_new(cred, remote_user, pubkey, privkey, passphrase);

		if (privkey)
			free(privkey);
		if (pubkey)
			free(pubkey);
		return ret;
	}

	giterr_set(GITERR_NET, "unexpected cred type");
	return -1;
}
Exemplo n.º 3
0
void test_online_clone__credentials(void)
{
    /* Remote URL environment variable must be set.
     * User and password are optional.
     */
    const char *remote_url = cl_getenv("GITTEST_REMOTE_URL");
    git_cred_userpass_payload user_pass = {
        cl_getenv("GITTEST_REMOTE_USER"),
        cl_getenv("GITTEST_REMOTE_PASS")
    };

    if (!remote_url) return;

    if (cl_getenv("GITTEST_REMOTE_DEFAULT")) {
        g_options.remote_callbacks.credentials = cred_default;
    } else {
        g_options.remote_callbacks.credentials = git_cred_userpass;
        g_options.remote_callbacks.payload = &user_pass;
    }

    cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
    git_repository_free(g_repo);
    g_repo = NULL;
    cl_fixture_cleanup("./foo");
}
Exemplo n.º 4
0
Arquivo: env.c Projeto: ileitch/meanie
void test_core_env__initialize(void)
{
#ifdef GIT_WIN32
	env_userprofile = cl_getenv("USERPROFILE");
	env_programfiles = cl_getenv("PROGRAMFILES");
#else
	env_home = cl_getenv("HOME");
#endif
}
Exemplo n.º 5
0
void test_online_clone__cred_callback_failure_return_code_is_tunnelled(void)
{
    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_callbacks.credentials = cred_failure_cb;

    cl_git_fail_with(-172, git_clone(&g_repo, remote_url, "./foo", &g_options));
}
Exemplo n.º 6
0
Arquivo: env.c Projeto: ileitch/meanie
void test_core_env__0(void)
{
	static char *home_values[] = {
		"fake_home",
		"fáke_hõme", /* all in latin-1 supplement */
		"fĀke_Ĥome", /* latin extended */
		"fακε_hοmέ",  /* having fun with greek */
		"faงe_นome", /* now I have no idea, but thai characters */
		"f\xe1\x9cx80ke_\xe1\x9c\x91ome", /* tagalog characters */
		"\xe1\xb8\x9fẢke_hoṁe", /* latin extended additional */
		"\xf0\x9f\x98\x98\xf0\x9f\x98\x82", /* emoticons */
		NULL
	};
	git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
	char **val;
	char *check;

	for (val = home_values; *val != NULL; val++) {

		if (p_mkdir(*val, 0777) == 0) {
			/* if we can't make the directory, let's just assume
			 * we are on a filesystem that doesn't support the
			 * characters in question and skip this test...
			 */
			cl_git_pass(git_path_prettify(&path, *val, NULL));

#ifdef GIT_WIN32
			cl_git_pass(cl_setenv("USERPROFILE", path.ptr));

			/* do a quick check that it was set correctly */
			check = cl_getenv("USERPROFILE");
			cl_assert_equal_s(path.ptr, check);
			git__free(check);
#else
			cl_git_pass(cl_setenv("HOME", path.ptr));

			/* do a quick check that it was set correctly */
			check = cl_getenv("HOME");
			cl_assert_equal_s(path.ptr, check);
#endif

			cl_git_pass(git_buf_puts(&path, "/testfile"));
			cl_git_mkfile(path.ptr, "find me");

			cl_git_pass(git_futils_find_global_file(&found, "testfile"));
		}
	}

	git_buf_free(&path);
	git_buf_free(&found);
}
Exemplo n.º 7
0
void test_online_clone__cred_callback_called_again_on_auth_failure(void)
{
    const char *remote_url = cl_getenv("GITTEST_REMOTE_URL");
    const char *remote_user = cl_getenv("GITTEST_REMOTE_USER");
    size_t counter = 0;

    if (!remote_url || !remote_user)
        clar__skip();

    g_options.remote_callbacks.credentials = cred_count_calls_cb;
    g_options.remote_callbacks.payload = &counter;

    cl_git_fail_with(GIT_EUSER, git_clone(&g_repo, remote_url, "./foo", &g_options));
    cl_assert_equal_i(3, counter);
}
Exemplo n.º 8
0
int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *payload)
{
    git_cert_hostkey *key;
    git_oid expected = {{0}}, actual = {{0}};
    const char *expected_str;

    GIT_UNUSED(valid);
    GIT_UNUSED(payload);

    expected_str = cl_getenv("GITTEST_REMOTE_SSH_FINGERPRINT");
    cl_assert(expected_str);

    cl_git_pass(git_oid_fromstrp(&expected, expected_str));
    cl_assert_equal_i(GIT_CERT_HOSTKEY_LIBSSH2, cert->cert_type);
    key = (git_cert_hostkey *) cert;

    /*
     * We need to figure out how long our input was to check for
     * the type. Here we abuse the fact that both hashes fit into
     * our git_oid type.
     */
    if (strlen(expected_str) == 32 && key->type & GIT_CERT_SSH_MD5) {
        memcpy(&actual.id, key->hash_md5, 16);
    } else 	if (strlen(expected_str) == 40 && key->type & GIT_CERT_SSH_SHA1) {
        memcpy(&actual, key->hash_sha1, 20);
    } else {
        cl_fail("Cannot find a usable SSH hash");
    }

    cl_assert(!memcmp(&expected, &actual, 20));

    cl_assert_equal_s("localhost", host);

    return GIT_EUSER;
}
Exemplo n.º 9
0
void test_online_clone__ssh_memory_auth(void)
{
	const char *remote_url = cl_getenv("GITTEST_REMOTE_URL");
	const char *remote_user = cl_getenv("GITTEST_REMOTE_USER");
	const char *privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY");

#ifndef GIT_SSH_MEMORY_CREDENTIALS
	clar__skip();
#endif
	if (!remote_url || !remote_user || !privkey || strncmp(remote_url, "ssh://", 5) != 0)
		clar__skip();

	g_options.fetch_opts.callbacks.credentials = ssh_memory_cred_cb;

	cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
}
Exemplo n.º 10
0
bool cl_is_env_set(const char *name)
{
	char *env = cl_getenv(name);
	bool result = (env != NULL);
	git__free(env);
	return result;
}
Exemplo n.º 11
0
void test_refs_revparse__initialize(void)
{
	char *tz = cl_getenv("TZ");
	if (tz)
		strcpy(g_orig_tz, tz);
	cl_setenv("TZ", "UTC");
	g_repo = cl_git_sandbox_init("testrepo.git");
}
Exemplo n.º 12
0
void test_online_clone__ssh_cert(void)
{
    g_options.remote_callbacks.certificate_check = ssh_certificate_check;

    if (!cl_getenv("GITTEST_REMOTE_SSH_FINGERPRINT"))
        cl_skip();

    cl_git_fail_with(GIT_EUSER, git_clone(&g_repo, "ssh://localhost/foo", "./foo", &g_options));
}
Exemplo n.º 13
0
void test_online_clone__initialize(void)
{
	git_checkout_options dummy_opts = GIT_CHECKOUT_OPTIONS_INIT;
	git_fetch_options dummy_fetch = GIT_FETCH_OPTIONS_INIT;

	g_repo = NULL;

	memset(&g_options, 0, sizeof(git_clone_options));
	g_options.version = GIT_CLONE_OPTIONS_VERSION;
	g_options.checkout_opts = dummy_opts;
	g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
	g_options.fetch_opts = dummy_fetch;

	_remote_url = cl_getenv("GITTEST_REMOTE_URL");
	_remote_user = cl_getenv("GITTEST_REMOTE_USER");
	_remote_pass = cl_getenv("GITTEST_REMOTE_PASS");
	_remote_ssh_pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY");
	_remote_ssh_privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY");
	_remote_ssh_passphrase = cl_getenv("GITTEST_REMOTE_SSH_PASSPHRASE");
	_remote_ssh_fingerprint = cl_getenv("GITTEST_REMOTE_SSH_FINGERPRINT");
	_remote_proxy_url = cl_getenv("GITTEST_REMOTE_PROXY_URL");
	_remote_proxy_user = cl_getenv("GITTEST_REMOTE_PROXY_USER");
	_remote_proxy_pass = cl_getenv("GITTEST_REMOTE_PROXY_PASS");
}