-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathserver_unix_test.go
More file actions
50 lines (45 loc) · 999 Bytes
/
server_unix_test.go
File metadata and controls
50 lines (45 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: MPL-2.0
//go:build !windows
package plugin
import (
"fmt"
"os"
"os/user"
"syscall"
"testing"
)
func TestUnixSocketGroupPermissions(t *testing.T) {
group, err := user.LookupGroupId(fmt.Sprintf("%d", os.Getgid()))
if err != nil {
t.Fatal(err)
}
for name, tc := range map[string]struct {
group string
}{
"as integer": {fmt.Sprintf("%d", os.Getgid())},
"as name": {group.Name},
} {
t.Run(name, func(t *testing.T) {
ln, err := serverListener_unix(UnixSocketConfig{Group: tc.group})
if err != nil {
t.Fatal(err)
}
defer func() { _ = ln.Close() }()
info, err := os.Lstat(ln.Addr().String())
if err != nil {
t.Fatal(err)
}
if info.Mode()&os.ModePerm != 0o660 {
t.Fatal(info.Mode())
}
stat, ok := info.Sys().(*syscall.Stat_t)
if !ok {
t.Fatal()
}
if stat.Gid != uint32(os.Getgid()) {
t.Fatalf("Expected %d, but got %d", os.Getgid(), stat.Gid)
}
})
}
}