repo: improve wildcard safe.directory tests

This commit is contained in:
Edward Thomson
2026-06-01 23:24:45 +01:00
parent c90dc5284e
commit 2eed889d8a

View File

@@ -669,17 +669,7 @@ void test_repo_open__can_allowlist_dirs_wildcard(void)
git_str_dispose(&path);
}
void test_repo_open__can_allowlist_dirs_wildcard_fail(void)
{
git_str path = GIT_STR_INIT;
cl_git_pass(git_str_printf(
&path, "%s/%s*", clar_sandbox_path(), "empty_standard_repo"));
cl_git_fail_with(GIT_EOWNER, test_safe_path(path.ptr));
git_str_dispose(&path);
}
void test_repo_open__can_allowlist_dirs_wildcard_fail2(void)
void test_repo_open__allowlist_dirs_cannot_have_wildcard_suffix(void)
{
git_str path = GIT_STR_INIT;
@@ -710,17 +700,7 @@ void test_repo_open__can_allowlist_bare_wildcard_gitdir(void)
git_str_dispose(&path);
}
void test_repo_open__can_allowlist_bare_wildcard_gitdir_fail(void)
{
git_str path = GIT_STR_INIT;
cl_git_pass(git_str_printf(&path, "%s*", clar_sandbox_path()));
cl_git_fail_with(GIT_EOWNER, test_bare_safe_path(path.ptr));
git_str_dispose(&path);
}
void test_repo_open__can_allowlist_bare_wildcard_gitdir_fail2(void)
void test_repo_open__allowlist_bare_dirs_cannot_have_wildcard_suffix(void)
{
git_str path = GIT_STR_INIT;
@@ -731,6 +711,16 @@ void test_repo_open__can_allowlist_bare_wildcard_gitdir_fail2(void)
git_str_dispose(&path);
}
void test_repo_open__allowlist_relative_bare_dirs_cannot_have_wildcard_suffix(void)
{
git_str path = GIT_STR_INIT;
cl_git_pass(git_str_printf(&path, "%s*", clar_sandbox_path()));
cl_git_fail_with(GIT_EOWNER, test_bare_safe_path(path.ptr));
git_str_dispose(&path);
}
void test_repo_open__can_wildcard_allowlist_bare_gitdir(void)
{
cl_git_pass(test_bare_safe_path("*"));
@@ -753,6 +743,23 @@ void test_repo_open__can_handle_prefixed_safe_paths(void)
#endif
}
void test_repo_open__can_handle_prefixed_wildcard_safe_paths(void)
{
#ifndef GIT_WIN32
git_str path = GIT_STR_INIT;
/*
* Using "%(prefix)/" becomes "%(prefix)//tmp/foo" - so
* "%(prefix)/" is stripped and means the literal path
* follows.
*/
cl_git_pass(git_str_printf(&path, "%%(prefix)/%s/*",
clar_sandbox_path()));
cl_git_pass(test_safe_path(path.ptr));
git_str_dispose(&path);
#endif
}
void test_repo_open__prefixed_safe_paths_must_have_two_slashes(void)
{
git_str path = GIT_STR_INIT;