|
7 | 7 | void test_repo_open__cleanup(void) |
8 | 8 | { |
9 | 9 | cl_git_sandbox_cleanup(); |
| 10 | + cl_fixture_cleanup("empty_standard_repo"); |
10 | 11 |
|
11 | 12 | if (git_path_isdir("alternate")) |
12 | 13 | git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES); |
| 14 | + |
| 15 | + git_path__set_owner(GIT_PATH_MOCK_OWNER_NONE); |
13 | 16 | } |
14 | 17 |
|
15 | 18 | void test_repo_open__bare_empty_repo(void) |
@@ -453,3 +456,35 @@ void test_repo_open__force_bare(void) |
453 | 456 | git_repository_free(barerepo); |
454 | 457 | } |
455 | 458 |
|
| 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