Skip to content

Commit

Permalink
add a test for cases where -g is used to select a supplementary group
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Dec 19, 2024
1 parent b5f82b4 commit cdd3e87
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test-framework/sudo-compliance-tests/src/sudo/flag_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@ fn adds_group_to_groups_output() -> Result<()> {
Ok(())
}

#[test]
fn supplementary_groups_can_be_made_primary() -> Result<()> {
let extra_group = "rustaceans";
let env = Env(SUDOERS_ALL_ALL_NOPASSWD)
.user(User(USERNAME).secondary_group(extra_group))
.group(Group(extra_group))
.group("secondary-group")
.build()?;

let stdout = Command::new("groups")
.as_user(USERNAME)
.output(&env)?
.stdout()?;
let mut groups_without_sudo = stdout.split_ascii_whitespace().collect::<Vec<_>>();

let stdout = Command::new("sudo")
.args(["-g", extra_group, "groups"])
.as_user(USERNAME)
.output(&env)?
.stdout()?;

let mut groups_with_sudo = stdout.split_ascii_whitespace().collect::<Vec<_>>();

assert_eq!(groups_with_sudo[0], extra_group);

groups_without_sudo.sort();
groups_with_sudo.sort();
assert_eq!(groups_with_sudo, groups_without_sudo);

Ok(())
}

#[test]
fn group_can_be_specified_by_id() -> Result<()> {
let expected_gid = 1234;
Expand Down

0 comments on commit cdd3e87

Please sign in to comment.