MCPcopy
hub / github.com/probelabs/goreplay / TestTCPInputSecure

Function TestTCPInputSecure

input_tcp_test.go:83–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestTCPInputSecure(t *testing.T) {
84 serverCertPem, serverPrivPem := genCertificate(&x509.Certificate{
85 DNSNames: []string{"localhost"},
86 IPAddresses: []net.IP{net.ParseIP("127.0.0.1"), net.ParseIP("::")},
87 })
88
89 serverCertPemFile, _ := ioutil.TempFile("", "server.crt")
90 serverCertPemFile.Write(serverCertPem)
91 serverCertPemFile.Close()
92
93 serverPrivPemFile, _ := ioutil.TempFile("", "server.key")
94 serverPrivPemFile.Write(serverPrivPem)
95 serverPrivPemFile.Close()
96
97 defer func() {
98 os.Remove(serverPrivPemFile.Name())
99 os.Remove(serverCertPemFile.Name())
100 }()
101
102 wg := new(sync.WaitGroup)
103
104 input := NewTCPInput("127.0.0.1:0", &TCPInputConfig{
105 Secure: true,
106 CertificatePath: serverCertPemFile.Name(),
107 KeyPath: serverPrivPemFile.Name(),
108 })
109 output := NewTestOutput(func(*Message) {
110 wg.Done()
111 })
112
113 plugins := &InOutPlugins{
114 Inputs: []PluginReader{input},
115 Outputs: []PluginWriter{output},
116 }
117 plugins.All = append(plugins.All, input, output)
118
119 emitter := NewEmitter()
120 go emitter.Start(plugins, Settings.Middleware)
121
122 conf := &tls.Config{
123 InsecureSkipVerify: true,
124 }
125
126 conn, err := tls.Dial("tcp", input.listener.Addr().String(), conf)
127 if err != nil {
128 t.Fatal(err)
129 }
130 defer conn.Close()
131
132 msg := []byte("1 1 1\nGET / HTTP/1.1\r\n\r\n")
133
134 for i := 0; i < 100; i++ {
135 wg.Add(1)
136 conn.Write(msg)
137 conn.Write([]byte(payloadSeparator))
138 }
139
140 wg.Wait()

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
CloseMethod · 0.95
genCertificateFunction · 0.85
NewTCPInputFunction · 0.85
NewTestOutputFunction · 0.85
NewEmitterFunction · 0.85
WriteMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected