Skip to content

Commit 84d8077

Browse files
committed
Various improvements to the passwd_timeout tests
* Fix "token exceeds maximum length" by rounding the division result * Assert exit code / kill signal to ensure the process exited for the right reason. * Fail the zero_time_out test when sudo crashed with a signal before we kill it.
1 parent 43d0f4c commit 84d8077

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test-framework/sudo-compliance-tests/src/sudo/sudoers/passwd_timeout.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::os::unix::process::ExitStatusExt;
12
use std::thread;
23
use std::time::Duration;
34

@@ -13,7 +14,7 @@ fn time_out() -> Result<()> {
1314
let script_path = "/tmp/passwd_timeout.sh";
1415

1516
let env = Env(format!(
16-
"{USERNAME} ALL=(ALL:ALL) ALL\nDefaults passwd_timeout={}",
17+
"{USERNAME} ALL=(ALL:ALL) ALL\nDefaults passwd_timeout={:04}",
1718
timeout_seconds as f64 / 60.0,
1819
))
1920
.user(User(USERNAME).password(PASSWORD))
@@ -40,6 +41,7 @@ fn time_out() -> Result<()> {
4041
}
4142

4243
let output = child.wait();
44+
output.assert_exit_code(1);
4345
let diagnostic = if sudo_test::is_original_sudo() {
4446
"timed out reading password"
4547
} else {
@@ -57,7 +59,7 @@ fn dont_time_out() -> Result<()> {
5759
let script_path = "/tmp/passwd_timeout.sh";
5860

5961
let env = Env(format!(
60-
"{USERNAME} ALL=(ALL:ALL) ALL\nDefaults passwd_timeout={}",
62+
"{USERNAME} ALL=(ALL:ALL) ALL\nDefaults passwd_timeout={:04}",
6163
timeout_seconds as f64 / 60.0,
6264
))
6365
.user(User(USERNAME).password(PASSWORD))
@@ -73,7 +75,8 @@ fn dont_time_out() -> Result<()> {
7375

7476
child.kill()?;
7577

76-
let output = dbg!(child.wait());
78+
let output = child.wait();
79+
assert_eq!(output.status().signal(), Some(9 /* SIGKILL */));
7780
assert_not_contains!(output.stderr(), "timed out");
7881
Ok(())
7982
}
@@ -101,16 +104,14 @@ fn zero_time_out() -> Result<()> {
101104
None => {
102105
child.kill()?;
103106
}
104-
Some(status) => {
105-
if let Some(code) = status.code() {
106-
println!("passwd_timeout=0 exited: {code:?}");
107-
println!("{:?}", child.wait());
108-
panic!();
109-
}
107+
Some(_status) => {
108+
println!("exited with {:?}", child.wait());
109+
panic!();
110110
}
111111
}
112112

113113
let output = child.wait();
114+
assert_eq!(output.status().signal(), Some(9 /* SIGKILL */));
114115
assert_not_contains!(output.stderr(), "timed out");
115116
Ok(())
116117
}

0 commit comments

Comments
 (0)