77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
"""Prod env checker: failures block deploys, warnings don't."""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
|
|
sys.path.insert(0, str(REPO_ROOT / "backend" / "scripts"))
|
|
|
|
from check_prod import check
|
|
|
|
|
|
def _good() -> dict:
|
|
return {
|
|
"CALLBACK_TOKEN": "t" * 40,
|
|
"JWT_SECRET": "j" * 40,
|
|
"LANGFLOW_API_KEY": "k" * 24,
|
|
"LFX_API_KEY": "x" * 24,
|
|
"LANGFLOW_SUPERUSER_PASSWORD": "p" * 20,
|
|
"LANGFLOW_SECRET_KEY": "s" * 40,
|
|
"FRONTEND_MODE": "preview",
|
|
"ADMIN_EMAILS": "admin@example.com",
|
|
"SMTP_HOST": "smtp.example.com",
|
|
"SMTP_PASSWORD": "secret",
|
|
"CONTACT_TO": "team@example.com",
|
|
"FRONTEND_URL": "https://example.com",
|
|
}
|
|
|
|
|
|
def test_good_env_passes_without_warnings():
|
|
failures, warnings = check(_good())
|
|
assert failures == []
|
|
assert warnings == []
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("key", "bad_value"),
|
|
[
|
|
("CALLBACK_TOKEN", ""),
|
|
("JWT_SECRET", ""),
|
|
("CALLBACK_TOKEN", "t" * 10),
|
|
("JWT_SECRET", "j" * 10),
|
|
("LANGFLOW_SUPERUSER_PASSWORD", "short"),
|
|
("LANGFLOW_SECRET_KEY", "s" * 10),
|
|
("LANGFLOW_API_KEY", "sk-"),
|
|
("LFX_API_KEY", "lfx-abc"),
|
|
("FRONTEND_MODE", "dev"),
|
|
("APP_ENV", "dev"),
|
|
("LANGFLOW_AUTO_LOGIN", "true"),
|
|
],
|
|
)
|
|
def test_bad_values_fail(key, bad_value):
|
|
values = _good()
|
|
values[key] = bad_value
|
|
failures, _ = check(values)
|
|
wanted = "AUTO_LOGIN" if key == "LANGFLOW_AUTO_LOGIN" else key
|
|
assert any(wanted in f for f in failures), failures
|
|
|
|
|
|
def test_soft_misconfigurations_warn_only():
|
|
values = _good()
|
|
values["ADMIN_EMAILS"] = ""
|
|
values["SMTP_PASSWORD"] = ""
|
|
values["CONTACT_TO"] = ""
|
|
values["FRONTEND_URL"] = "http://example.com"
|
|
failures, warnings = check(values)
|
|
assert failures == []
|
|
assert len(warnings) == 4
|
|
|
|
|
|
def test_example_file_would_not_pass():
|
|
from check_prod import parse_env
|
|
|
|
values = parse_env(REPO_ROOT / ".env.example")
|
|
failures, _ = check(values)
|
|
assert failures, "placeholders must be detectable"
|