Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
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
61 changes: 50 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,73 @@ jobs:

test:
name: Test
runs-on: ubuntu-latest
runs-on: ubuntu-18.04

strategy:
fail-fast: false
matrix:
go_version: [1.14, 1.15]
pg_version: [9.6, 10, 11, 12, 13]
go-version: [1.15, 1.16]
pg-version: [9.6, 10, 11, 12, 13, cockroachdb]
include:
- pg-version: 9.6
pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test"
pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require
pgx-test-md5-password-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-plain-password-conn-string: postgres://pgx_pw:secret@127.0.0.1/pgx_test
- pg-version: 10
pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test"
pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require
pgx-test-md5-password-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-plain-password-conn-string: postgres://pgx_pw:secret@127.0.0.1/pgx_test
- pg-version: 11
pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test"
pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require
pgx-test-md5-password-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-plain-password-conn-string: postgres://pgx_pw:secret@127.0.0.1/pgx_test
- pg-version: 12
pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test"
pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require
pgx-test-md5-password-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-plain-password-conn-string: postgres://pgx_pw:secret@127.0.0.1/pgx_test
- pg-version: 13
pgx-test-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-unix-socket-conn-string: "host=/var/run/postgresql dbname=pgx_test"
pgx-test-tcp-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-tls-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require
pgx-test-md5-password-conn-string: postgres://pgx_md5:secret@127.0.0.1/pgx_test
pgx-test-plain-password-conn-string: postgres://pgx_pw:secret@127.0.0.1/pgx_test
- pg-version: cockroachdb
pgx-test-conn-string: "postgresql://root@127.0.0.1:26257/pgx_test?sslmode=disable&experimental_enable_temp_tables=on"

steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go_version }}
go-version: ${{ matrix.go-version }}

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Setup database server for testing
run: ci/setup_test.bash
env:
PGVERSION: ${{ matrix.pg_version }}
PGVERSION: ${{ matrix.pg-version }}

- name: Test
run: go test -v -race ./...
env:
PGX_TEST_CONN_STRING: postgres://pgx_md5:secret@127.0.0.1/pgx_test
PGX_TEST_UNIX_SOCKET_CONN_STRING: "host=/var/run/postgresql dbname=pgx_test"
PGX_TEST_TCP_CONN_STRING: postgres://pgx_md5:secret@127.0.0.1/pgx_test
PGX_TEST_TLS_CONN_STRING: postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require
PGX_TEST_MD5_PASSWORD_CONN_STRING: postgres://pgx_md5:secret@127.0.0.1/pgx_test
PGX_TEST_PLAIN_PASSWORD_CONN_STRING: postgres://pgx_pw:secret@127.0.0.1/pgx_test
PGX_TEST_CONN_STRING: ${{ matrix.pgx-test-conn-string }}
PGX_TEST_UNIX_SOCKET_CONN_STRING: ${{ matrix.pgx-test-unix-socket-conn-string }}
PGX_TEST_TCP_CONN_STRING: ${{ matrix.pgx-test-tcp-conn-string }}
PGX_TEST_TLS_CONN_STRING: ${{ matrix.pgx-test-tls-conn-string }}
PGX_TEST_MD5_PASSWORD_CONN_STRING: ${{ matrix.pgx-test-md5-password-conn-string }}
PGX_TEST_PLAIN_PASSWORD_CONN_STRING: ${{ matrix.pgx-test-plain-password-conn-string }}
6 changes: 3 additions & 3 deletions auth_scram.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
"strconv"

"github.com/jackc/pgproto3/v2"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/text/secure/precis"
errors "golang.org/x/xerrors"
)

