mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-06 01:40:19 +00:00
feat(test-e2e-playwright): run each role on one of its served networks
When a node serves a role on several networks, the runner picks one of the role's vhosts at random and keeps that pick for the flake retry. The .env is rendered for the picked vhost, so APP_BASE_URL follows its network, and CANONICAL_DOMAIN moves to its sibling there. Reports of a pick outside the canonical network land under <application_id>+<network>. network-leak.spec.js is staged next to every role spec and skipped unless the role is served on more than one network. It fails when a request leaves the network of the document that issued it, or when the browser blocks mixed content. Only the SSO issuer may cross networks, so an onion pick reaches it past the Tor proxy. Onion detection reads the host of APP_BASE_URL before CANONICAL_DOMAIN, so roles without CANONICAL_DOMAIN also get the onion timeouts and Tor retries. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
66c8df6729
commit
6f8dcc40cc
19 files changed
+504
-138
No files matched your search
@@ -0,0 +1,73 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from jinja2 import Environment, StrictUndefined
|
||||
|
||||
from plugins.filter.dotenv import dotenv_quote
|
||||
from plugins.filter.network_of import in_network, network_of, network_suffixes
|
||||
from plugins.lookup.network_siblings import served_siblings
|
||||
from utils.cache.yaml import load_yaml_any
|
||||
from utils.domains.default_primary import default_domain_primary
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
|
||||
TASKS = PROJECT_ROOT / "roles/test-e2e-playwright/tasks/03_run_pass.yml"
|
||||
TASK_NAME = "📄 Render .env from templates/playwright.env.j2"
|
||||
PRIMARY = default_domain_primary()
|
||||
NODE = "abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrstuvw.onion"
|
||||
CLEARNET = [f"api.s3.{PRIMARY}", f"console.s3.{PRIMARY}"]
|
||||
TOR = [f"api.s3.{NODE}", f"console.s3.{NODE}"]
|
||||
|
||||
|
||||
def render(pass_domain: str) -> str:
|
||||
tasks = load_yaml_any(str(TASKS))
|
||||
task = next(t for t in tasks if t.get("name") == TASK_NAME)
|
||||
env = Environment(autoescape=False, trim_blocks=True, undefined=StrictUndefined) # noqa: S701 - dotenv file, not markup
|
||||
env.filters.update(
|
||||
dotenv_quote=dotenv_quote,
|
||||
in_network=in_network,
|
||||
network_of=network_of,
|
||||
network_suffixes=network_suffixes,
|
||||
to_json=json.dumps,
|
||||
urlsplit=lambda url, part: getattr(urlsplit(url), part),
|
||||
)
|
||||
|
||||
def lookup(name, term, template_vars=None):
|
||||
if name == "template":
|
||||
return (
|
||||
f'APP_BASE_URL="https://{template_vars["domain"]}/"\n'
|
||||
f'CANONICAL_DOMAIN="{CLEARNET[1]}"\n'
|
||||
)
|
||||
return served_siblings(term, {"web-app-minio": CLEARNET + TOR}, PRIMARY, NODE)
|
||||
|
||||
return env.from_string(task["ansible.builtin.copy"]["content"]).render(
|
||||
lookup=lookup,
|
||||
_playwright_env_template="playwright.env.j2",
|
||||
_playwright_pass_domain=pass_domain,
|
||||
_playwright_passes=[CLEARNET[0], TOR[0]],
|
||||
TEST_E2E_PLAYWRIGHT_CONFIG_TIMEOUTS={},
|
||||
OIDC={"URL": f"https://auth.{PRIMARY}/realms/main"},
|
||||
DEPLOYMENT_MODE="compose",
|
||||
)
|
||||
|
||||
|
||||
class TestEnvCanonicalDomain(unittest.TestCase):
|
||||
def test_onion_pick_moves_the_canonical_domain_to_its_onion_sibling(self):
|
||||
rendered = render(TOR[0])
|
||||
self.assertIn(f'APP_BASE_URL="https://{TOR[0]}/"\n', rendered)
|
||||
self.assertIn(f'CANONICAL_DOMAIN="{TOR[1]}"\n', rendered)
|
||||
|
||||
def test_canonical_network_pick_keeps_the_rendered_env(self):
|
||||
self.assertTrue(
|
||||
render(CLEARNET[0]).startswith(
|
||||
f'APP_BASE_URL="https://{CLEARNET[0]}/"\n'
|
||||
f'CANONICAL_DOMAIN="{CLEARNET[1]}"\n'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -8,7 +8,7 @@ from utils.cache.yaml import load_yaml_any
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
|
||||
TASKS = PROJECT_ROOT / "roles/test-e2e-playwright/tasks/02_run_one.yml"
|
||||
TASKS = PROJECT_ROOT / "roles/test-e2e-playwright/tasks/03_run_pass.yml"
|
||||
TASK_NAME = "⏳ Wait until application is ready (any non-error response)"
|
||||
|
||||
|
||||
|
||||
@@ -13,11 +13,14 @@ import textwrap
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from utils.domains.default_primary import default_domain_primary
|
||||
|
||||
from . import PROJECT_ROOT
|
||||
|
||||
HELPER_PATH = str(
|
||||
PROJECT_ROOT / "roles" / "test-e2e-playwright" / "files" / "timeouts.js"
|
||||
)
|
||||
DOMAIN = default_domain_primary()
|
||||
|
||||
|
||||
def _have_node():
|
||||
@@ -60,7 +63,7 @@ class TestTimeoutsHelper(unittest.TestCase):
|
||||
def test_clearnet_default_factor_is_identity(self):
|
||||
out = self._run(
|
||||
"t.resolveTimeout(60000)",
|
||||
{"CANONICAL_DOMAIN": '"x.infinito.test"'},
|
||||
{"CANONICAL_DOMAIN": f'"x.{DOMAIN}"'},
|
||||
)
|
||||
self.assertIn("RESULT:60000", out)
|
||||
|
||||
@@ -75,7 +78,7 @@ class TestTimeoutsHelper(unittest.TestCase):
|
||||
out = self._run(
|
||||
"t.resolveTimeout(60000)",
|
||||
{
|
||||
"CANONICAL_DOMAIN": "x.infinito.test",
|
||||
"CANONICAL_DOMAIN": f"x.{DOMAIN}",
|
||||
"PLAYWRIGHT_TIMEOUT_FACTOR": "2",
|
||||
},
|
||||
)
|
||||
@@ -96,7 +99,7 @@ class TestTimeoutsHelper(unittest.TestCase):
|
||||
out = self._run(
|
||||
"t.resolveTimeout(60000)",
|
||||
{
|
||||
"CANONICAL_DOMAIN": "x.infinito.test",
|
||||
"CANONICAL_DOMAIN": f"x.{DOMAIN}",
|
||||
"PLAYWRIGHT_TIMEOUT_FACTOR": "0",
|
||||
},
|
||||
)
|
||||
@@ -113,7 +116,23 @@ class TestTimeoutsHelper(unittest.TestCase):
|
||||
)
|
||||
self.assertIn(
|
||||
"RESULT:false",
|
||||
self._run("t.isOnionTarget()", {"CANONICAL_DOMAIN": '"x.infinito.test"'}),
|
||||
self._run("t.isOnionTarget()", {"CANONICAL_DOMAIN": f'"x.{DOMAIN}"'}),
|
||||
)
|
||||
|
||||
def test_is_onion_target_reads_app_base_url_first(self):
|
||||
self.assertIn(
|
||||
"RESULT:true",
|
||||
self._run("t.isOnionTarget()", {"APP_BASE_URL": '"https://x.abc.onion/"'}),
|
||||
)
|
||||
self.assertIn(
|
||||
"RESULT:false",
|
||||
self._run(
|
||||
"t.isOnionTarget()",
|
||||
{
|
||||
"APP_BASE_URL": f'"https://x.{DOMAIN}/"',
|
||||
"CANONICAL_DOMAIN": '"x.abc.onion"',
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user