summaryrefslogtreecommitdiff
path: root/tests/libgit2/repo/open.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libgit2/repo/open.c')
-rw-r--r--tests/libgit2/repo/open.c95
1 files changed, 87 insertions, 8 deletions
diff --git a/tests/libgit2/repo/open.c b/tests/libgit2/repo/open.c
index 634ba59d2..3d1a0620b 100644
--- a/tests/libgit2/repo/open.c
+++ b/tests/libgit2/repo/open.c
@@ -410,6 +410,7 @@ void test_repo_open__no_config(void)
git_str_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
+ cl_assert(git_repository_oid_type(repo) == GIT_OID_SHA1);
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "test.set", "42"));
@@ -433,11 +434,13 @@ void test_repo_open__force_bare(void)
cl_git_pass(git_repository_open(&barerepo, "alternate"));
cl_assert(!git_repository_is_bare(barerepo));
+ cl_assert(git_repository_oid_type(barerepo) == GIT_OID_SHA1);
git_repository_free(barerepo);
cl_git_pass(git_repository_open_bare(
&barerepo, "empty_standard_repo/.git"));
cl_assert(git_repository_is_bare(barerepo));
+ cl_assert(git_repository_oid_type(barerepo) == GIT_OID_SHA1);
git_repository_free(barerepo);
cl_git_fail(git_repository_open_bare(&barerepo, "alternate/.git"));
@@ -487,7 +490,7 @@ void test_repo_open__validates_dir_ownership(void)
/* When the system user owns the repo config, fail */
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
- cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
#ifdef GIT_WIN32
/* When the user is an administrator, succeed on Windows. */
@@ -498,7 +501,7 @@ void test_repo_open__validates_dir_ownership(void)
/* When an unknown user owns the repo config, fail */
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
- cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
}
void test_repo_open__validates_bare_repo_ownership(void)
@@ -516,7 +519,7 @@ void test_repo_open__validates_bare_repo_ownership(void)
/* When the system user owns the repo config, fail */
git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR);
- cl_git_fail(git_repository_open(&repo, "testrepo.git"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git"));
#ifdef GIT_WIN32
/* When the user is an administrator, succeed on Windows. */
@@ -527,7 +530,7 @@ void test_repo_open__validates_bare_repo_ownership(void)
/* When an unknown user owns the repo config, fail */
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
- cl_git_fail(git_repository_open(&repo, "testrepo.git"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git"));
}
void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
@@ -543,7 +546,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
- cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
/* Add safe.directory options to the global configuration */
git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
@@ -575,6 +578,45 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
git_str_dispose(&config_data);
}
+void test_repo_open__can_wildcard_allowlist_with_problematic_ownership(void)
+{
+ git_repository *repo;
+ git_str config_path = GIT_STR_INIT, config_filename = GIT_STR_INIT;
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 1));
+
+ cl_fixture_sandbox("empty_standard_repo");
+ cl_git_pass(cl_rename(
+ "empty_standard_repo/.gitted", "empty_standard_repo/.git"));
+
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
+ cl_git_fail_with(
+ GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
+
+ /* Add safe.directory options to the global configuration */
+ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
+ cl_must_pass(p_mkdir(config_path.ptr, 0777));
+ git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
+ config_path.ptr);
+
+ git_str_joinpath(&config_filename, config_path.ptr, ".gitconfig");
+
+ cl_git_rewritefile(config_filename.ptr, "[foo]\n"
+ "\tbar = Foobar\n"
+ "\tbaz = Baz!\n"
+ "[safe]\n"
+ "\tdirectory = *\n"
+ "[bar]\n"
+ "\tfoo = barfoo\n");
+
+ cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
+ git_repository_free(repo);
+
+ git_str_dispose(&config_path);
+ git_str_dispose(&config_filename);
+}
+
void test_repo_open__can_allowlist_bare_gitdir(void)
{
git_repository *repo;
@@ -587,7 +629,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void)
cl_fixture_sandbox("testrepo.git");
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
- cl_git_fail(git_repository_open(&repo, "testrepo.git"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git"));
/* Add safe.directory options to the global configuration */
git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
@@ -619,6 +661,43 @@ void test_repo_open__can_allowlist_bare_gitdir(void)
git_str_dispose(&config_data);
}
+void test_repo_open__can_wildcard_allowlist_bare_gitdir(void)
+{
+ git_repository *repo;
+ git_str config_path = GIT_STR_INIT, config_filename = GIT_STR_INIT;
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 1));
+
+ cl_fixture_sandbox("testrepo.git");
+
+ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
+ cl_git_fail_with(
+ GIT_EOWNER, git_repository_open(&repo, "testrepo.git"));
+
+ /* Add safe.directory options to the global configuration */
+ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
+ cl_must_pass(p_mkdir(config_path.ptr, 0777));
+ git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
+ config_path.ptr);
+
+ git_str_joinpath(&config_filename, config_path.ptr, ".gitconfig");
+
+ cl_git_rewritefile(config_filename.ptr, "[foo]\n"
+ "\tbar = Foobar\n"
+ "\tbaz = Baz!\n"
+ "[safe]\n"
+ "\tdirectory = *\n"
+ "[bar]\n"
+ "\tfoo = barfoo\n");
+
+ cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+ git_repository_free(repo);
+
+ git_str_dispose(&config_path);
+ git_str_dispose(&config_filename);
+}
+
void test_repo_open__can_reset_safe_directory_list(void)
{
git_repository *repo;
@@ -632,7 +711,7 @@ void test_repo_open__can_reset_safe_directory_list(void)
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER);
- cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
/* Add safe.directory options to the global configuration */
git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config");
@@ -656,7 +735,7 @@ void test_repo_open__can_reset_safe_directory_list(void)
clar_sandbox_path(), "empty_standard_repo");
cl_git_rewritefile(config_filename.ptr, config_data.ptr);
- cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
+ cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo"));
/* The blank resets tmp and allows subsequent declarations to succeed */