mod common;
#[test]
fn pcred_reports_condensed_credentials() {
let output = common::run_ptool("pcred", &[], "examples/pcred_process", &[], &[], false);
let stdout = common::assert_success_and_get_stdout(output);
let mut lines = stdout.lines();
let first = lines
.next()
.unwrap_or_else(|| panic!("Expected credential line in pcred output:\n{stdout}"));
assert!(
first.contains("e/r/s/fsuid="),
"Expected condensed UID format:\n{stdout}"
);
assert!(
first.contains("e/r/s/fsgid="),
"Expected condensed GID format:\n{stdout}"
);
}
#[test]
fn pcred_all_flag_shows_separate_credentials() {
let output = common::run_ptool("pcred", &["-a"], "examples/pcred_process", &[], &[], false);
let stdout = common::assert_success_and_get_stdout(output);
let mut lines = stdout.lines();
let first = lines
.next()
.unwrap_or_else(|| panic!("Expected credential line in pcred output:\n{stdout}"));
assert!(
first.contains("euid="),
"Expected separate euid with -a flag:\n{stdout}"
);
assert!(
first.contains("ruid="),
"Expected separate ruid with -a flag:\n{stdout}"
);
assert!(
first.contains("suid="),
"Expected separate suid with -a flag:\n{stdout}"
);
assert!(
first.contains("egid="),
"Expected separate egid with -a flag:\n{stdout}"
);
assert!(
first.contains("rgid="),
"Expected separate rgid with -a flag:\n{stdout}"
);
assert!(
first.contains("sgid="),
"Expected separate sgid with -a flag:\n{stdout}"
);
}
#[test]
fn pcred_reports_groups_when_supplementary_groups_exist() {
let status = std::fs::read_to_string("/proc/self/status").unwrap();
let has_groups = status
.lines()
.any(|l| l.starts_with("Groups:") && !l["Groups:".len()..].trim().is_empty());
if !has_groups {
return;
}
let output = common::run_ptool("pcred", &["-a"], "examples/pcred_process", &[], &[], false);
let stdout = common::assert_success_and_get_stdout(output);
assert!(
stdout.contains("groups:"),
"Expected groups line with -a flag:\n{stdout}"
);
}