fix(config): el error de SECRET_KEY no vuelca el entorno al log
pydantic incluía las variables de entorno (contraseñas demo) en el mensaje de validación; hide_input_in_errors lo evita.
This commit is contained in:
1 parent
b9ac60d9ae
commit
bfc27f6188
2 files changed
+16
-2
No files matched your search
+4
-1
@@ -19,7 +19,10 @@ CLAVES_DE_EJEMPLO = frozenset({"", "dev-solo-local-cambiar", "cambiar", "changem
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
||||
# hide_input_in_errors: un error de validación no debe volcar el entorno (contraseñas) al log.
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env", env_file_encoding="utf-8", extra="ignore", hide_input_in_errors=True
|
||||
)
|
||||
|
||||
app_env: Literal["dev", "test", "prod"] = Field(
|
||||
default="prod", description="Solo `test` permite arrancar sin SECRET_KEY."
|
||||
|
||||
+12
-1
@@ -34,6 +34,16 @@ def test_sin_secret_key_propia_las_settings_fallan(
|
||||
Settings(_env_file=None)
|
||||
|
||||
|
||||
def test_el_error_no_vuelca_las_contrasenas_del_entorno(
|
||||
entorno_limpio: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
entorno_limpio.setenv("DEMO_PASSWORD_OFICIAL", "contrasena-que-no-debe-salir")
|
||||
|
||||
with pytest.raises(ValidationError) as error:
|
||||
Settings(_env_file=None)
|
||||
assert "contrasena-que-no-debe-salir" not in str(error.value)
|
||||
|
||||
|
||||
def test_con_app_env_test_arranca_sin_secret_key(entorno_limpio: pytest.MonkeyPatch) -> None:
|
||||
entorno_limpio.setenv("APP_ENV", "test")
|
||||
|
||||
@@ -67,10 +77,11 @@ def _arrancar_app(tmp_path: Path, **extra: str) -> subprocess.CompletedProcess[s
|
||||
|
||||
|
||||
def test_sin_secret_key_la_app_no_levanta(tmp_path: Path) -> None:
|
||||
proceso = _arrancar_app(tmp_path)
|
||||
proceso = _arrancar_app(tmp_path, DEMO_PASSWORD_OFICIAL="contrasena-que-no-debe-salir")
|
||||
|
||||
assert proceso.returncode != 0
|
||||
assert "SECRET_KEY no está definida" in proceso.stderr
|
||||
assert "contrasena-que-no-debe-salir" not in proceso.stderr
|
||||
|
||||
|
||||
def test_con_app_env_test_la_app_levanta(tmp_path: Path) -> None:
|
||||
|
||||
Reference in new issue
Block a user