const clientNonceLen = 18
Expand Down Expand Up @@ -192,12 +192,12 @@ func (sc *scramClient) recvServerFirstMessage(serverFirstMessage []byte) error {
var err error
sc.salt, err = base64.StdEncoding.DecodeString(string(saltStr))
if err != nil {
return errors.Errorf("invalid SCRAM salt received from server: %w", err)
return fmt.Errorf("invalid SCRAM salt received from server: %w", err)
}

sc.iterations, err = strconv.Atoi(string(iterationsStr))
if err != nil || sc.iterations <= 0 {
return errors.Errorf("invalid SCRAM iteration count received from server: %w", err)
return fmt.Errorf("invalid SCRAM iteration count received from server: %w", err)
}

if !bytes.HasPrefix(sc.clientAndServerNonce, sc.clientNonce) {
Expand Down
10 changes: 9 additions & 1 deletion ci/setup_test.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -eux

if [ "${PGVERSION-}" != "" ]
if [[ "${PGVERSION-}" =~ ^[0-9.]+$ ]]
then
sudo apt-get remove -y --purge postgresql libpq-dev libpq5 postgresql-client-common postgresql-common
sudo rm -rf /var/lib/postgresql
Expand Down Expand Up @@ -38,6 +38,14 @@ then
psql -U postgres -c "create user \" tricky, ' } \"\" \\ test user \" superuser password 'secret'"
fi

if [[ "${PGVERSION-}" =~ ^cockroach ]]
then
wget -qO- https://binaries.cockroachdb.com/cockroach-v20.2.5.linux-amd64.tgz | tar xvz
sudo mv cockroach-v20.2.5.linux-amd64/cockroach /usr/local/bin/
cockroach start-single-node --insecure --background --listen-addr=localhost
cockroach sql --insecure -e 'create database pgx_test'
fi

if [ "${CRATEVERSION-}" != "" ]
then
docker run \
Expand Down
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/jackc/pgpassfile"
"github.com/jackc/pgproto3/v2"
"github.com/jackc/pgservicefile"
errors "golang.org/x/xerrors"
)

type AfterConnectFunc func(ctx context.Context, pgconn *PgConn) error
Expand Down Expand Up @@ -409,7 +409,7 @@ func parseURLSettings(connString string) (map[string]string, error) {
}
h, p, err := net.SplitHostPort(host)
if err != nil {
return nil, errors.Errorf("failed to split host:port in '%s', err: %w", host, err)
return nil, fmt.Errorf("failed to split host:port in '%s', err: %w", host, err)
}
hosts = append(hosts, h)
ports = append(ports, p)
Expand Down Expand Up @@ -617,7 +617,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) {
caPath := sslrootcert
caCert, err := ioutil.ReadFile(caPath)
if err != nil {
return nil, errors.Errorf("unable to read CA file: %w", err)
return nil, fmt.Errorf("unable to read CA file: %w", err)
}

if !caCertPool.AppendCertsFromPEM(caCert) {
Expand All @@ -635,7 +635,7 @@ func configTLS(settings map[string]string) ([]*tls.Config, error) {
if sslcert != "" && sslkey != "" {
cert, err := tls.LoadX509KeyPair(sslcert, sslkey)
if err != nil {
return nil, errors.Errorf("unable to read cert: %w", err)
return nil, fmt.Errorf("unable to read cert: %w", err)
}

tlsConfig.Certificates = []tls.Certificate{cert}
Expand Down
3 changes: 1 addition & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package pgconn

import (
"context"
"errors"
"fmt"
"net"
"net/url"
"regexp"
"strings"

errors "golang.org/x/xerrors"
)

// SafeToRetry checks if the err is guaranteed to have occurred before sending any data to the server.
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ require (
github.com/stretchr/testify v1.5.1
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/text v0.3.3
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
)
5 changes: 3 additions & 2 deletions pgconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"crypto/tls"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"io"
"math"
"net"
Expand All @@ -16,7 +18,6 @@ import (
"github.com/jackc/pgconn/internal/ctxwatch"
"github.com/jackc/pgio"
"github.com/jackc/pgproto3/v2"
errors "golang.org/x/xerrors"
)

const (
Expand Down Expand Up @@ -1043,7 +1044,7 @@ func (pgConn *PgConn) execExtendedPrefix(ctx context.Context, paramValues [][]by
}

if len(paramValues) > math.MaxUint16 {
result.concludeCommand(nil, errors.Errorf("extended protocol limited to %v parameters", math.MaxUint16))
result.concludeCommand(nil, fmt.Errorf("extended protocol limited to %v parameters", math.MaxUint16))
result.closed = true
pgConn.unlock()
return result
Expand Down
6 changes: 2 additions & 4 deletions pgconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -17,12 +18,9 @@ import (
"testing"
"time"

"github.com/jackc/pgmock"

"github.com/jackc/pgconn"
"github.com/jackc/pgmock"
"github.com/jackc/pgproto3/v2"
errors "golang.org/x/xerrors"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down