Skip to content

fix(db): populated URL in getTestConnectionString to fix password injection#42

Merged
mfreed merged 1 commit into
mainfrom
fix/db-test-password-injection
May 24, 2026
Merged

fix(db): populated URL in getTestConnectionString to fix password injection#42
mfreed merged 1 commit into
mainfrom
fix/db-test-password-injection

Conversation

@mfreed
Copy link
Copy Markdown
Member

@mfreed mfreed commented May 24, 2026

NewClient's injectPasswordIntoConnStr requires user@host in the URL to inject the resolved password (from PGPASSWORD or password_command). getTestConnectionString previously returned the bare URL "postgres://localhost/postgres?sslmode=disable" and relied on pgx's env-var fallback for credentials. This broke whenever PGPASSWORD was set: NewClient errored with "connection string has no user@host format" before any test logic ran, blocking 75 tests in the db package from running against a local PostgreSQL with password auth.

Read PGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASE and construct a fully-populated URL with url.QueryEscape on credentials. Keep TEST_DATABASE_URL precedence intact for CI/CD environments that supply their own connection string.

Add unit tests covering: the populated-URL contract, the no-PGHOST skip path, TEST_DATABASE_URL precedence, and special-character escaping.

Before: 75 failed, 0 passed (against demo PG).
After: 0 failed, full db suite green.

…rd injection

NewClient's injectPasswordIntoConnStr requires user@host in the URL to
inject the resolved password (from PGPASSWORD or password_command).
getTestConnectionString previously returned the bare URL
"postgres://localhost/postgres?sslmode=disable" and relied on pgx's
env-var fallback for credentials. This broke whenever PGPASSWORD was
set: NewClient errored with "connection string has no user@host format"
before any test logic ran, blocking 75 tests in the db package from
running against a local PostgreSQL with password auth.

Read PGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASE and construct a
fully-populated URL with url.QueryEscape on credentials. Keep
TEST_DATABASE_URL precedence intact for CI/CD environments that supply
their own connection string.

Add unit tests covering: the populated-URL contract, the no-PGHOST skip
path, TEST_DATABASE_URL precedence, and special-character escaping.

Before: 75 failed, 0 passed (against demo PG).
After:  0 failed, full db suite green.
@mfreed mfreed merged commit 7606b16 into main May 24, 2026
2 checks passed
@mfreed mfreed deleted the fix/db-test-password-injection branch May 24, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant