Merge branch 'main' into feature/store-i18n

This commit is contained in:
kevinveenbirkenbach committed 2026-10-08 19:52:53 +02:00
commit cb74bb73ec
21 files changed
+372 -28

No files matched your search

@@ -0,0 +1,49 @@
"""phpredis reads ``auth[user]``/``auth[pass]`` and ``prefix`` from the query of
``session.save_path``; a password with a reserved character that is not
percent-encoded splits the query and the handler authenticates with a fragment.
"""
from __future__ import annotations
import importlib
import unittest
from urllib.parse import parse_qs, urlsplit
plugin_module = importlib.import_module("plugins.lookup.engine")
redis_session_path = plugin_module.redis_session_path
class TestRedisSessionPath(unittest.TestCase):
def test_an_embedded_sidecar_gets_no_credentials(self) -> None:
self.assertEqual(
"tcp://redis:6379?prefix=suitecrm:session:",
redis_session_path("redis", 6379, "suitecrm", "", ""),
)
def test_a_shared_redis_gets_user_and_password(self) -> None:
query = parse_qs(
urlsplit(
redis_session_path("redis-central", 6379, "suitecrm", "default", "pw")
).query
)
self.assertEqual(["default"], query["auth[user]"])
self.assertEqual(["pw"], query["auth[pass]"])
def test_a_password_with_reserved_characters_survives_the_query(self) -> None:
password = "a&b=c?d#e/f+g h"
query = parse_qs(
urlsplit(
redis_session_path("redis-central", 6379, "suitecrm", "default", password)
).query
)
self.assertEqual([password], query["auth[pass]"])
self.assertEqual(["suitecrm:session:"], query["prefix"])
def test_a_user_without_a_password_is_not_sent(self) -> None:
self.assertNotIn(
"auth", redis_session_path("redis", 6379, "suitecrm", "default", "")
)
if __name__ == "__main__":
unittest.main()
Whitespace-only changes.
@@ -0,0 +1,62 @@
from __future__ import annotations
import unittest
from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoescape
from utils.cache.files import PROJECT_ROOT
from utils.cache.yaml import load_yaml_str
TEMPLATE_DIR = PROJECT_ROOT / "roles/web-app-prometheus/templates/configuration"
def ready_module(*, tls_mode: str, prometheus_tls: bool, ca_injected: bool) -> dict:
def lookup(name, *terms):
if name == "tls" and terms[1] == "enabled":
return prometheus_tls
if name == "ca_injected":
return ca_injected
raise AssertionError(f"the template calls an unexpected lookup: {name!r}")
env = Environment(
loader=FileSystemLoader(str(TEMPLATE_DIR)),
undefined=StrictUndefined,
autoescape=select_autoescape(),
)
env.filters["bool"] = bool
rendered = env.get_template("blackbox.yml.j2").render(
lookup=lookup,
application_id="web-app-prometheus",
TLS_MODE=tls_mode,
)
return load_yaml_str(rendered)["modules"]["http_ready"]["http"]
class TestBlackboxReadyModule(unittest.TestCase):
def test_an_http_target_passes_while_prometheus_itself_uses_tls(self):
module = ready_module(
tls_mode="letsencrypt", prometheus_tls=True, ca_injected=False
)
self.assertIs(module["fail_if_not_ssl"], False)
def test_certificates_are_verified_while_prometheus_itself_has_no_tls(self):
module = ready_module(
tls_mode="letsencrypt", prometheus_tls=False, ca_injected=False
)
self.assertIs(module["tls_config"]["insecure_skip_verify"], False)
def test_certificates_are_verified_once_the_private_ca_is_mounted(self):
module = ready_module(
tls_mode="self_signed", prometheus_tls=True, ca_injected=True
)
self.assertIs(module["tls_config"]["insecure_skip_verify"], False)
def test_verification_is_skipped_only_without_the_private_ca(self):
module = ready_module(
tls_mode="self_signed", prometheus_tls=False, ca_injected=False
)
self.assertIs(module["tls_config"]["insecure_skip_verify"], True)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,84 @@
from __future__ import annotations
import unittest
from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoescape
from utils.cache.files import PROJECT_ROOT
from utils.cache.yaml import load_yaml_str
TEMPLATE_DIR = PROJECT_ROOT / "roles/web-app-prometheus/templates/configuration"
ONION = "a" * 56 + ".onion"
DOMAINS = {
"web-app-prometheus": [f"prometheus.{ONION}"],
"web-app-nextcloud": {"nextcloud": f"next.cloud.{ONION}"},
"web-app-gitea": ["git.infinito.test"],
"web-svc-cdn": ["cdn.infinito.test"],
"svc-db-postgres": ["postgres.infinito.test"],
}
ROLES_WITH_THE_PROMETHEUS_SERVICE = ["web-app-nextcloud", "web-app-gitea"]
def lookup(name, *terms, **_kwargs):
if name == "domains":
return DOMAINS
if name == "roles_with_service":
return [{"id": role} for role in ROLES_WITH_THE_PROMETHEUS_SERVICE]
if name == "tls":
term, want = terms
scheme = "http" if term.endswith(".onion") else "https"
return {
"url.base": f"{scheme}://{term}/",
"protocols.web": "http",
"enabled": False,
}[want]
if name == "domain":
return DOMAINS[terms[0]][0]
if name == "scrape_target":
return f"{terms[1]}:9000"
if name == "native_metrics_apps":
return []
raise AssertionError(f"the template calls an unexpected lookup: {name!r}")
def probed_targets() -> dict[str, list[str]]:
env = Environment(
loader=FileSystemLoader(str(TEMPLATE_DIR)),
undefined=StrictUndefined,
autoescape=select_autoescape(),
)
env.filters["bool"] = bool
rendered = env.get_template("prometheus.yml.j2").render(
lookup=lookup,
application_id="web-app-prometheus",
CURRENT_PLAY_APPLICATIONS=list(DOMAINS),
DOMAIN_PRIMARY="infinito.test",
ALERT_RULES_CONFIG_DOCKER="/etc/prometheus/alert_rules.yml",
)
jobs = {job["job_name"]: job for job in load_yaml_str(rendered)["scrape_configs"]}
return {
group["labels"]["app"]: group["targets"]
for group in jobs["blackbox-healthz"]["static_configs"]
}
class TestBlackboxTargets(unittest.TestCase):
def test_an_onion_app_is_probed_under_its_onion_name_over_http(self):
self.assertEqual(
probed_targets()["web-app-nextcloud"],
[f"http://next.cloud.{ONION}/healthz/ready"],
)
def test_a_clearnet_app_is_probed_under_its_own_scheme(self):
self.assertEqual(
probed_targets()["web-app-gitea"],
["https://git.infinito.test/healthz/ready"],
)
def test_only_the_roles_the_service_lookup_names_are_probed(self):
self.assertEqual(set(probed_targets()), set(ROLES_WITH_THE_PROMETHEUS_SERVICE))
if __name__ == "__main__":
unittest.main()