We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a9ec61d commit be2637aCopy full SHA for be2637a
library/std/src/sys/unix/ext/ucred.rs
@@ -87,3 +87,23 @@ pub mod impl_bsd {
87
}
88
89
90
+
91
+#[cfg(test)]
92
+mod test {
93
+ use crate::os::unix::net::UnixStream;
94
+ use libc::{getegid, geteuid};
95
96
+ #[test]
97
+ fn test_socket_pair() {
98
+ // Create two connected sockets and get their peer credentials. They should be equal.
99
+ let (sock_a, sock_b) = UnixStream::pair().unwrap();
100
+ let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap());
101
+ assert_eq!(cred_a, cred_b);
102
103
+ // Check that the UID and GIDs match up.
104
+ let uid = unsafe { geteuid() };
105
+ let gid = unsafe { getegid() };
106
+ assert_eq!(cred_a.uid, uid);
107
+ assert_eq!(cred_a.gid, gid);
108
+ }
109
+}
0 commit comments