| 1 | #![warn (rust_2018_idioms)] |
| 2 | #![cfg (feature = "full" )] |
| 3 | #![cfg (all(unix, not(target_os = "dragonfly" )))] |
| 4 | |
| 5 | use tokio::net::UnixStream; |
| 6 | |
| 7 | use libc::getegid; |
| 8 | use libc::geteuid; |
| 9 | |
| 10 | #[tokio::test ] |
| 11 | #[cfg_attr ( |
| 12 | target_os = "netbsd" , |
| 13 | ignore = "NetBSD does not support getpeereid() for sockets created by socketpair()" |
| 14 | )] |
| 15 | async fn test_socket_pair() { |
| 16 | let (a, b) = UnixStream::pair().unwrap(); |
| 17 | let cred_a = a.peer_cred().unwrap(); |
| 18 | let cred_b = b.peer_cred().unwrap(); |
| 19 | assert_eq!(cred_a, cred_b); |
| 20 | |
| 21 | let uid = unsafe { geteuid() }; |
| 22 | let gid = unsafe { getegid() }; |
| 23 | |
| 24 | assert_eq!(cred_a.uid(), uid); |
| 25 | assert_eq!(cred_a.gid(), gid); |
| 26 | } |
| 27 | |