• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = "freebsd",
13     ignore = "Requires FreeBSD 12.0 or later. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=176419"
14 )]
15 #[cfg_attr(
16     target_os = "netbsd",
17     ignore = "NetBSD does not support getpeereid() for sockets created by socketpair()"
18 )]
test_socket_pair()19 async fn test_socket_pair() {
20     let (a, b) = UnixStream::pair().unwrap();
21     let cred_a = a.peer_cred().unwrap();
22     let cred_b = b.peer_cred().unwrap();
23     assert_eq!(cred_a, cred_b);
24 
25     let uid = unsafe { geteuid() };
26     let gid = unsafe { getegid() };
27 
28     assert_eq!(cred_a.uid(), uid);
29     assert_eq!(cred_a.gid(), gid);
30 }
31