Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP7:GA
libgit2.25921
0014-repo-add-tests-for-bare-repo-permissions.p...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0014-repo-add-tests-for-bare-repo-permissions.patch of Package libgit2.25921
From 77f95ffafc7dc597b1beaee397b50d1122c681b2 Mon Sep 17 00:00:00 2001 From: Edward Thomson <ethomson@edwardthomson.com> Date: Sat, 2 Jul 2022 15:21:55 -0400 Subject: [PATCH 14/20] repo: add tests for bare repo permissions Ensure that we test opening a bare repository with odd permissions. --- tests/repo/open.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/repo/open.c b/tests/repo/open.c index a2f006c0d..ac5274680 100644 --- a/tests/repo/open.c +++ b/tests/repo/open.c @@ -16,6 +16,7 @@ void test_repo_open__cleanup(void) { cl_git_sandbox_cleanup(); cl_fixture_cleanup("empty_standard_repo"); + cl_fixture_cleanup("testrepo.git"); cl_fixture_cleanup("__global_config"); if (git_path_isdir("alternate")) @@ -493,6 +494,28 @@ void test_repo_open__validates_dir_ownership(void) cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); } +void test_repo_open__validates_bare_repo_ownership(void) +{ + git_repository *repo; + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 1)); + + cl_fixture_sandbox("testrepo.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, "testrepo.git")); + 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, "testrepo.git")); + + /* 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, "testrepo.git")); +} + void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) { git_repository *repo; @@ -538,6 +561,50 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) git_buf_dispose(&config_data); } +void test_repo_open__can_allowlist_bare_gitdir(void) +{ + git_repository *repo; + git_str config_path = GIT_STR_INIT, + config_filename = GIT_STR_INIT, + config_data = 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_MOCK_OWNER_OTHER); + cl_git_fail(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"); + + git_str_printf(&config_data, + "[foo]\n" \ + "\tbar = Foobar\n" \ + "\tbaz = Baz!\n" \ + "[safe]\n" \ + "\tdirectory = /non/existent/path\n" \ + "\tdirectory = /\n" \ + "\tdirectory = c:\\\\temp\n" \ + "\tdirectory = %s/%s\n" \ + "\tdirectory = /tmp\n" \ + "[bar]\n" \ + "\tfoo = barfoo\n", + clar_sandbox_path(), "testrepo.git"); + cl_git_rewritefile(config_filename.ptr, config_data.ptr); + + cl_git_pass(git_repository_open(&repo, "testrepo.git")); + git_repository_free(repo); + + git_str_dispose(&config_path); + git_str_dispose(&config_filename); + git_str_dispose(&config_data); +} + void test_repo_open__can_reset_safe_directory_list(void) { git_repository *repo; -- 2.37.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor