|
1 |
| -use sudo_test::{Command, Env, TextFile}; |
| 1 | +use sudo_test::{Command, Env, TextFile, User}; |
2 | 2 |
|
3 | 3 | #[test]
|
4 | 4 | fn syslog_writer_should_not_hang() {
|
@@ -30,3 +30,42 @@ fn no_permissions_should_not_violate_io_safety() {
|
30 | 30 | "sudo-rs: cannot execute '/usr/bin/foo': Permission denied (os error 13)"
|
31 | 31 | );
|
32 | 32 | }
|
| 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