@@ -3,12 +3,14 @@ package proxy
33import (
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+
121190func TestTLSVerifyClientCertDifferentCAs (t * testing.T ) {
122191 a := assert .New (t )
123192
0 commit comments