Skip to content

Commit 5c78488

Browse files
committed
add regression test
1 parent 848719f commit 5c78488

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

test-framework/e2e-tests/src/regression.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sudo_test::{Command, Env, TextFile};
1+
use sudo_test::{Command, Env, TextFile, User};
22

33
#[test]
44
fn syslog_writer_should_not_hang() {
@@ -30,3 +30,42 @@ fn no_permissions_should_not_violate_io_safety() {
3030
"sudo-rs: cannot execute '/usr/bin/foo': Permission denied (os error 13)"
3131
);
3232
}
33+
34+
#[test]
35+
fn user_without_permissions_cannot_distinguish_file_existence() {
36+
// run test for users both without any permissions and limited permissions that
37+
// exclude access to the directory of interest
38+
for sudoers in ["", "ALL ALL=/bin/true"] {
39+
let env = Env(sudoers)
40+
// ordinary users have no access to the directory
41+
.directory(sudo_test::Directory("/secret").chmod("777"))
42+
// this should be irrespective of file permissions
43+
.file("/secret/txt", TextFile("").chmod("000"))
44+
.file("/secret/foo", TextFile("#! /bin/sh").chmod("777"))
45+
.user(User("user").password("password"))
46+
.build();
47+
48+
for bait in ["/secret/txt", "/secret/foo"] {
49+
let output = Command::new("sudo")
50+
.args(["-S", "-l", bait])
51+
.as_user("user")
52+
.stdin("password")
53+
.output(&env);
54+
assert!(!output.status().success());
55+
let response_1 = output.stderr().replace(bait, "<file>");
56+
57+
let output = Command::new("sudo")
58+
.args(["-S", "-l", "/secret/missing"])
59+
.as_user("user")
60+
.stdin("password")
61+
.output(&env);
62+
assert!(!output.status().success());
63+
let response_2 = output.stderr().replace("/secret/missing", "<file>");
64+
65+
dbg!(sudoers);
66+
dbg!(bait);
67+
dbg!(&response_1);
68+
assert_eq!(response_1, response_2);
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)