|
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | 5 | // spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile tabsize aaaaaaaa bbbb cccc dddddddd ncccc neee naaaaa nbcdef nfffff dired subdired tmpfs mdir COLORTERM mexe bcdef mfoo |
| 6 | +// spell-checker:ignore (words) fakeroot setcap |
6 | 7 | #![allow( |
7 | 8 | clippy::similar_names, |
8 | 9 | clippy::too_many_lines, |
@@ -5516,3 +5517,49 @@ fn test_suffix_case_sensitivity() { |
5516 | 5517 | /* cSpell:enable */ |
5517 | 5518 | ); |
5518 | 5519 | } |
| 5520 | + |
| 5521 | +#[cfg(all(unix, target_os = "linux"))] |
| 5522 | +#[test] |
| 5523 | +fn test_ls_capabilities() { |
| 5524 | + let scene = TestScenario::new(util_name!()); |
| 5525 | + let at = &scene.fixtures; |
| 5526 | + |
| 5527 | + // Test must be run as root (or with `sudo -E`) |
| 5528 | + // fakeroot setcap cap_net_bind_service=ep /tmp/file_name |
| 5529 | + // doesn't trigger an error and fails silently |
| 5530 | + if scene.cmd("whoami").run().stdout_str() != "root\n" { |
| 5531 | + return; |
| 5532 | + } |
| 5533 | + at.mkdir("test"); |
| 5534 | + at.mkdir("test/dir"); |
| 5535 | + at.touch("test/cap_pos"); |
| 5536 | + at.touch("test/dir/cap_neg"); |
| 5537 | + at.touch("test/dir/cap_pos"); |
| 5538 | + |
| 5539 | + let files = ["test/cap_pos", "test/dir/cap_pos"]; |
| 5540 | + for file in &files { |
| 5541 | + scene |
| 5542 | + .cmd("sudo") |
| 5543 | + .args(&[ |
| 5544 | + "-E", |
| 5545 | + "--non-interactive", |
| 5546 | + "setcap", |
| 5547 | + "cap_net_bind_service=ep", |
| 5548 | + at.plus(file).to_str().unwrap(), |
| 5549 | + ]) |
| 5550 | + .succeeds(); |
| 5551 | + } |
| 5552 | + |
| 5553 | + let ls_colors = "di=:ca=30;41"; |
| 5554 | + |
| 5555 | + scene |
| 5556 | + .ucmd() |
| 5557 | + .env("LS_COLORS", ls_colors) |
| 5558 | + .arg("--color=always") |
| 5559 | + .arg("test/cap_pos") |
| 5560 | + .arg("test/dir") |
| 5561 | + .succeeds() |
| 5562 | + .stdout_contains("\x1b[30;41mtest/cap_pos") // spell-checker:disable-line |
| 5563 | + .stdout_contains("\x1b[30;41mcap_pos") // spell-checker:disable-line |
| 5564 | + .stdout_does_not_contain("0;41mtest/dir/cap_neg"); // spell-checker:disable-line |
| 5565 | +} |
0 commit comments