Skip to content

Commit df85eb2

Browse files
committed
chore: add test for setgid bit inheritance in mkdir -p
1 parent cbbff30 commit df85eb2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/by-util/test_mkdir.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,32 @@ fn test_mkdir_parent_mode_with_explicit_mode() {
908908
);
909909
}
910910

911+
/// Test that nested directories inherit the setgid bit with mkdir -p.
912+
#[test]
913+
#[cfg(not(windows))]
914+
fn test_mkdir_parent_inherits_setgid() {
915+
let (at, mut ucmd) = at_and_ucmd!();
916+
917+
at.mkdir("parent");
918+
at.set_mode("parent", 0o2755);
919+
920+
ucmd.arg("-p")
921+
.arg("parent/child/grandchild")
922+
.succeeds()
923+
.no_stderr()
924+
.no_stdout();
925+
926+
// All descendants should inherit the setgid bit (0o2000)
927+
let parent_mode = at.metadata("parent").permissions().mode() as mode_t;
928+
assert_eq!(parent_mode & 0o2000, 0o2000);
929+
930+
let child_mode = at.metadata("parent/child").permissions().mode() as mode_t;
931+
assert_eq!(child_mode & 0o2000, 0o2000);
932+
933+
let grandchild_mode = at.metadata("parent/child/grandchild").permissions().mode() as mode_t;
934+
assert_eq!(grandchild_mode & 0o2000, 0o2000);
935+
}
936+
911937
#[test]
912938
fn test_mkdir_concurrent_creation() {
913939
// Test concurrent mkdir -p operations: 10 iterations, 8 threads, 40 levels nesting

0 commit comments

Comments
 (0)