Skip to content

Commit 2ec1ac7

Browse files
bjorn3squell
authored andcommitted
Add a test for sudoedit running the editor as the correct user
1 parent 7cced18 commit 2ec1ac7

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test-framework/sudo-compliance-tests/src/sudoedit.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,32 @@ done",
429429

430430
assert_starts_with!(actual[actual.rfind('/').unwrap()..], "/foo");
431431
}
432+
433+
#[test]
434+
fn run_editor_as_correct_user() {
435+
let env = Env(SUDOERS_ALL_ALL_NOPASSWD)
436+
.user(USERNAME)
437+
.file(
438+
DEFAULT_EDITOR,
439+
TextFile(
440+
"#!/bin/sh
441+
id -un
442+
id -Gn",
443+
)
444+
.chmod(CHMOD_EXEC),
445+
)
446+
.build();
447+
448+
let output = Command::new("sh")
449+
.arg("-c")
450+
.arg(format!("{DEFAULT_EDITOR} && cd / && sudoedit foo"))
451+
.as_user(USERNAME)
452+
.output(&env);
453+
454+
output.assert_success();
455+
456+
assert_eq!(
457+
output.stdout(),
458+
format!("{USERNAME}\nusers\n{USERNAME}\nusers")
459+
);
460+
}

0 commit comments

Comments
 (0)