mirror of https://github.com/jackc/pgx.git
Test TLS connection with pg_stat_ssl
Because of the nbconn wrapper it is no longer possible to check if the conn is a *tls.Conn directly. This is actually a more reliable test anyway.pull/1281/head
parent
82ca09e645
commit
125ee9670e
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -66,9 +65,11 @@ func TestConnectTLS(t *testing.T) {
|
||||||
conn, err := pgconn.Connect(context.Background(), connString)
|
conn, err := pgconn.Connect(context.Background(), connString)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if _, ok := conn.Conn().(*tls.Conn); !ok {
|
result := conn.ExecParams(context.Background(), `select ssl from pg_stat_ssl where pg_backend_pid() = pid;`, nil, nil, nil, nil).Read()
|
||||||
t.Error("not a TLS connection")
|
require.NoError(t, result.Err)
|
||||||
}
|
require.Len(t, result.Rows, 1)
|
||||||
|
require.Len(t, result.Rows[0], 1)
|
||||||
|
require.Equalf(t, "t", string(result.Rows[0][0]), "not a TLS connection")
|
||||||
|
|
||||||
closeConn(t, conn)
|
closeConn(t, conn)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue