Skip to content

Commit 01b09e7

Browse files
committed
Dialer and Socks5 proxy tests
1 parent 79c2a10 commit 01b09e7

File tree

14 files changed

+1158
-9
lines changed

14 files changed

+1158
-9
lines changed

Gopkg.lock

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proxy/auth_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ import (
77
"fmt"
88
"github.com/grepplabs/kafka-proxy/pkg/apis"
99
"github.com/stretchr/testify/assert"
10+
"net"
1011
"testing"
1112
"time"
1213
)
1314

1415
func TestAuthHandshake(t *testing.T) {
1516
a := assert.New(t)
17+
testAuthHandshake(a, makePipe)
18+
}
19+
20+
func TestAuthHandshakeSocks5(t *testing.T) {
21+
a := assert.New(t)
22+
testAuthHandshake(a, makeSocks5Pipe)
23+
}
1624

25+
func testAuthHandshake(a *assert.Assertions, mp func() (c1, c2 net.Conn, stop func(), err error)) {
1726
magic, err := RandomUint64()
1827
a.Nil(err)
1928

@@ -36,15 +45,14 @@ func TestAuthHandshake(t *testing.T) {
3645
tokenProvider: tokenProvider,
3746
}
3847

39-
//TODO: implement verify
4048
server := &AuthServer{
4149
enabled: true,
4250
magic: magic,
4351
method: "google-id",
4452
timeout: 10 * time.Second,
4553
tokenInfo: tokenInfo,
4654
}
47-
c1, c2, stop, err := makePipe()
55+
c1, c2, stop, err := mp()
4856
a.Nil(err)
4957
defer stop()
5058

proxy/tls_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package proxy
33
import (
44
"bytes"
55
"crypto/x509"
6+
"github.com/armon/go-socks5"
67
"github.com/grepplabs/kafka-proxy/config"
78
"github.com/pkg/errors"
89
"github.com/stretchr/testify/assert"
910
"io"
1011
"net"
1112
"os"
13+
"strings"
1214
"testing"
1315
"time"
1416
)
@@ -118,6 +120,73 @@ func TestTLSSelfSigned(t *testing.T) {
118120
pingPong(t, c1, c2)
119121
}
120122

123+
func TestTLSThroughSocks5(t *testing.T) {
124+
a := assert.New(t)
125+
126+
bundle := NewCertsBundle()
127+
defer bundle.Close()
128+
129+
c := new(config.Config)
130+
c.Proxy.TLS.ListenerCertFile = bundle.ServerCert.Name()
131+
c.Proxy.TLS.ListenerKeyFile = bundle.ServerKey.Name()
132+
c.Kafka.TLS.CAChainCertFile = bundle.ServerCert.Name()
133+
134+
c1, c2, stop, err := makeTLSSocks5Pipe(c, nil, "", "")
135+
if err != nil {
136+
a.FailNow(err.Error())
137+
}
138+
defer stop()
139+
pingPong(t, c1, c2)
140+
}
141+
142+
func TestTLSThroughSocks5WithCredentials(t *testing.T) {
143+
a := assert.New(t)
144+
145+
bundle := NewCertsBundle()
146+
defer bundle.Close()
147+
148+
c := new(config.Config)
149+
c.Proxy.TLS.ListenerCertFile = bundle.ServerCert.Name()
150+
c.Proxy.TLS.ListenerKeyFile = bundle.ServerKey.Name()
151+
c.Kafka.TLS.CAChainCertFile = bundle.ServerCert.Name()
152+
153+
authenticator := &socks5.UserPassAuthenticator{
154+
Credentials: testCredentials{
155+
username: "test-user",
156+
password: "test-password",
157+
},
158+
}
159+
c1, c2, stop, err := makeTLSSocks5Pipe(c, authenticator, "test-user", "test-password")
160+
if err != nil {
161+
a.FailNow(err.Error())
162+
}
163+
defer stop()
164+
pingPong(t, c1, c2)
165+
}
166+
167+
func TestTLSThroughSocks5WithBadCredentials(t *testing.T) {
168+
a := assert.New(t)
169+
170+
bundle := NewCertsBundle()
171+
defer bundle.Close()
172+
173+
c := new(config.Config)
174+
c.Proxy.TLS.ListenerCertFile = bundle.ServerCert.Name()
175+
c.Proxy.TLS.ListenerKeyFile = bundle.ServerKey.Name()
176+
c.Kafka.TLS.CAChainCertFile = bundle.ServerCert.Name()
177+
178+
authenticator := &socks5.UserPassAuthenticator{
179+
Credentials: testCredentials{
180+
username: "test-user",
181+
password: "test-password",
182+
},
183+
}
184+
_, _, _, err := makeTLSSocks5Pipe(c, authenticator, "test-user", "bad-password")
185+
a.NotNil(err)
186+
a.True(strings.HasPrefix(err.Error(), "proxy: SOCKS5 proxy at"))
187+
a.True(strings.HasSuffix(err.Error(), "rejected username/password"))
188+
}
189+
121190
func TestTLSVerifyClientCertDifferentCAs(t *testing.T) {
122191
a := assert.New(t)
123192

0 commit comments

Comments
 (0)