Beispiel #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,
	};

#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.fetch_opts.callbacks.transport = git_transport_ssh_with_paths;
	g_options.fetch_opts.callbacks.credentials = cred_cb;
	g_options.fetch_opts.callbacks.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));
}
Beispiel #2
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));
}
Beispiel #3
0
void test_online_clone__ssh_memory_auth(void)
{
#ifndef GIT_SSH_MEMORY_CREDENTIALS
	clar__skip();
#endif
	if (!_remote_url || !_remote_user || !_remote_ssh_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));
}
Beispiel #4
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));
}
Beispiel #5
0
/* When looking at the short name for a submodule, we need to prevent
 * people from overwriting the `.git` file in the submodule working
 * directory itself.  We don't want to look at the actual repository
 * path, since it will be in the super's repository above us, and
 * typically named with the name of our subrepository.  Consequently,
 * preventing access to the short name of the actual repository path
 * would prevent us from creating files with the same name as the
 * subrepo.  (Eg, a submodule named "libgit2" could not contain a file
 * named "libgit2", which would be unfortunate.)
 */
void test_repo_reservedname__submodule_pointer(void)
{
#ifdef GIT_WIN32
	git_repository *super_repo, *sub_repo;
	git_submodule *sub;
	git_buf *sub_reserved;
	size_t sub_reserved_len;

	if (!cl_sandbox_supports_8dot3())
		clar__skip();

	super_repo = setup_fixture_submod2();

	assert_submodule_exists(super_repo, "sm_unchanged");

	cl_git_pass(git_submodule_lookup(&sub, super_repo, "sm_unchanged"));
	cl_git_pass(git_submodule_open(&sub_repo, sub));

	cl_assert(git_repository__reserved_names(&sub_reserved, &sub_reserved_len, sub_repo, true));

	cl_assert_equal_i(2, sub_reserved_len);
	cl_assert_equal_s(".git", sub_reserved[0].ptr);
	cl_assert_equal_s("GIT~1", sub_reserved[1].ptr);

	git_submodule_free(sub);
	git_repository_free(sub_repo);
#endif
}
Beispiel #6
0
void test_path_win32__8dot3_name(void)
{
#ifdef GIT_WIN32
	char *shortname;

	if (!cl_sandbox_supports_8dot3())
		clar__skip();

	/* Some guaranteed short names */
	cl_assert_equal_s("PROGRA~1", (shortname = git_win32_path_8dot3_name("C:\\Program Files")));
	git__free(shortname);

	cl_assert_equal_s("WINDOWS", (shortname = git_win32_path_8dot3_name("C:\\WINDOWS")));
	git__free(shortname);

	/* Create some predictible short names */
	cl_must_pass(p_mkdir(".foo", 0777));
	cl_assert_equal_s("FOO~1", (shortname = git_win32_path_8dot3_name(".foo")));
	git__free(shortname);

	cl_git_write2file("bar~1", "foobar\n", 7, O_RDWR|O_CREAT, 0666);
	cl_must_pass(p_mkdir(".bar", 0777));
	cl_assert_equal_s("BAR~2", (shortname = git_win32_path_8dot3_name(".bar")));
	git__free(shortname);
#endif
}
Beispiel #7
0
void test_online_clone__ssh_cannot_change_username(void)
{
#ifndef GIT_SSH
	clar__skip();
#endif
	g_options.fetch_opts.callbacks.credentials = cred_foo_bar;

	cl_git_fail(git_clone(&g_repo, "ssh://[email protected]/libgit2/TestGitRepository", "./foo", &g_options));
}
Beispiel #8
0
void test_online_clone__cred_callback_failure_return_code_is_tunnelled(void)
{
	if (!_remote_url || !_remote_user)
		clar__skip();

	g_options.fetch_opts.callbacks.credentials = cred_failure_cb;

	cl_git_fail_with(-172, git_clone(&g_repo, _remote_url, "./foo", &g_options));
}
Beispiel #9
0
/* A tree that contains an entry "git~2", when we have forced the short
 * name for ".git" into "GIT~2".
 */
