tests: disable some chgrp tests when part of the root group

Some tests failed when run using Docker because they assumed the
user would never be root.  This is more of a band-aid solution.
An actual fix would be to test see if something like these tests
were to succeed when the user is root.
This commit is contained in:
Alex Lyon 2018-03-01 23:08:09 -08:00
parent 8ece01d0ef
commit d8e738c49b
5 changed files with 298 additions and 249 deletions

456
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -252,6 +252,7 @@ unindent = "0.1.0"
lazy_static = "0.2.2"
[target.'cfg(unix)'.dev-dependencies]
rust-users = { git = "https://github.com/Arcterus/rust-users" }
unix_socket = "0.5.0"
[[bin]]

View file

@ -18,8 +18,11 @@ mod platform {
fn main() {
mkmain::main();
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("Could not find manifest dir");
let profile = env::var("PROFILE").expect("Could not determine profile");
let out_dir = env::var("OUT_DIR").unwrap();
let libstdbuf = format!("{}/../../{}/{}/deps/liblibstdbuf{}", env::var("CARGO_MANIFEST_DIR").unwrap(), env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string()), env::var("PROFILE").unwrap(), platform::DYLIB_EXT);
let libstdbuf = format!("{}/../../{}/{}/deps/liblibstdbuf{}", manifest_dir, env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string()), profile, platform::DYLIB_EXT);
fs::copy(libstdbuf, Path::new(&out_dir).join("libstdbuf.so")).unwrap();
}

View file

@ -1,5 +1,5 @@
use common::util::*;
use rust_users::*;
#[test]
fn test_invalid_option() {
@ -14,30 +14,34 @@ static DIR: &'static str = "/tmp";
#[test]
fn test_invalid_group() {
new_ucmd!()
.arg("nosuchgroup")
.arg("__nosuchgroup__")
.arg("/")
.fails()
.stderr_is("chgrp: invalid group: nosuchgroup");
.stderr_is("chgrp: invalid group: __nosuchgroup__");
}
#[test]
fn test_1() {
new_ucmd!()
.arg("bin")
.arg(DIR)
.fails()
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
if get_effective_gid() != 0 {
new_ucmd!()
.arg("bin")
.arg(DIR)
.fails()
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
}
}
#[test]
fn test_fail_silently() {
for opt in &["-f", "--silent", "--quiet"] {
new_ucmd!()
.arg(opt)
.arg("bin")
.arg(DIR)
.run()
.fails_silently();
if get_effective_gid() != 0 {
for opt in &["-f", "--silent", "--quiet"] {
new_ucmd!()
.arg(opt)
.arg("bin")
.arg(DIR)
.run()
.fails_silently();
}
}
}
@ -94,13 +98,15 @@ fn test_preserve_root_symlink() {
#[test]
#[cfg(target_os = "linux")]
fn test_reference() {
new_ucmd!()
.arg("-v")
.arg("--reference=/etc/passwd")
.arg("/etc")
.fails()
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\n")
.stdout_is("failed to change group of /etc from root to root\n");
if get_effective_gid() != 0 {
new_ucmd!()
.arg("-v")
.arg("--reference=/etc/passwd")
.arg("/etc")
.fails()
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\n")
.stdout_is("failed to change group of /etc from root to root\n");
}
}
#[test]
@ -116,23 +122,27 @@ fn test_reference() {
#[test]
#[cfg(target_os = "linux")]
fn test_big_p() {
new_ucmd!()
.arg("-RP")
.arg("bin")
.arg("/proc/self/cwd")
.fails()
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n");
if get_effective_gid() != 0 {
new_ucmd!()
.arg("-RP")
.arg("bin")
.arg("/proc/self/cwd")
.fails()
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_big_h() {
assert!(new_ucmd!()
.arg("-RH")
.arg("bin")
.arg("/proc/self/fd")
.fails()
.stderr
.lines()
.fold(0, |acc, _| acc + 1) > 1);
if get_effective_gid() != 0 {
assert!(new_ucmd!()
.arg("-RH")
.arg("bin")
.arg("/proc/self/fd")
.fails()
.stderr
.lines()
.fold(0, |acc, _| acc + 1) > 1);
}
}

View file

@ -4,6 +4,9 @@ mod common;
#[macro_use]
extern crate lazy_static;
#[cfg(unix)]
extern crate rust_users;
// For conditional compilation
macro_rules! unix_only {
($($fea:expr, $m:ident);+) => {