mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
The cache renderer and twelve unit tests built their Jinja2 environments with autoescape=False (CodeQL py/jinja2/autoescape-false, alert 958 and fifteen test alerts) behind `# noqa: S701` markers. They now use select_autoescape(default_for_string=False), the form the repository already uses in over forty other modules. Every template the cache renderer loads ends in .j2, so nothing is escaped: its output stays byte-identical for all five distros, also with markup characters injected into every variable, while a control run with autoescape=True differs in exactly those injected cases. 🎯 Fix: 95 % 💥 Break: 2 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 93 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from jinja2 import Environment, StrictUndefined, select_autoescape
|
|
from psycopg2.extensions import parse_dsn
|
|
|
|
from utils.cache.yaml import load_yaml
|
|
from utils.roles.mapping import ROLE_FILE_VARS_MAIN
|
|
|
|
from . import PROJECT_ROOT
|
|
|
|
_ROLE_VARS = PROJECT_ROOT / "roles/web-app-baserow" / ROLE_FILE_VARS_MAIN
|
|
_SWARM_IPVS_IDLE_TIMEOUT_SECONDS = 900
|
|
|
|
|
|
class TestDatabaseUrlKeepalive(unittest.TestCase):
|
|
def _connection_parameters(self) -> dict[str, str]:
|
|
env = Environment(
|
|
undefined=StrictUndefined,
|
|
autoescape=select_autoescape(default_for_string=False),
|
|
)
|
|
url = env.from_string(
|
|
load_yaml(str(_ROLE_VARS))["BASEROW_DATABASE_URL"]
|
|
).render(
|
|
BASEROW_DATABASE_USER="baserow",
|
|
BASEROW_DATABASE_PASSWORD="placeholder",
|
|
BASEROW_DATABASE_HOST="postgres",
|
|
BASEROW_DATABASE_PORT="5432",
|
|
BASEROW_DATABASE_NAME="baserow",
|
|
)
|
|
return parse_dsn(url)
|
|
|
|
def test_idle_connection_is_probed_before_the_swarm_vip_forgets_it(self) -> None:
|
|
params = self._connection_parameters()
|
|
self.assertEqual(params.get("keepalives"), "1")
|
|
self.assertLess(
|
|
int(params["keepalives_idle"]),
|
|
_SWARM_IPVS_IDLE_TIMEOUT_SECONDS,
|
|
"an idle connection through the swarm service VIP is dropped after "
|
|
f"{_SWARM_IPVS_IDLE_TIMEOUT_SECONDS}s without traffic",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|