Skip to content

Commit 4d4bf89

Browse files
committed
Test for excessive write permissions on nonexclusive checkout
This expands the `overwriting_files_and_lone_directories_works` test function to check not only that executable permissions have been added at least for the owner, but that write permissions are not added anywhere they would be excessive. The write permissions bits of the current test runner process umask is used to gauge this. This means we are expecting different permissions in different environments. `(umask ...; cargo nextest run ...)` can be used to try it with different umasks if desired, but this should not typically be necessary. Possible under-restrictive umasks could make the test pass even if the underlying bug is not fixed; this is avoided by also testing that the umask is sufficient to facilitate the test. (This is really why the test accesses the umask in the first place: in environments where files would automatically be created with completely unrestricted permissions, the expected behavior of the code under test may be to do that, but running the tests in such an environment is insufficient to check if the bug is fixed.)
1 parent 8e7fb99 commit 4d4bf89

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

gix-worktree-state/tests/state/checkout.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,32 @@ fn overwriting_files_and_lone_directories_works() -> crate::Result {
220220

221221
let meta = std::fs::symlink_metadata(exe)?;
222222
assert!(meta.is_file());
223+
#[cfg(unix)]
223224
if opts.fs.executable_bit {
224-
#[cfg(unix)]
225-
assert_eq!(meta.mode() & 0o700, 0o700, "the executable bit is set where supported");
225+
let mode = meta.mode();
226+
assert_eq!(
227+
mode & 0o100,
228+
0o100,
229+
"executable bit set where supported ({:04o} & {:04o} = {:04o} should be {:04o})",
230+
mode,
231+
0o100,
232+
mode & 0o100,
233+
0o100
234+
);
235+
let umask_write = gix_testtools::umask() & 0o222;
236+
assert_eq!(
237+
mode & umask_write,
238+
0,
239+
"no excessive write bits are set ({:04o} & {:04o} = {:04o} should be {:04o})",
240+
mode,
241+
umask_write,
242+
mode & umask_write,
243+
0
244+
);
245+
assert_ne!(
246+
umask_write, 0,
247+
"test not meaningful unless runner umask restricts some writes"
248+
);
226249
}
227250

228251
assert_eq!(

0 commit comments

Comments
 (0)