github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/acceptance/testdata/psql/test-psql-unix.sh (about) 1 #!/usr/bin/env bash 2 3 CERTS_DIR=${CERTS_DIR:-/certs} 4 crdb=$1 5 trap "set -x; killall cockroach cockroachshort || true" EXIT HUP 6 7 set -euo pipefail 8 9 # Disable automatic network access by psql. 10 unset PGHOST 11 unset PGPORT 12 # Use root access. 13 export PGUSER=root 14 15 echo "Testing Unix socket connection via insecure server." 16 set -x 17 18 # Start an insecure CockroachDB server. 19 # We use a different port number from standard for an extra guarantee that 20 # "psql" is not going to find it. 21 "$crdb" start-single-node --background --insecure \ 22 --socket-dir=/tmp \ 23 --listen-addr=:12345 24 25 # Wait for server ready. 26 "$crdb" sql --insecure -e "select 1" -p 12345 27 28 # Verify that psql can connect to the server. 29 psql -h /tmp -p 12345 -c "select 1" | grep "1 row" 30 31 # It worked. 32 "$crdb" quit --insecure -p 12345 33 sleep 1; killall -9 cockroach cockroachshort || true 34 35 set +x 36 echo "Testing Unix socket connection via secure server." 37 set -x 38 39 # Restart the server in secure mode. 40 "$crdb" start-single-node --background \ 41 --certs-dir="$CERTS_DIR" --socket-dir=/tmp \ 42 --listen-addr=:12345 43 44 # Wait for server ready; also create a user that can log in. 45 "$crdb" sql --certs-dir="$CERTS_DIR" -e "create user foo with password 'pass'" -p 12345 46 47 # Also verify that psql can connect to the server. 48 env PGPASSWORD=pass psql -U foo -h /tmp -p 12345 -c "select 1" | grep "1 row" 49 50 set +x 51 # Done. 52 "$crdb" quit --certs-dir="$CERTS_DIR" -p 12345