-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathnpipe_windows_test.go
More file actions
84 lines (76 loc) · 1.94 KB
/
Copy pathnpipe_windows_test.go
File metadata and controls
84 lines (76 loc) · 1.94 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:build windows
package confignet
import (
"context"
"net"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNpipeListenAndDial(t *testing.T) {
endpoint := `\\.\pipe\otel-test-confignet`
nas := &AddrConfig{
Endpoint: endpoint,
Transport: TransportTypeNpipe,
}
ln, err := nas.Listen(context.Background())
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, ln.Close())
})
defer ln.Close()
done := make(chan bool, 1)
go func() {
conn, errGo := ln.Accept()
assert.NoError(t, errGo)
buf := make([]byte, 10)
var numChr int
numChr, errGo = conn.Read(buf)
assert.NoError(t, errGo)
assert.Equal(t, "test", string(buf[:numChr]))
assert.NoError(t, conn.Close())
done <- true
}()
nac := &AddrConfig{
Endpoint: endpoint,
Transport: TransportTypeNpipe,
}
var conn net.Conn
conn, err = nac.Dial(context.Background())
require.NoError(t, err)
_, err = conn.Write([]byte("test"))
assert.NoError(t, err)
assert.NoError(t, conn.Close())
<-done
}
func TestNpipeListenSecurityDescriptor(t *testing.T) {
tests := []struct {
name string
securityDescriptor string
wantErr bool
}{
{name: "default", securityDescriptor: "", wantErr: false},
{name: "owner local system, allow everyone read/write", securityDescriptor: "O:SYG:SYD:(A;;GRGW;;;WD)", wantErr: false},
{name: "invalid SDDL", securityDescriptor: "not-a-valid-sddl", wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nas := &AddrConfig{
Endpoint: `\\.\pipe\otel-test-confignet-sd`,
Transport: TransportTypeNpipe,
NpipeConfig: NpipeConfig{
SecurityDescriptor: tt.securityDescriptor,
},
}
ln, err := nas.Listen(t.Context())
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.NoError(t, ln.Close())
})
}
}