-
Notifications
You must be signed in to change notification settings - Fork 458
/
server_unix_test.go
56 lines (50 loc) · 1.08 KB
/
server_unix_test.go
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
51
52
53
54
55
56
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build !windows
// +build !windows
package plugin
import (
"fmt"
"os"
"os/user"
"runtime"
"syscall"
"testing"
)
func TestUnixSocketGroupPermissions(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("go-plugin doesn't support unix sockets on Windows")
}
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 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)
}
})
}
}