diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2022-04-11 17:07:20 +0100 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-04-11 22:15:47 -0400 |
| commit | 90d2b619575a5c61bde9498b5bf3912eca1a58ad (patch) | |
| tree | b547fbd0221a6491a72170c227fefd2fb8751123 /tests/libgit2 | |
| parent | c0b7f88ed0b55206b147ebba330ae903f7830ca4 (diff) | |
| download | libgit2-90d2b619575a5c61bde9498b5bf3912eca1a58ad.tar.gz | |
repo: test configuration ownership validation
Test that we prevent opening directories that are not owned by
ourselves.
Diffstat (limited to 'tests/libgit2')
| -rw-r--r-- | tests/libgit2/repo/config.c | 1 | ||||
| -rw-r--r-- | tests/libgit2/repo/open.c | 35 |
2 files changed, 35 insertions, 1 deletions
diff --git a/tests/libgit2/repo/config.c b/tests/libgit2/repo/config.c index ee7e43dff..37f6b521d 100644 --- a/tests/libgit2/repo/config.c +++ b/tests/libgit2/repo/config.c @@ -28,7 +28,6 @@ void test_repo_config__cleanup(void) cl_assert(!git_fs_path_isdir("alternate")); cl_fixture_cleanup("empty_standard_repo"); - } void test_repo_config__can_open_global_when_there_is_no_file(void) diff --git a/tests/libgit2/repo/open.c b/tests/libgit2/repo/open.c index f7ed2c373..fa6e36b8f 100644 --- a/tests/libgit2/repo/open.c +++ b/tests/libgit2/repo/open.c @@ -7,9 +7,12 @@ void test_repo_open__cleanup(void) { cl_git_sandbox_cleanup(); + cl_fixture_cleanup("empty_standard_repo"); if (git_fs_path_isdir("alternate")) git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES); + + git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_NONE); } void test_repo_open__bare_empty_repo(void) @@ -453,3 +456,35 @@ void test_repo_open__force_bare(void) git_repository_free(barerepo); } +void test_repo_open__validates_dir_ownership(void) +{ + git_repository *repo; + + cl_fixture_sandbox("empty_standard_repo"); + cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); + + /* When the current user owns the repo config, that's acceptable */ + git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_CURRENT_USER); + cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); + git_repository_free(repo); + + /* When the system user owns the repo config, fail */ + git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_SYSTEM); + cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + + /* When an unknown user owns the repo config, fail */ + git_fs_path__set_owner(GIT_FS_PATH_MOCK_OWNER_OTHER); + cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); +} + +void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) +{ + git_repository *repo; + + 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_MOCK_OWNER_OTHER); + cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + +} |
