package runner import ( "os" "testing" "golang.org/x/sys/unix" ) // On a Mac the tool socket's peer is read with LOCAL_PEERCRED: both ends // of a socket pair this process made are its own user. Runs only on a // Mac; the seam tests (TestToolSocketPeerUID, TestDarwinToolProxyChecksTheListener) // cover the decision everywhere. func TestPeerUIDIsThisUser(t *testing.T) { fds, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0) if err != nil { t.Fatal(err) } defer unix.Close(fds[0]) defer unix.Close(fds[1]) for _, fd := range fds { uid, err := peerUID(fd) if err != nil || uid != uint32(os.Getuid()) { t.Fatalf("peer of %d: %d %v, want %d", fd, uid, err, os.Getuid()) } } if _, err := peerUID(-1); err == nil { t.Fatal("a closed descriptor has a peer") } }