oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package runner
2
3import (
4 "os"
5 "testing"
6
7 "golang.org/x/sys/unix"
8)
9
10// On a Mac the tool socket's peer is read with LOCAL_PEERCRED: both ends
11// of a socket pair this process made are its own user. Runs only on a
12// Mac; the seam tests (TestToolSocketPeerUID, TestDarwinToolProxyChecksTheListener)
13// cover the decision everywhere.
14func TestPeerUIDIsThisUser(t *testing.T) {
15 fds, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0)
16 if err != nil {
17 t.Fatal(err)
18 }
19 defer unix.Close(fds[0])
20 defer unix.Close(fds[1])
21 for _, fd := range fds {
22 uid, err := peerUID(fd)
23 if err != nil || uid != uint32(os.Getuid()) {
24 t.Fatalf("peer of %d: %d %v, want %d", fd, uid, err, os.Getuid())
25 }
26 }
27 if _, err := peerUID(-1); err == nil {
28 t.Fatal("a closed descriptor has a peer")
29 }
30}
31