go.nanomsg.org/mangos/v3@v3.4.3-0.20240217232803-46464076f1f5/transport/ipc/ipc_peer_linux_test.go (about) 1 // Copyright 2020 The Mangos Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use file except in compliance with the License. 5 // You may obtain a copy of the license at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build linux 16 // +build linux 17 18 package ipc 19 20 import ( 21 "os" 22 "testing" 23 "time" 24 25 "go.nanomsg.org/mangos/v3" 26 . "go.nanomsg.org/mangos/v3/internal/test" 27 ) 28 29 func TestIpcPeerIdLinux(t *testing.T) { 30 sock1 := GetMockSocket() 31 sock2 := GetMockSocket() 32 defer MustClose(t, sock1) 33 defer MustClose(t, sock2) 34 addr := AddrTestIPC() 35 l, e := sock1.NewListener(addr, nil) 36 MustSucceed(t, e) 37 MustSucceed(t, l.Listen()) 38 d, e := sock2.NewDialer(addr, nil) 39 MustSucceed(t, d.Dial()) 40 time.Sleep(time.Millisecond * 20) 41 42 MustSend(t, sock1, make([]byte, 1)) 43 m := MustRecvMsg(t, sock2) 44 p := m.Pipe 45 46 v, err := p.GetOption(mangos.OptionPeerPID) 47 MustSucceed(t, err) 48 pid, ok := v.(int) 49 MustBeTrue(t, ok) 50 MustBeTrue(t, pid == os.Getpid()) 51 52 v, err = p.GetOption(mangos.OptionPeerUID) 53 MustSucceed(t, err) 54 uid, ok := v.(int) 55 MustBeTrue(t, ok) 56 MustBeTrue(t, uid == os.Getuid()) 57 58 v, err = p.GetOption(mangos.OptionPeerGID) 59 MustSucceed(t, err) 60 gid, ok := v.(int) 61 MustBeTrue(t, ok) 62 MustBeTrue(t, gid == os.Getgid()) 63 }