Skip to content

Commit 7eb1169

Browse files
committed
Update test to verify ownership/permissions
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent e6929d9 commit 7eb1169

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

sockets/unix_socket_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"net"
66
"os"
7+
"syscall"
78
"testing"
89
)
910

@@ -47,12 +48,25 @@ func TestNewUnixSocket(t *testing.T) {
4748

4849
func TestUnixSocketWithOpts(t *testing.T) {
4950
uid, gid := os.Getuid(), os.Getgid()
51+
perms := os.FileMode(0660)
5052
path := "/tmp/test.sock"
5153
echoStr := "hello"
52-
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(0660))
54+
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(perms))
5355
if err != nil {
5456
t.Fatal(err)
5557
}
5658
defer l.Close()
59+
p, err := os.Stat(path)
60+
if err != nil {
61+
t.Fatal(err)
62+
}
63+
if p.Mode().Perm() != perms {
64+
t.Fatalf("unexpected file permissions: expected: %#o, got: %#o", perms, p.Mode().Perm())
65+
}
66+
if stat, ok := p.Sys().(*syscall.Stat_t); ok {
67+
if stat.Uid != uint32(uid) || stat.Gid != uint32(gid) {
68+
t.Fatalf("unexpected file ownership: expected: %d:%d, got: %d:%d", uid, gid, stat.Uid, stat.Gid)
69+
}
70+
}
5771
runTest(t, path, l, echoStr)
5872
}

0 commit comments

Comments
 (0)