void test_checkout_nasty__git_custom_shortname(void)
{
#ifdef GIT_WIN32
	if (!cl_sandbox_supports_8dot3())
		clar__skip();

	cl_must_pass(p_rename("nasty/.git", "nasty/_temp"));
	cl_git_write2file("nasty/git~1", "", 0, O_RDWR|O_CREAT, 0666);
	cl_must_pass(p_rename("nasty/_temp", "nasty/.git"));
	test_checkout_fails("refs/heads/git_tilde2", ".git/foobar");
#endif
}
Beispiel #10
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));
}
Beispiel #11
0
void test_online_clone__cred_callback_called_again_on_auth_failure(void)
{
	size_t counter = 0;

	if (!_remote_url || !_remote_user)
		clar__skip();

	g_options.fetch_opts.callbacks.credentials = cred_count_calls_cb;
	g_options.fetch_opts.callbacks.payload = &counter;

	cl_git_fail_with(GIT_EUSER, git_clone(&g_repo, _remote_url, "./foo", &g_options));
	cl_assert_equal_i(3, counter);
}
Beispiel #12
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);
}
Beispiel #13
0
void test_apply_both__index_mode_must_match_workdir(void)
{
	git_diff *diff;

	if (!cl_is_chmod_supported())
		clar__skip();

	/* Set a file in the working directory executable. */
	cl_must_pass(p_chmod("merge-recursive/asparagus.txt", 0755));

	cl_git_pass(git_diff_from_buffer(&diff, DIFF_MODIFY_TWO_FILES,
	    strlen(DIFF_MODIFY_TWO_FILES)));
	cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));

	git_diff_free(diff);
}
Beispiel #14
0
void test_online_clone__ssh_auth_methods(void)
{
	int with_user;

#ifndef GIT_SSH
	clar__skip();
#endif
	g_options.fetch_opts.callbacks.credentials = check_ssh_auth_methods;
	g_options.fetch_opts.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://[email protected]/libgit2/TestGitRepository", "./foo", &g_options));
}
Beispiel #15
0
void test_threads_basic__exit(void)
{
#ifndef GIT_THREADS
	clar__skip();
#else
	git_thread thread;
	void *result;

	/* Ensure that the return value of the threadproc is returned. */
	cl_git_pass(git_thread_create(&thread, return_normally, (void *)424242));
	cl_git_pass(git_thread_join(&thread, &result));
	cl_assert_equal_sz(424242, (size_t)result);

	/* Ensure that the return value of `git_thread_exit` is returned. */
	cl_git_pass(git_thread_create(&thread, return_normally, (void *)232323));
	cl_git_pass(git_thread_join(&thread, &result));
	cl_assert_equal_sz(232323, (size_t)result);
#endif
}
Beispiel #16
0
/* Ensures that custom shortnames are included: creates a GIT~1 so that the
 * .git folder itself will have to be named GIT~2
 */
void test_repo_reservedname__custom_shortname_recognized(void)
{
#ifdef GIT_WIN32
	git_repository *repo;
	git_buf *reserved;
	size_t reserved_len;

	if (!cl_sandbox_supports_8dot3())
		clar__skip();

	repo = cl_git_sandbox_init("nasty");

	cl_must_pass(p_rename("nasty/.git", "nasty/_temp"));
	cl_git_write2file("nasty/git~1", "", 0, O_RDWR|O_CREAT, 0666);
	cl_must_pass(p_rename("nasty/_temp", "nasty/.git"));

	cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, true));

	cl_assert_equal_i(3, reserved_len);
	cl_assert_equal_s(".git", reserved[0].ptr);
	cl_assert_equal_s("GIT~1", reserved[1].ptr);
	cl_assert_equal_s("GIT~2", reserved[2].ptr);
#endif
}
Beispiel #17
0
void test_online_clone__credentials(void)
{
	/* Remote URL environment variable must be set.
	 * User and password are optional.
	 */
	git_cred_userpass_payload user_pass = {
		_remote_user,
		_remote_pass
	};

	if (!_remote_url)
		clar__skip();

	if (cl_is_env_set("GITTEST_REMOTE_DEFAULT")) {
		g_options.fetch_opts.callbacks.credentials = cred_default;
	} else {
		g_options.fetch_opts.callbacks.credentials = git_cred_userpass;
		g_options.fetch_opts.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");
}