Skip to content

Commit

Permalink
Test EXE_INFO no local config even if temp dir is a repo
Browse files Browse the repository at this point in the history
This adds a test that `EXE_INFO` does not return the path to a
local scope configuration file even if no other configuration file
is available and even if the temp dir (from `env::temp_dir()`) is
itself a Git repository.

This test is not quite done, because it is strangely passing, even
though the implementation is not yet hardened to the degree that it
should be able to avoid doing this. Specifically, although Git will
refuse to use (and, in `git config -l`, will omit) the local scope
configuration from a repository that is owned by another user (and
not allowed via `safe.directory`), this test is attempting to cause
a local repository owned by the current user to be used as the
directory `env::temp_dir()` will return.

Once that test bug is fixed, the test should start failing. Then,
when further hardening against unusual temporary directories (and
vulnerable `git` versions) is implemented, it should pass again.
  • Loading branch information
EliahKagan committed Aug 28, 2024
1 parent 65d5151 commit 287f267
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gix-path/src/env/git/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,25 @@ fn exe_info_never_from_local_scope() {
);
}

#[test]
#[serial]
fn exe_info_never_from_local_scope_even_if_temp_is_here() {
let repo = gix_testtools::scripted_fixture_read_only("local_config.sh").expect("script succeeds");
let repo_str = repo.to_str().expect("valid Unicode");
let _cwd = gix_testtools::set_current_dir(&repo).expect("can change to repo dir");
let _env = gix_testtools::Env::new()
.set("GIT_CONFIG_NOSYSTEM", "1")
.set("GIT_CONFIG_GLOBAL", if cfg!(windows) { "NUL" } else { "/dev/null" })
.set("TMPDIR", repo_str) // Mainly for Unix.
.set("TMP", repo_str) // Mainly for Windows.
.set("TEMP", repo_str); // Mainly for Windows, too.
let maybe_path = super::exe_info();
assert!(
maybe_path.is_none(),
"Finds no config path if the config would be local even in a `/tmp`-like dir"
);
}

#[test]
fn first_file_from_config_with_origin() {
let macos =
Expand Down

0 comments on commit 287f267

Please sign in to comment.