Skip to content

Commit caee92e

Browse files
committed
repo: test configuration ownership validation
Test that we prevent opening directories that are not owned by ourselves.
1 parent e4eabb0 commit caee92e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

tests/repo/config.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void test_repo_config__cleanup(void)
2828
cl_assert(!git_path_isdir("alternate"));
2929

3030
cl_fixture_cleanup("empty_standard_repo");
31-
3231
}
3332

3433
void test_repo_config__can_open_global_when_there_is_no_file(void)

tests/repo/open.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
void test_repo_open__cleanup(void)
88
{
99
cl_git_sandbox_cleanup();
10+
cl_fixture_cleanup("empty_standard_repo");
1011

1112
if (git_path_isdir("alternate"))
1213
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES);
14+
15+
git_path__set_owner(GIT_PATH_MOCK_OWNER_NONE);
1316
}
1417

1518
void test_repo_open__bare_empty_repo(void)
@@ -453,3 +456,35 @@ void test_repo_open__force_bare(void)
453456
git_repository_free(barerepo);
454457
}
455458

459+
void test_repo_open__validates_dir_ownership(void)
460+
{
461+
git_repository *repo;
462+
463+
cl_fixture_sandbox("empty_standard_repo");
464+
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
465+
466+
/* When the current user owns the repo config, that's acceptable */
467+
git_path__set_owner(GIT_PATH_MOCK_OWNER_CURRENT_USER);
468+
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
469+
git_repository_free(repo);
470+
471+
/* When the system user owns the repo config, fail */
472+
git_path__set_owner(GIT_PATH_MOCK_OWNER_SYSTEM);
473+
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
474+
475+
/* When an unknown user owns the repo config, fail */
476+
git_path__set_owner(GIT_PATH_MOCK_OWNER_OTHER);
477+
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
478+
}
479+
480+
void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
481+
{
482+
git_repository *repo;
483+
484+
cl_fixture_sandbox("empty_standard_repo");
485+
cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git"));
486+
487+
git_path__set_owner(GIT_PATH_MOCK_OWNER_OTHER);
488+
cl_git_fail(git_repository_open(&repo, "empty_standard_repo"));
489+
490+
}

0 commit comments

Comments
 (0)