fix(svc-cache-package): serve HTTP/2 on TLS listeners behind the platform switch

The package-cache frontend rendered its TLS server blocks without an http2 directive, so re-enabling WEBSERVER_HTTP2_ENABLED after the OpenResty CVE fix would still leave every cached HTTPS host on HTTP/1.1. The template now emits http2 on; for TLS listeners when the switch is on, fail-closed for string overrides from extra vars. The dev-stack renderer reads the same switch from group_vars/all/04_webserver.yml, so both renderers stay in step. Plain listeners never get HTTP/2.

Refs #2245, builds on #2237.

🎯 Fix: 93 %
💥 Break: 3 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 90
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-11-19 15:34:39 +00:00
1 parent 8f551186c6
commit d84d87b46c
3 files changed
+47

No files matched your search

+38
View File
@@ -11,6 +11,7 @@ import stat
import tempfile
import unittest
from pathlib import Path
from unittest import mock
from utils.cache.hosts import host_records
from utils.cache.render import _write, upstreams_conf
@@ -88,5 +89,42 @@ class TestOllamaRegistry(unittest.TestCase):
self.assertNotIn("location /v2/", block)
def _servers(http2: bool | str) -> tuple[list[str], list[str]]:
"""Return the TLS and the plain server blocks of the rendered frontend.
Args:
http2: the value ``WEBSERVER_HTTP2_ENABLED`` is rendered with.
"""
with mock.patch("utils.cache.render._webserver_http2", return_value=http2):
blocks = upstreams_conf().split("server {")[1:]
tls = [block for block in blocks if " ssl;" in block]
return tls, [block for block in blocks if " ssl;" not in block]
class TestHttp2(unittest.TestCase):
def test_no_listener_serves_http2_while_the_switch_is_off(self) -> None:
tls, plain = _servers(False)
self.assertTrue(tls)
self.assertFalse([block for block in tls + plain if "http2" in block])
def test_every_tls_listener_serves_http2_once_the_switch_is_on(self) -> None:
tls, _plain = _servers(True)
self.assertTrue(tls)
self.assertEqual([block for block in tls if "\n\thttp2 on;\n" not in block], [])
def test_a_string_false_from_extra_vars_keeps_http2_off(self) -> None:
tls, _plain = _servers("false")
self.assertFalse([block for block in tls if "http2" in block])
def test_a_plain_listener_never_serves_http2(self) -> None:
_tls, plain = _servers(True)
self.assertTrue(plain)
self.assertFalse([block for block in plain if "http2" in block])
if __name__ == "__main__":
unittest.main()