Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions pkg/ccl/sqlproxyccl/proxy_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestProxyProtocol(t *testing.T) {
sqlDB.Exec(t, `CREATE USER bob WITH PASSWORD 'builder'`)

var validateFn func(h *proxyproto.Header) error
withProxyProtocol := func(p bool) (server *Server, addrs *serverAddresses) {
withProxyProtocol := func(p bool, stopper *stop.Stopper) (server *Server, addrs *serverAddresses) {
options := &ProxyOptions{
RoutingRule: ts.AdvSQLAddr(),
SkipVerify: true,
Expand All @@ -171,7 +171,7 @@ func TestProxyProtocol(t *testing.T) {
options.testingKnobs.validateProxyHeader = func(h *proxyproto.Header) error {
return validateFn(h)
}
return newSecureProxyServer(ctx, t, sql.Stopper(), options)
return newSecureProxyServer(ctx, t, stopper, options)
}

timeout := 3 * time.Second
Expand Down Expand Up @@ -228,11 +228,10 @@ func TestProxyProtocol(t *testing.T) {
})()

testSQLNoRequiredProxyProtocol := func(s *Server, addr string) {
url := fmt.Sprintf("postgres://bob:builder@%s/tenant-cluster-42.defaultdb?sslmode=require", addr)
url := fmt.Sprintf("postgres://bob:builder@%s/tenant-cluster-42.defaultdb?sslmode=require&sslrootcert=%s", addr, datapathutils.TestDataPath(t, "testserver.crt"))
// No proxy protocol.
te.TestConnect(ctx, t, url,
func(conn *pgx.Conn) {
t.Log("B")
require.NotZero(t, s.metrics.CurConnCount.Value())
require.NoError(t, runTestQuery(ctx, conn))
},
Expand All @@ -247,7 +246,7 @@ func TestProxyProtocol(t *testing.T) {
}

testSQLRequiredProxyProtocol := func(s *Server, addr string) {
url := fmt.Sprintf("postgres://bob:builder@%s/tenant-cluster-42.defaultdb?sslmode=require", addr)
url := fmt.Sprintf("postgres://bob:builder@%s/tenant-cluster-42.defaultdb?sslmode=require&sslrootcert=%s", addr, datapathutils.TestDataPath(t, "testserver.crt"))
// No proxy protocol.
_ = te.TestConnectErr(ctx, t, url, codeClientReadFailed, "tls error")
// Proxy protocol.
Expand All @@ -264,7 +263,9 @@ func TestProxyProtocol(t *testing.T) {
}

t.Run("server doesn't require proxy protocol", func(t *testing.T) {
s, addrs := withProxyProtocol(false)
stopper := stop.NewStopper()
defer stopper.Stop(ctx)
s, addrs := withProxyProtocol(false, stopper)
// Test SQL on the default listener. Both should go through.
testSQLNoRequiredProxyProtocol(s, addrs.listenAddr)
// Test SQL on the proxy protocol listener. Only request with PROXY should go
Expand All @@ -279,7 +280,9 @@ func TestProxyProtocol(t *testing.T) {
})

t.Run("server requires proxy protocol", func(t *testing.T) {
s, addrs := withProxyProtocol(true)
stopper := stop.NewStopper()
defer stopper.Stop(ctx)
s, addrs := withProxyProtocol(true, stopper)
// Test SQL on the default listener. Both should go through.
testSQLRequiredProxyProtocol(s, addrs.listenAddr)
// Test SQL on the proxy protocol listener. Only request with PROXY should go
Expand Down