From f287322065784610e6abb41ab5d1101aa2d014d2 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 30 Oct 2026 21:52:35 +0100 Subject: [PATCH] fix(objstore): serve public bucket files same-origin on every vhost of the consumer WordPress put objstore.public_url, the clearnet api.seaweedfs.s3 host, into S3_UPLOADS_BUCKET_URL, so the onion pass of WordPress#0 (CI run 40979252521) loaded the site logo from clearnet and the leak spec failed; the /objstore rebase only fired on onion-only consumers and never on a multi-network node. lookup('objstore', app, 'relative_url') now returns /_infinito/objstore/ for a shared consumer with a public bucket and an API domain, and locations.conf.j2 serves that path on every vhost of the consumer, clearnet and onion alike, by proxying over the loopback to the provider's own vhost. The route passes GET and HEAD only, answers 404 for a path ending in / (no ListObjects), drops the query string (no S3 subresources or presigned queries) and the Authorization and Cookie headers, so only the public bucket's anonymous read applies, and adds nosniff plus a sandbox CSP; private and embedded buckets get no route. Only web-app-wordpress switches to relative_url: mastodon, pixelfed, baserow, bookwyrm, snipe-it, listmonk, mediawiki, shopware and peertube need absolute URLs for federation, mail or server-side rendering, and decidim and funkwhale sign URLs, which the route deliberately refuses. The prefix moves from /objstore to /_infinito/objstore. Co-Authored-By: Claude Opus 5.5 --- docs/contributing/design/network_modes.md | 1 + plugins/lookup/objstore.py | 11 +- roles/web-app-wordpress/templates/env.j2 | 2 +- roles/web-svc-seaweedfs/README.md | 5 + .../templates/nginx/locations.conf.j2 | 17 ++- .../python/plugins/lookup/test_objstore.py | 88 +++++++++-- .../web-app-wordpress/test_s3_public_url.py | 124 +++++++++++++++ .../test_objstore_location.py | 142 ++++++++++++++++++ 8 files changed, 371 insertions(+), 19 deletions(-) create mode 100644 tests/unit/python/roles/web-app-wordpress/test_s3_public_url.py create mode 100644 tests/unit/python/roles/web-svc-seaweedfs/test_objstore_location.py diff --git a/docs/contributing/design/network_modes.md b/docs/contributing/design/network_modes.md index 0b72f57e03..90972dec61 100644 --- a/docs/contributing/design/network_modes.md +++ b/docs/contributing/design/network_modes.md @@ -64,6 +64,7 @@ A value that names an own or peer host MUST point to the network of the vhost th |---|---|---| | Allowlist a peer checks (OIDC redirect and post-logout URIs, web origins, Collabora `aliasgroupN`, trusted domains, CSP sources) | Union of every sibling, rendered once | `lookup('network_urls', url)` for a URL, a loop over `lookup('network_siblings', domain)` when each entry needs its own scheme or port | | Asset a browser loads (logo, icon, manifest icon, CDN file) | Same-origin path | `lookup('design', ...).relative_urls`, `lookup('cdn', ...).relative_urls`; `/_infinito/cdn/` is served on every vhost | +| Object-store file a browser loads (uploads, media in a public bucket) | Same-origin path | `lookup('objstore', application_id, 'relative_url')`, which is `/_infinito/objstore/` for a shared consumer with `public: true`; [locations.conf.j2](../../../roles/web-svc-seaweedfs/templates/nginx/locations.conf.j2) serves it on every vhost of that consumer with `GET` and `HEAD` only, no query string and no path ending in `/` | | Pointer a browser follows from a snippet rendered per vhost (injected script, proxy config) | Rendered per vhost | `lookup('tls', '', 'url.base')` with `domain` in scope, which aligns the term to the vhost's network | | Own public URL an application keeps in one server-side setting | Request-derived or one instance per network | Let the application read `X-Forwarded-Host` and `X-Forwarded-Proto`, which every vhost sends; otherwise run one instance per network as [web-svc-logout](../../../roles/web-svc-logout/templates/compose.yml.j2) does with `network_instances` | diff --git a/plugins/lookup/objstore.py b/plugins/lookup/objstore.py index 7e48f930a3..ce074523bf 100644 --- a/plugins/lookup/objstore.py +++ b/plugins/lookup/objstore.py @@ -27,7 +27,7 @@ OBJSTORE_DEFAULT_IMAGE = { "minio": "quay.io/minio/minio", } OBJSTORE_DEFAULT_REGION = "us-east-1" -OBJSTORE_PROXY_PREFIX = "/objstore" +OBJSTORE_PROXY_PREFIX = "/_infinito/objstore" def _is_enabled(applications: dict[str, Any], consumer_id: str, engine: str) -> bool: @@ -119,6 +119,7 @@ class LookupModule(LookupBase): "public_bucket": "", "public_endpoint": "", "public_url": "", + "relative_url": "", "proxy_required": False, "proxy_prefix": "", "upstream_domain": "", @@ -260,8 +261,13 @@ class LookupModule(LookupBase): ) return bool(served_on) and all(is_onion_domain(d) for d in served_on) + relative_url = ( + f"{OBJSTORE_PROXY_PREFIX}/{bucket}" + if public and shared and public_domain + else "" + ) proxy_required = bool( - public_domain + relative_url and not is_onion_domain(public_domain) and _consumer_is_onion_only() ) @@ -302,6 +308,7 @@ class LookupModule(LookupBase): "public_bucket": public_bucket, "public_endpoint": public_endpoint, "public_url": public_url, + "relative_url": relative_url, "proxy_required": proxy_required, "proxy_prefix": OBJSTORE_PROXY_PREFIX, "upstream_domain": public_domain, diff --git a/roles/web-app-wordpress/templates/env.j2 b/roles/web-app-wordpress/templates/env.j2 index 3ec7db7090..263d3714d6 100644 --- a/roles/web-app-wordpress/templates/env.j2 +++ b/roles/web-app-wordpress/templates/env.j2 @@ -14,7 +14,7 @@ INFINITO_NETWORK_BASE_URLS={{ WORDPRESS_NETWORK_BASE_URLS }} WORDPRESS_S3_BUCKET={{ lookup('objstore', application_id, 'bucket') }} WORDPRESS_S3_ENDPOINT={{ lookup('objstore', application_id, 'url') }} WORDPRESS_S3_KEY={{ lookup('objstore', application_id, 'access_key') }} -WORDPRESS_S3_PUBLIC_URL={{ lookup('objstore', application_id, 'public_url') }} +WORDPRESS_S3_PUBLIC_URL={{ lookup('objstore', application_id, 'relative_url') }} WORDPRESS_S3_REGION={{ lookup('objstore', application_id, 'region') }} WORDPRESS_S3_SECRET={{ lookup('objstore', application_id, 'secret_key') | dotenv_quote }} {% endif %} diff --git a/roles/web-svc-seaweedfs/README.md b/roles/web-svc-seaweedfs/README.md index cfba524c05..7bf2514064 100644 --- a/roles/web-svc-seaweedfs/README.md +++ b/roles/web-svc-seaweedfs/README.md @@ -23,6 +23,11 @@ The bucket of every consumer not marked `public` carries a bucket policy stateme Every deploy of this role converges that statement on all existing consumer buckets, adding it to private buckets and removing it from public ones, and a consumer's provisioning applies it right after creating the bucket. Other statements an operator adds to a consumer's bucket policy are kept. +Every vhost of a shared consumer marked `public` also serves its bucket under `/_infinito/objstore//`, and `lookup('objstore', application_id, 'relative_url')` returns that host-relative base for URLs a browser loads. +The route passes `GET` and `HEAD` for object keys only: it answers `404` for a path ending in `/`, drops the query string and the `Authorization` and `Cookie` headers, and sends the request over the loopback to the `api.seaweedfs.s3.*` vhost. +Responses carry `X-Content-Type-Options: nosniff` and a `sandbox` Content Security Policy. +A consumer without `public: true` or in embedded mode gets an empty `relative_url` and no route. + In embedded mode (`shared: false`) a consumer's compose stack receives a storage-only SeaweedFS container without UI or published ports. The embedded S3 listener starts without identities and accepts unauthenticated requests until the background `s3.configure` grant at startup registers the consumer identity; from then on it authenticates against that identity. Embedded buckets carry no `DenyAnonymousRead` statement because the listener publishes no port, so the container MUST stay confined to the consumer's isolated compose network. diff --git a/roles/web-svc-seaweedfs/templates/nginx/locations.conf.j2 b/roles/web-svc-seaweedfs/templates/nginx/locations.conf.j2 index 97cd7afb99..dcafe73a02 100644 --- a/roles/web-svc-seaweedfs/templates/nginx/locations.conf.j2 +++ b/roles/web-svc-seaweedfs/templates/nginx/locations.conf.j2 @@ -1,12 +1,25 @@ -{% if lookup('objstore', application_id, 'proxy_required') | bool %} {% set objstore = lookup('objstore', application_id) %} - location {{ objstore.proxy_prefix }}/{{ objstore.bucket }}/ { +{% if objstore.relative_url %} + location ^~ {{ objstore.relative_url }}/ { + location ~ /$ { + return 404; + } + limit_except GET { + deny all; + } + set $args ""; proxy_pass {{ objstore.upstream_scheme }}://127.0.0.1/{{ objstore.bucket }}/; proxy_ssl_server_name on; proxy_ssl_name {{ objstore.upstream_domain }}; proxy_set_header Host {{ objstore.upstream_domain }}; + proxy_set_header Authorization ""; + proxy_set_header Cookie ""; proxy_http_version 1.1; proxy_set_header Connection ""; + proxy_hide_header Content-Security-Policy; + proxy_hide_header Set-Cookie; + add_header X-Content-Type-Options "nosniff" always; + add_header Content-Security-Policy "sandbox; default-src 'none'; img-src 'self' data:; media-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'" always; {% include 'roles/sys-svc-proxy/templates/headers/upstream_strips.conf.j2' %} } {% endif %} diff --git a/tests/unit/python/plugins/lookup/test_objstore.py b/tests/unit/python/plugins/lookup/test_objstore.py index 0d957ac445..7c682d99de 100644 --- a/tests/unit/python/plugins/lookup/test_objstore.py +++ b/tests/unit/python/plugins/lookup/test_objstore.py @@ -107,6 +107,7 @@ class ObjstoreLookupTests(unittest.TestCase): self.assertEqual(out["public_bucket"], "") self.assertEqual(out["public_endpoint"], "") self.assertEqual(out["public_url"], "") + self.assertEqual(out["relative_url"], "") self.assertEqual(out["reach_host"], "127.0.0.1") self.assertEqual(self._run(["web-app-foo", "url"], applications)[0], "") @@ -143,6 +144,11 @@ class ObjstoreLookupTests(unittest.TestCase): self.assertEqual(out["public_bucket"], "api.seaweedfs.s3.example.com/foo") self.assertEqual(out["public_endpoint"], "https://api.seaweedfs.s3.example.com") self.assertEqual(out["public_url"], "https://api.seaweedfs.s3.example.com/foo") + self.assertEqual( + out["relative_url"], + "", + "a bucket without anonymous read gets no same-origin route", + ) self.assertEqual( self._run(["web-app-foo", "url"], applications)[0], @@ -308,25 +314,32 @@ class ObjstoreSameOriginProxyTests(unittest.TestCase): def setUpClass(cls): cls.mod = _load_module("plugins/lookup/objstore.py", "lookup_objstore") - APPLICATIONS: ClassVar[dict] = { - "web-app-foo": { - "services": {"seaweedfs": {"enabled": True, "shared": True}}, - "secrets": {"credentials": {"objstore_secret_key": "sk"}}, - }, - "web-svc-seaweedfs": { - "services": {"seaweedfs": {"name": "seaweedfs-central"}}, - "domains": {"canonical": {"api": "api.seaweedfs.s3.example.com"}}, - }, - } + PUBLIC_SHARED: ClassVar[dict] = {"enabled": True, "shared": True, "public": True} - def _resolve(self, *, consumer_domains, consumer_web="http"): + def _applications(self, consumer_seaweedfs: dict) -> dict: + return { + "web-app-foo": { + "services": {"seaweedfs": consumer_seaweedfs}, + "secrets": {"credentials": {"objstore_secret_key": "sk"}}, + }, + "web-svc-seaweedfs": { + "services": {"seaweedfs": {"name": "seaweedfs-central"}}, + "domains": {"canonical": {"api": "api.seaweedfs.s3.example.com"}}, + }, + } + + def _resolve( + self, *, consumer_domains, consumer_web="http", consumer_seaweedfs=None + ): vars_ = {"DIR_COMPOSITIONS": "/opt/compose/", "TLS_ENABLED": True} lm = self.mod.LookupModule() lm._templar = _DummyTemplar(vars_) lm._loader = mock.MagicMock() payloads = { - "applications": self.APPLICATIONS, + "applications": self._applications( + self.PUBLIC_SHARED if consumer_seaweedfs is None else consumer_seaweedfs + ), "domains": {"web-app-foo": consumer_domains}, "tls": { "domain": consumer_domains[0], @@ -358,10 +371,10 @@ class ObjstoreSameOriginProxyTests(unittest.TestCase): out = self._resolve(consumer_domains=["foo.abcdefghij.onion"]) self.assertTrue(out["proxy_required"]) - self.assertEqual(out["proxy_prefix"], "/objstore") + self.assertEqual(out["proxy_prefix"], "/_infinito/objstore") self.assertEqual( out["public_url"], - "http://foo.abcdefghij.onion/objstore/foo", + "http://foo.abcdefghij.onion/_infinito/objstore/foo", "the browser must dial the page's own origin, never the provider's " "clearnet host it cannot resolve through Tor", ) @@ -408,6 +421,53 @@ class ObjstoreSameOriginProxyTests(unittest.TestCase): self.assertFalse(out["proxy_required"]) self.assertEqual(out["public_domain"], "api.seaweedfs.s3.example.com") + def test_a_consumer_on_both_families_gets_a_same_origin_relative_url(self): + out = self._resolve( + consumer_domains=["foo.example.com", "foo.abcdefghij.onion"], + ) + + self.assertEqual( + out["relative_url"], + "/_infinito/objstore/foo", + "one server-side setting serves the clearnet and the onion vhost, so " + "only a host-relative path stays inside the network of the page", + ) + self.assertTrue(out["relative_url"].startswith("/")) + self.assertFalse(out["relative_url"].startswith("//")) + self.assertNotIn("api.seaweedfs.s3.example.com", out["relative_url"]) + + def test_a_clearnet_consumer_gets_the_same_relative_url(self): + out = self._resolve(consumer_domains=["foo.example.com"], consumer_web="https") + + self.assertEqual(out["relative_url"], "/_infinito/objstore/foo") + + def test_a_private_bucket_gets_no_same_origin_route(self): + out = self._resolve( + consumer_domains=["foo.abcdefghij.onion"], + consumer_seaweedfs={"enabled": True, "shared": True, "public": False}, + ) + + self.assertEqual( + out["relative_url"], + "", + "the route only fronts buckets with anonymous read", + ) + self.assertFalse(out["proxy_required"]) + self.assertEqual(out["public_url"], "https://api.seaweedfs.s3.example.com/foo") + + def test_an_embedded_store_gets_no_same_origin_route(self): + out = self._resolve( + consumer_domains=["foo.example.com", "foo.abcdefghij.onion"], + consumer_seaweedfs={"enabled": True, "shared": False, "public": True}, + ) + + self.assertEqual( + out["relative_url"], + "", + "the route loops back to the central provider's vhost, which holds " + "no bucket of an embedded store", + ) + if __name__ == "__main__": unittest.main() diff --git a/tests/unit/python/roles/web-app-wordpress/test_s3_public_url.py b/tests/unit/python/roles/web-app-wordpress/test_s3_public_url.py new file mode 100644 index 0000000000..cf591fd950 --- /dev/null +++ b/tests/unit/python/roles/web-app-wordpress/test_s3_public_url.py @@ -0,0 +1,124 @@ +from __future__ import annotations + +import importlib.util +import unittest +import unittest.mock as mock + +from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoescape + +from utils.cache.yaml import load_yaml + +from . import PROJECT_ROOT + +APP = "web-app-wordpress" +PROVIDER_HOST = "api.seaweedfs.s3.example.com" +SERVED_ON = ["blog.example.com", "blog." + "a" * 56 + ".onion"] +SERVICES = load_yaml(str(PROJECT_ROOT / "roles" / APP / "meta" / "services.yml")) + + +def _objstore() -> dict: + """ + Returns: + lookup('objstore', 'web-app-wordpress') for a node serving the blog on clearnet and onion, with the role's own `public` flag. + """ + spec = importlib.util.spec_from_file_location( + "lookup_objstore_wordpress", str(PROJECT_ROOT / "plugins/lookup/objstore.py") + ) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + payloads = { + "applications": { + APP: { + "services": { + "seaweedfs": { + "enabled": True, + "shared": True, + "public": SERVICES["seaweedfs"]["public"], + } + }, + "secrets": {"credentials": {"objstore_secret_key": "sk"}}, + }, + "web-svc-seaweedfs": { + "services": {"seaweedfs": {"name": "seaweedfs"}}, + "domains": {"canonical": {"api": PROVIDER_HOST}}, + }, + }, + "domains": {APP: SERVED_ON}, + } + lookup = module.LookupModule() + lookup._templar = mock.MagicMock(available_variables={}) + lookup._loader = mock.MagicMock() + with ( + mock.patch.object(module, "lookup_loader") as loader, + mock.patch.object(module, "entity_name", return_value="wordpress"), + ): + loader.get.side_effect = lambda name, **_kwargs: mock.MagicMock( + run=lambda _terms, **_kw: [payloads[name]] + ) + return lookup.run( + [APP], variables={"DIR_COMPOSITIONS": "/opt/compose/", "TLS_ENABLED": True} + )[0] + + +def _render_env(objstore: dict) -> dict[str, str]: + env = Environment( + loader=FileSystemLoader(str(PROJECT_ROOT)), + undefined=StrictUndefined, + autoescape=select_autoescape(), + keep_trailing_newline=True, + ) + + def lookup(name: str, *terms: str): + if name == "objstore": + return objstore[terms[1]] + if name == "database": + return "db" + raise AssertionError(f"env.j2 renders an unexpected lookup {name}{terms}") + + env.globals["lookup"] = lookup + env.filters["bool"] = bool + env.filters["dotenv_quote"] = lambda value: value + env.filters["urlsplit"] = lambda _url, _part: "sso.example.com" + env.filters["network_of"] = lambda _host: "clearnet" + rendered = env.get_template(f"roles/{APP}/templates/env.j2").render( + application_id=APP, + HOST_TIMEZONE="UTC", + WORDPRESS_MCP_SERVICE_KEY="wordpress", + WORDPRESS_NETWORK_BASE_URLS="", + MODE_DEBUG=False, + OIDC={"CLIENT": {"ISSUER_URL": "https://sso.example.com/realms/x"}}, + ) + return dict( + line.split("=", 1) + for line in rendered.splitlines() + if "=" in line and not line.startswith("#") + ) + + +class TestWordpressS3PublicUrl(unittest.TestCase): + def test_the_bucket_url_is_host_relative(self): + values = _render_env(_objstore()) + + self.assertEqual( + values["WORDPRESS_S3_PUBLIC_URL"], + "/_infinito/objstore/wordpress", + "S3-Uploads prefixes every upload URL with S3_UPLOADS_BUCKET_URL " + "verbatim, and one container serves the clearnet and the onion " + "vhost, so only a host-relative path keeps the logo on the page's " + "network", + ) + self.assertFalse(values["WORDPRESS_S3_PUBLIC_URL"].startswith("//")) + + def test_no_browser_facing_value_names_the_provider_host(self): + values = _render_env(_objstore()) + + self.assertNotIn(PROVIDER_HOST, values["WORDPRESS_S3_PUBLIC_URL"]) + + def test_the_server_side_endpoint_stays_on_the_internal_store(self): + values = _render_env(_objstore()) + + self.assertEqual(values["WORDPRESS_S3_ENDPOINT"], "http://seaweedfs:8333") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/python/roles/web-svc-seaweedfs/test_objstore_location.py b/tests/unit/python/roles/web-svc-seaweedfs/test_objstore_location.py new file mode 100644 index 0000000000..34f858a314 --- /dev/null +++ b/tests/unit/python/roles/web-svc-seaweedfs/test_objstore_location.py @@ -0,0 +1,142 @@ +from __future__ import annotations + +import re +import unittest + +from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoescape + +from utils.cache.files import PROJECT_ROOT, read_text + +TEMPLATE = "roles/web-svc-seaweedfs/templates/nginx/locations.conf.j2" +VHOSTS = ( + "roles/sys-svc-proxy/templates/vhost/basic.conf.j2", + "roles/sys-svc-proxy/templates/vhost/ws_generic.conf.j2", +) +CONSUMER = "web-app-foo" +PUBLIC_CONSUMER = { + "bucket": "foo", + "relative_url": "/_infinito/objstore/foo", + "upstream_scheme": "https", + "upstream_domain": "api.seaweedfs.s3.example.com", +} +CLEARNET = "foo.example.com" +ONION = "foo.abcdefghij.onion" + + +def _render(objstore: dict, application_id: str, domain: str) -> str: + """ + Args: + objstore: what lookup('objstore', 'web-app-foo') answers; every other role answers an empty relative_url. + application_id: the role whose vhost is rendered. + domain: the vhost being rendered. + + Returns: + The rendered nginx fragment. + """ + env = Environment( + loader=FileSystemLoader(str(PROJECT_ROOT)), + undefined=StrictUndefined, + autoescape=select_autoescape(), + ) + env.globals["lookup"] = lambda name, app: ( + objstore if (name, app) == ("objstore", CONSUMER) else {"relative_url": ""} + ) + return env.get_template(TEMPLATE).render( + application_id=application_id, domain=domain + ) + + +def _outer_location(rendered: str) -> str: + match = re.search( + r"location \^~ /_infinito/objstore/foo/ \{(?P.*)\n \}", + rendered, + re.DOTALL, + ) + assert match, rendered + return match.group("body") + + +def _limited_methods(body: str) -> set[str]: + match = re.search(r"limit_except ([A-Z ]+)\{\s*deny all;\s*\}", body) + assert match, body + return set(match.group(1).split()) + + +class TestObjstoreSameOriginLocation(unittest.TestCase): + def test_the_route_is_rendered_on_the_clearnet_and_the_onion_vhost(self): + clearnet = _render(PUBLIC_CONSUMER, CONSUMER, CLEARNET) + onion = _render(PUBLIC_CONSUMER, CONSUMER, ONION) + + self.assertIn("location ^~ /_infinito/objstore/foo/ {", clearnet) + self.assertEqual( + clearnet, + onion, + "a page on either network dials the same relative path, so both " + "vhosts must answer it alike", + ) + + def test_only_get_and_head_pass(self): + body = _outer_location(_render(PUBLIC_CONSUMER, CONSUMER, ONION)) + + self.assertEqual( + _limited_methods(body), + {"GET"}, + "limit_except GET admits GET and HEAD only; PUT, POST and DELETE " + "would reach the S3 write API", + ) + + def test_the_bucket_listing_and_s3_subresources_are_closed(self): + body = _outer_location(_render(PUBLIC_CONSUMER, CONSUMER, ONION)) + + self.assertRegex( + body, + r"location ~ /\$ \{\s*return 404;\s*\}", + "a path ending in / is ListObjects on the bucket or a directory", + ) + self.assertIn( + 'set $args "";', + body, + "?list-type, ?acl, ?policy, ?tagging and presigned queries must " + "never reach the store", + ) + + def test_the_route_is_bound_to_the_consumer_bucket_anonymously(self): + body = _outer_location(_render(PUBLIC_CONSUMER, CONSUMER, ONION)) + + self.assertIn("proxy_pass https://127.0.0.1/foo/;", body) + self.assertIn("proxy_set_header Host api.seaweedfs.s3.example.com;", body) + self.assertIn('proxy_set_header Authorization "";', body) + self.assertIn('proxy_set_header Cookie "";', body) + self.assertIn("proxy_hide_header X-Powered-By;", body) + self.assertIn('Content-Security-Policy "sandbox;', body) + self.assertIn('X-Content-Type-Options "nosniff"', body) + + def test_a_consumer_without_a_relative_url_gets_no_route(self): + rendered = _render({**PUBLIC_CONSUMER, "relative_url": ""}, CONSUMER, ONION) + + self.assertNotIn("location", rendered) + + def test_a_role_without_an_object_store_gets_no_route(self): + rendered = _render(PUBLIC_CONSUMER, "web-app-bar", CLEARNET) + + self.assertNotIn("location", rendered) + + def test_every_generic_vhost_includes_the_route_outside_any_branch(self): + include = f"{{% include '{TEMPLATE}' %}}" + for vhost in VHOSTS: + text = read_text(str(PROJECT_ROOT / vhost)) + with self.subTest(vhost=vhost): + self.assertIn(include, text) + before = text.split(include, 1)[0] + depth = len(re.findall(r"\{%-?\s*if\b", before)) - len( + re.findall(r"\{%-?\s*endif\b", before) + ) + self.assertEqual( + depth, + 0, + "an include inside a branch would skip the route on some vhosts", + ) + + +if __name__ == "__main__": + unittest.main()