@@ -575,6 +575,45 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void)
575575 git_str_dispose (& config_data );
576576}
577577
578+ void test_repo_open__can_wildcard_allowlist_with_problematic_ownership (void )
579+ {
580+ git_repository * repo ;
581+ git_str config_path = GIT_STR_INIT , config_filename = GIT_STR_INIT ;
582+
583+ cl_git_pass (git_libgit2_opts (GIT_OPT_SET_OWNER_VALIDATION , 1 ));
584+
585+ cl_fixture_sandbox ("empty_standard_repo" );
586+ cl_git_pass (cl_rename (
587+ "empty_standard_repo/.gitted" , "empty_standard_repo/.git" ));
588+
589+ git_fs_path__set_owner (GIT_FS_PATH_OWNER_OTHER );
590+ cl_git_fail_with (
591+ GIT_EOWNER , git_repository_open (& repo , "empty_standard_repo" ));
592+
593+ /* Add safe.directory options to the global configuration */
594+ git_str_joinpath (& config_path , clar_sandbox_path (), "__global_config" );
595+ cl_must_pass (p_mkdir (config_path .ptr , 0777 ));
596+ git_libgit2_opts (
597+ GIT_OPT_SET_SEARCH_PATH , GIT_CONFIG_LEVEL_GLOBAL ,
598+ config_path .ptr );
599+
600+ git_str_joinpath (& config_filename , config_path .ptr , ".gitconfig" );
601+
602+ cl_git_rewritefile (config_filename .ptr , "[foo]\n"
603+ "\tbar = Foobar\n"
604+ "\tbaz = Baz!\n"
605+ "[safe]\n"
606+ "\tdirectory = *\n"
607+ "[bar]\n"
608+ "\tfoo = barfoo\n" );
609+
610+ cl_git_pass (git_repository_open (& repo , "empty_standard_repo" ));
611+ git_repository_free (repo );
612+
613+ git_str_dispose (& config_path );
614+ git_str_dispose (& config_filename );
615+ }
616+
578617void test_repo_open__can_allowlist_bare_gitdir (void )
579618{
580619 git_repository * repo ;
@@ -619,6 +658,43 @@ void test_repo_open__can_allowlist_bare_gitdir(void)
619658 git_str_dispose (& config_data );
620659}
621660
661+ void test_repo_open__can_wildcard_allowlist_bare_gitdir (void )
662+ {
663+ git_repository * repo ;
664+ git_str config_path = GIT_STR_INIT , config_filename = GIT_STR_INIT ;
665+
666+ cl_git_pass (git_libgit2_opts (GIT_OPT_SET_OWNER_VALIDATION , 1 ));
667+
668+ cl_fixture_sandbox ("testrepo.git" );
669+
670+ git_fs_path__set_owner (GIT_FS_PATH_OWNER_OTHER );
671+ cl_git_fail_with (
672+ GIT_EOWNER , git_repository_open (& repo , "testrepo.git" ));
673+
674+ /* Add safe.directory options to the global configuration */
675+ git_str_joinpath (& config_path , clar_sandbox_path (), "__global_config" );
676+ cl_must_pass (p_mkdir (config_path .ptr , 0777 ));
677+ git_libgit2_opts (
678+ GIT_OPT_SET_SEARCH_PATH , GIT_CONFIG_LEVEL_GLOBAL ,
679+ config_path .ptr );
680+
681+ git_str_joinpath (& config_filename , config_path .ptr , ".gitconfig" );
682+
683+ cl_git_rewritefile (config_filename .ptr , "[foo]\n"
684+ "\tbar = Foobar\n"
685+ "\tbaz = Baz!\n"
686+ "[safe]\n"
687+ "\tdirectory = *\n"
688+ "[bar]\n"
689+ "\tfoo = barfoo\n" );
690+
691+ cl_git_pass (git_repository_open (& repo , "testrepo.git" ));
692+ git_repository_free (repo );
693+
694+ git_str_dispose (& config_path );
695+ git_str_dispose (& config_filename );
696+ }
697+
622698void test_repo_open__can_reset_safe_directory_list (void )
623699{
624700 git_repository * repo ;
0 commit comments