Skip to content

Commit f0ade8a

Browse files
committed
Fix test in mock build environment
1 parent 5ae1634 commit f0ade8a

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

tests/pcred_test.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,22 @@ fn pcred_all_flag_shows_separate_credentials() {
6666
}
6767

6868
#[test]
69-
fn pcred_all_flag_always_shows_groups() {
69+
fn pcred_reports_groups_when_supplementary_groups_exist() {
70+
// Check whether this process has supplementary groups. The child inherits
71+
// them, so we can read our own /proc status to decide what to expect.
72+
let status = std::fs::read_to_string("/proc/self/status").unwrap();
73+
let has_groups = status
74+
.lines()
75+
.any(|l| l.starts_with("Groups:") && !l["Groups:".len()..].trim().is_empty());
76+
77+
if !has_groups {
78+
// No supplementary groups in this environment (e.g., mock build chroot).
79+
// Nothing to test — pcred correctly omits the groups line.
80+
return;
81+
}
82+
83+
// The default mode may suppress the groups line if there is only one group
84+
// matching rgid, so verify with -a which shows groups unconditionally.
7085
let output = common::run_ptool("pcred", &["-a"], "examples/pcred_process", &[], &[], false);
7186
let stdout = common::assert_success_and_get_stdout(output);
7287

@@ -76,20 +91,3 @@ fn pcred_all_flag_always_shows_groups() {
7691
stdout
7792
);
7893
}
79-
80-
#[test]
81-
fn pcred_reports_groups_when_supplementary_groups_exist() {
82-
let output = common::run_ptool("pcred", &[], "examples/pcred_process", &[], &[], false);
83-
common::assert_success_and_get_stdout(output);
84-
85-
// The default mode may suppress the groups line if there is only one group
86-
// matching rgid, so verify with -a which always shows groups.
87-
let output_all = common::run_ptool("pcred", &["-a"], "examples/pcred_process", &[], &[], false);
88-
let stdout_all = common::assert_success_and_get_stdout(output_all);
89-
90-
assert!(
91-
stdout_all.contains("groups:"),
92-
"Expected groups line with -a flag:\n{}",
93-
stdout_all
94-
);
95-
}

0 commit comments

Comments
 (0)