Skip to content

Commit b215bb8

Browse files
authored
Modify test cases so they test the same on Ubuntu and pass on Fedora (#1031)
2 parents 69d9a40 + 2e93b32 commit b215bb8

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

src/common/resolve.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,23 @@ mod test {
365365
fn canonicalization() {
366366
assert_eq!(canonicalize("/").unwrap(), Path::new("/"));
367367
assert_eq!(canonicalize("").unwrap(), Path::new(""));
368-
assert_eq!(
369-
canonicalize("/usr/bin/pkill").unwrap(),
370-
Path::new("/usr/bin/pkill")
371-
);
372368
if cfg!(any(target_os = "linux", target_os = "macos")) {
369+
// this test REQUIRES /usr/bin/unxz to be a symlink for /usr/bin/xz
370+
assert_eq!(
371+
canonicalize("/usr/bin/unxz").unwrap(),
372+
Path::new("/usr/bin/unxz")
373+
);
373374
// this assumes /bin is a symlink on /usr/bin, like it is on modern Debian/Ubuntu
374375
assert_eq!(
375-
canonicalize("/bin/pkill").unwrap(),
376-
Path::new("/usr/bin/pkill")
376+
canonicalize("/bin/unxz").unwrap(),
377+
Path::new("/usr/bin/unxz")
377378
);
378379
} else if cfg!(target_os = "freebsd") {
380+
// this test REQUIRES /usr/bin/pkill to be a symlink for /usr/bin/pgrep
381+
assert_eq!(
382+
canonicalize("/usr/bin/pkill").unwrap(),
383+
Path::new("/usr/bin/pkill")
384+
);
379385
assert_eq!(canonicalize("/bin/pkill").unwrap(), Path::new("/bin/pkill"));
380386
} else {
381387
panic!(

src/system/audit.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ mod test {
119119

120120
#[cfg(target_os = "linux")]
121121
{
122-
// /var/log/utmp should be readable, but not secure (writeable by group other than root)
122+
// /var/log/wtmp should be readable, but not secure (writeable by group other than root)
123123
// It doesn't exist on many non-Linux systems however.
124-
assert!(std::fs::File::open("/var/log/wtmp").is_ok());
125-
assert!(secure_open("/var/log/wtmp", false).is_err());
124+
if std::fs::File::open("/var/log/wtmp").is_ok() {
125+
assert!(secure_open("/var/log/wtmp", false).is_err());
126+
}
126127
}
127128

128129
// /etc/shadow should not be readable

src/system/interface.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -160,39 +160,36 @@ mod test {
160160
use crate::system::{Group, User, ROOT_GROUP_NAME};
161161
use std::ffi::CString;
162162

163-
fn test_user(user: impl UnixUser, name_c: &CStr, uid: UserId) {
163+
fn test_user(user: impl UnixUser, name_c: &CStr) {
164164
let name = name_c.to_str().unwrap();
165165
assert!(user.has_name(name));
166-
assert!(user.has_uid(uid));
167166
if user.has_name("root") {
168167
assert!(user.in_group_by_name(CString::new(ROOT_GROUP_NAME).unwrap().as_c_str()));
168+
assert!(user.is_root());
169169
} else {
170170
assert!(user.in_group_by_name(name_c));
171+
assert!(!user.is_root());
171172
}
172173
assert_eq!(user.is_root(), name == "root");
173174
}
174175

175-
fn test_group(group: impl UnixGroup, name: &str, gid: GroupId) {
176-
assert_eq!(group.as_gid(), gid);
176+
fn test_group(group: impl UnixGroup, name: &str) {
177+
assert_eq!(name == ROOT_GROUP_NAME, group.as_gid() == GroupId::new(0));
177178
assert_eq!(group.try_as_name(), Some(name));
178179
}
179180

180181
#[test]
181182
fn test_unix_user() {
182183
let user = |name| User::from_name(name).unwrap().unwrap();
183-
test_user(user(cstr!("root")), cstr!("root"), UserId::ROOT);
184-
test_user(user(cstr!("daemon")), cstr!("daemon"), UserId::new(1));
184+
test_user(user(cstr!("root")), cstr!("root"));
185+
test_user(user(cstr!("daemon")), cstr!("daemon"));
185186
}
186187

187188
#[test]
188189
fn test_unix_group() {
189190
let group = |name| Group::from_name(name).unwrap().unwrap();
190191
let root_group_cstr = CString::new(ROOT_GROUP_NAME).unwrap();
191-
test_group(
192-
group(root_group_cstr.as_c_str()),
193-
ROOT_GROUP_NAME,
194-
GroupId::new(0),
195-
);
196-
test_group(group(cstr!("daemon")), "daemon", GroupId::new(1));
192+
test_group(group(root_group_cstr.as_c_str()), ROOT_GROUP_NAME);
193+
test_group(group(cstr!("daemon")), "daemon");
197194
}
198195
}

0 commit comments

Comments
 (0)