This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_network_test.go
96 lines (79 loc) · 1.96 KB
/
handler_network_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
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
85
86
87
88
89
90
91
92
93
94
95
96
package security
import (
"context"
"io"
"sync"
"testing"
"github.com/containerssh/log"
"github.com/containerssh/sshserver"
"github.com/stretchr/testify/assert"
)
func TestMaxSessions(t *testing.T) {
backend := &dummySSHBackend{
exitChannel: make(chan struct{}),
}
ssh := &sshConnectionHandler{
config: Config{
MaxSessions: 10,
},
backend: backend,
lock: &sync.Mutex{},
logger: log.NewTestLogger(t),
}
for i := 0; i < ssh.config.MaxSessions; i++ {
handler, err := ssh.OnSessionChannel(uint64(i), []byte{}, &sessionChannel{})
assert.NoError(t, err)
assert.NoError(
t, handler.OnShell(0),
)
}
_, err := ssh.OnSessionChannel(uint64(ssh.config.MaxSessions), []byte{}, &sessionChannel{})
assert.Error(t, err)
for i := 0; i < ssh.config.MaxSessions; i++ {
backend.exitChannel <- struct{}{}
}
}
type sessionChannel struct {
}
func (s *sessionChannel) Stdin() io.Reader {
panic("implement me")
}
func (s *sessionChannel) Stdout() io.Writer {
panic("implement me")
}
func (s *sessionChannel) Stderr() io.Writer {
panic("implement me")
}
func (s *sessionChannel) ExitStatus(_ uint32) {
panic("implement me")
}
func (s *sessionChannel) ExitSignal(_ string, _ bool, _ string, _ string) {
panic("implement me")
}
func (s *sessionChannel) CloseWrite() error {
panic("implement me")
}
func (s *sessionChannel) Close() error {
panic("implement me")
}
type dummySSHBackend struct {
exitChannel chan struct{}
}
func (d *dummySSHBackend) OnShutdown(_ context.Context) {
panic("implement me")
}
func (d *dummySSHBackend) OnUnsupportedGlobalRequest(_ uint64, _ string, _ []byte) {
panic("implement me")
}
func (d *dummySSHBackend) OnUnsupportedChannel(_ uint64, _ string, _ []byte) {
panic("implement me")
}
func (d *dummySSHBackend) OnSessionChannel(
_ uint64,
_ []byte,
_ sshserver.SessionChannel,
) (channel sshserver.SessionChannelHandler, failureReason sshserver.ChannelRejection) {
return &dummyBackend{
exit: d.exitChannel,
}, nil
}