Coverage for execution/live_credentials.py: 100%
11 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
1"""Pure validation over loaded live-broker credentials (Phase V2-22).
3No I/O here on purpose - see execution/live_credentials_io.py for how
4credentials actually get loaded (from ib_config.py or AETHER_IB_* env vars).
5This module only decides whether what was loaded is complete enough to
6consider live_credentials_present=True for execution.paper_readiness's
7evaluate_live_broker_config().
8"""
10from __future__ import annotations
12REQUIRED_FIELDS = ("ib_account", "ib_user_name", "ib_password")
14# The Postgres password docker-compose.yml / the DSN defaults ship with. Safe
15# for local dev but published in the public repo, so it is effectively no
16# password at all - live mode must refuse to run against it. Keep in sync with
17# docker-compose.yml's ${POSTGRES_PASSWORD:-aether_dev_password} default.
18DEFAULT_DEV_DB_PASSWORD = "aether_dev_password"
21def credentials_present(credentials: dict) -> bool:
22 """True only if every field in REQUIRED_FIELDS is a non-empty string."""
23 return all(str(credentials.get(field, "")).strip() for field in REQUIRED_FIELDS)
26def describe_missing_fields(credentials: dict) -> list[str]:
27 return [field for field in REQUIRED_FIELDS if not str(credentials.get(field, "")).strip()]
30def postgres_dsn_is_live_safe(dsn: str) -> bool:
31 """False if the DSN is empty or still carries the published dev-default
32 password - either case is unacceptable for a live deployment. An empty DSN
33 is treated as unsafe so a missing/unconfigured value fails closed. A DSN
34 that simply omits a password (e.g. peer/trust auth) is considered safe -
35 only the known-published default is rejected."""
36 if not str(dsn).strip():
37 return False
38 return DEFAULT_DEV_DB_PASSWORD not in dsn