MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestConnectionSetup

Function TestConnectionSetup

agentprotocol/server_test.go:14–100  ·  view source on GitHub ↗

region Tests

(t *testing.T)

Source from the content-addressed store, hash-verified

12
13// region Tests
14func TestConnectionSetup(t *testing.T) {
15 log := log.NewTestLogger(t)
16 fromClientReader, fromClientWriter := io.Pipe()
17 toClientReader, toClientWriter := io.Pipe()
18
19 clientCtx := proto.NewForwardCtx(toClientReader, fromClientWriter, log)
20
21 serverCtx := proto.NewForwardCtx(fromClientReader, toClientWriter, log)
22
23 closeChan := make(chan struct{})
24
25 go func() {
26 connChan, err := serverCtx.StartReverseForwardClient(
27 "127.0.0.1",
28 8080,
29 false,
30 )
31 if err != nil {
32 panic(err)
33 }
34
35 testConServer := <-connChan
36 err = testConServer.Accept()
37 if err != nil {
38 log.Error("Error accept connection", err)
39 }
40 buf := make([]byte, 512)
41 nBytes, err := testConServer.Read(buf)
42 if err != nil {
43 log.Error("Failed to read from server")
44 }
45 _, err = testConServer.Write(buf[:nBytes])
46 if err != nil {
47 log.Error("Failed to write to server")
48 }
49 <-closeChan
50 serverCtx.Kill()
51 }()
52
53 conType, setup, connectionChan, err := clientCtx.StartClient()
54 if err != nil {
55 t.Fatal("Test failed with error", err)
56 }
57 if conType != proto.CONNECTION_TYPE_PORT_FORWARD {
58 panic(fmt.Errorf("Invalid connection type %d", conType))
59 }
60
61 go func() {
62 for {
63 conn, ok := <-connectionChan
64 if !ok {
65 break
66 }
67 _ = conn.Reject()
68 _ = conn.Close()
69 }
70 }()
71

Callers

nothing calls this directly

Calls 13

KillMethod · 0.95
StartClientMethod · 0.95
NewConnectionTCPMethod · 0.95
AcceptMethod · 0.80
FatalMethod · 0.80
RejectMethod · 0.80
FatalfMethod · 0.80
ErrorMethod · 0.65
ReadMethod · 0.65
WriteMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected