fix(agent): quote DSN values and drop deprecated testcontainers import
This commit is contained in:
@@ -12,9 +12,13 @@ _MIGRATIONS_DIR = Path(__file__).parent / "migrations"
|
|||||||
|
|
||||||
|
|
||||||
def _dsn(cfg: AgentConfig, dbname: str) -> str:
|
def _dsn(cfg: AgentConfig, dbname: str) -> str:
|
||||||
return (
|
from psycopg import conninfo
|
||||||
f"host={cfg.db_host} port={cfg.db_port} dbname={dbname} "
|
return conninfo.make_conninfo(
|
||||||
f"user={cfg.db_user} password={cfg.db_password}"
|
host=cfg.db_host,
|
||||||
|
port=cfg.db_port,
|
||||||
|
dbname=dbname,
|
||||||
|
user=cfg.db_user,
|
||||||
|
password=cfg.db_password,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from testcontainers.postgres import PostgresContainer
|
from testcontainers.community.postgres import PostgresContainer
|
||||||
|
|
||||||
from agent.config import AgentConfig
|
from agent.config import AgentConfig
|
||||||
|
|
||||||
|
|||||||
@@ -37,3 +37,25 @@ def test_sync_runs_rejects_bad_status(cfg):
|
|||||||
"INSERT INTO sync_runs (connector, started_at, status)"
|
"INSERT INTO sync_runs (connector, started_at, status)"
|
||||||
" VALUES ('x', now(), 'bogus')"
|
" VALUES ('x', now(), 'bogus')"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_agent_dsn_escapes_password_with_space_and_quote():
|
||||||
|
import psycopg
|
||||||
|
from agent.config import AgentConfig
|
||||||
|
from agent.db import agent_dsn
|
||||||
|
|
||||||
|
cfg = AgentConfig(
|
||||||
|
db_host="localhost",
|
||||||
|
db_port=5432,
|
||||||
|
db_user="testuser",
|
||||||
|
db_password="pa ss'word", # password with space and single quote
|
||||||
|
agent_db_name="testdb",
|
||||||
|
firefly_url="http://firefly.test",
|
||||||
|
firefly_token="test-token",
|
||||||
|
heartbeat_interval_minutes=60,
|
||||||
|
)
|
||||||
|
|
||||||
|
dsn = agent_dsn(cfg)
|
||||||
|
# Parse DSN and verify password is preserved correctly
|
||||||
|
parsed = psycopg.conninfo.conninfo_to_dict(dsn)
|
||||||
|
assert parsed["password"] == "pa ss'word"
|
||||||
|
|||||||
Reference in New Issue
Block a user