-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sudo-test: revamp API to make it more like std::process::Command * applease clippy * update compliance tests * sudo-test: revamp EnvBuilder API to better adhere to the builder pattern * update compliance tests * add regression test for #81 * apply workaround for #102 * refactor some literals into constants
- Loading branch information
Showing
14 changed files
with
936 additions
and
849 deletions.
There are no files selected for viewing
44 changes: 18 additions & 26 deletions
44
test-framework/sudo-compliance-tests/src/child_process.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,45 @@ | ||
use pretty_assertions::assert_eq; | ||
use sudo_test::{As, EnvBuilder}; | ||
use sudo_test::{Command, Env}; | ||
|
||
use crate::{Result, SUDOERS_ROOT_ALL_NOPASSWD}; | ||
|
||
#[test] | ||
fn sudo_forwards_childs_exit_code() -> Result<()> { | ||
let env = EnvBuilder::default() | ||
.sudoers(SUDOERS_ROOT_ALL_NOPASSWD) | ||
.build()?; | ||
let env = Env(SUDOERS_ROOT_ALL_NOPASSWD).build()?; | ||
|
||
let expected = 42; | ||
let output = env.exec( | ||
&["sudo", "sh", "-c", &format!("exit {expected}")], | ||
As::Root, | ||
None, | ||
)?; | ||
assert_eq!(Some(expected), output.status.code()); | ||
let output = Command::new("sudo") | ||
.args(["sh", "-c"]) | ||
.arg(format!("exit {expected}")) | ||
.exec(&env)?; | ||
assert_eq!(Some(expected), output.status().code()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn sudo_forwards_childs_stdout() -> Result<()> { | ||
let env = EnvBuilder::default() | ||
.sudoers(SUDOERS_ROOT_ALL_NOPASSWD) | ||
.build()?; | ||
let env = Env(SUDOERS_ROOT_ALL_NOPASSWD).build()?; | ||
|
||
let expected = "hello"; | ||
let output = env.exec(&["sudo", "echo", expected], As::Root, None)?; | ||
assert_eq!(expected, output.stdout); | ||
assert!(output.stderr.is_empty()); | ||
let output = Command::new("sudo").args(["echo", expected]).exec(&env)?; | ||
assert!(output.stderr().is_empty()); | ||
assert_eq!(expected, output.stdout()?); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn sudo_forwards_childs_stderr() -> Result<()> { | ||
let env = EnvBuilder::default() | ||
.sudoers(SUDOERS_ROOT_ALL_NOPASSWD) | ||
.build()?; | ||
let env = Env(SUDOERS_ROOT_ALL_NOPASSWD).build()?; | ||
|
||
let expected = "hello"; | ||
let output = env.exec( | ||
&["sudo", "sh", "-c", &format!(">&2 echo {expected}")], | ||
As::Root, | ||
None, | ||
)?; | ||
assert_eq!(expected, output.stderr); | ||
assert!(output.stdout.is_empty()); | ||
let output = Command::new("sudo") | ||
.args(["sh", "-c"]) | ||
.arg(format!(">&2 echo {expected}")) | ||
.exec(&env)?; | ||
assert_eq!(expected, output.stderr()); | ||
assert!(output.stdout()?.is_empty()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.