Move Unix peer credentials tests to their own file
This commit is contained in:
parent
40a830321d
commit
7c20be387b
2 changed files with 16 additions and 20 deletions
|
@ -89,23 +89,3 @@ pub mod impl_bsd {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use crate::os::unix::net::UnixStream;
|
|
||||||
use libc::{getegid, geteuid};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_socket_pair() {
|
|
||||||
// Create two connected sockets and get their peer credentials. They should be equal.
|
|
||||||
let (sock_a, sock_b) = UnixStream::pair().unwrap();
|
|
||||||
let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap());
|
|
||||||
assert_eq!(cred_a, cred_b);
|
|
||||||
|
|
||||||
// Check that the UID and GIDs match up.
|
|
||||||
let uid = unsafe { geteuid() };
|
|
||||||
let gid = unsafe { getegid() };
|
|
||||||
assert_eq!(cred_a.uid, uid);
|
|
||||||
assert_eq!(cred_a.gid, gid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
16
library/std/src/sys/unix/ext/ucred/tests.rs
Normal file
16
library/std/src/sys/unix/ext/ucred/tests.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
use crate::os::unix::net::UnixStream;
|
||||||
|
use libc::{getegid, geteuid};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_socket_pair() {
|
||||||
|
// Create two connected sockets and get their peer credentials. They should be equal.
|
||||||
|
let (sock_a, sock_b) = UnixStream::pair().unwrap();
|
||||||
|
let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap());
|
||||||
|
assert_eq!(cred_a, cred_b);
|
||||||
|
|
||||||
|
// Check that the UID and GIDs match up.
|
||||||
|
let uid = unsafe { geteuid() };
|
||||||
|
let gid = unsafe { getegid() };
|
||||||
|
assert_eq!(cred_a.uid, uid);
|
||||||
|
assert_eq!(cred_a.gid, gid);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue