test(domains): read the primary domain from default.env in every test

The hardcoded-primary-domain lint exempted tests/ and scripts/tests/, so test
fixtures kept their own copy of the domain and would drift from
INFINITO_DOMAIN the moment it changes. The lint now scans both trees, and a
unit test pins its scope: only default.env, Markdown, inventories/, .claude/
and build/ may name the domain.

Python tests take the value from default_domain_primary(), and the workspace
helper builds its dashboard and Matomo URLs from INFINITO_DOMAIN once the repo
.env is loaded.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5.5 committed 2026-09-24 22:53:54 +02:00
1 parent e8cb94e246
commit e2beab9f1c
34 files changed
+371 -290

No files matched your search

@@ -1,82 +1,79 @@
import unittest
from plugins.filter.cookie_scope import common_dns_suffix, domain_strings
from utils.domains.default_primary import default_domain_primary
DOMAIN = default_domain_primary()
class CommonDnsSuffixTests(unittest.TestCase):
def test_domain_pipeline_normalizes_every_supported_shape(self):
mapping = {
"filer": "filer.seaweedfs.s3.infinito.test",
"master": "master.seaweedfs.s3.infinito.test",
"filer": f"filer.seaweedfs.s3.{DOMAIN}",
"master": f"master.seaweedfs.s3.{DOMAIN}",
}
self.assertEqual(
common_dns_suffix(domain_strings(mapping)),
"seaweedfs.s3.infinito.test",
f"seaweedfs.s3.{DOMAIN}",
)
self.assertEqual(
common_dns_suffix(domain_strings("cloud.infinito.test")),
"cloud.infinito.test",
common_dns_suffix(domain_strings(f"cloud.{DOMAIN}")),
f"cloud.{DOMAIN}",
)
mixed = domain_strings(
["cloud.infinito.test", "cloud.examplelongonionaddress.onion"]
[f"cloud.{DOMAIN}", "cloud.examplelongonionaddress.onion"]
)
clearnet = [domain for domain in mixed if not domain.endswith(".onion")]
self.assertEqual(common_dns_suffix(clearnet), "cloud.infinito.test")
self.assertEqual(common_dns_suffix(clearnet), f"cloud.{DOMAIN}")
def test_single_domain_returned_unchanged(self):
self.assertEqual(
common_dns_suffix(["cloud.infinito.test"]), "cloud.infinito.test"
)
self.assertEqual(common_dns_suffix([f"cloud.{DOMAIN}"]), f"cloud.{DOMAIN}")
def test_multi_domain_collapses_to_shared_parent(self):
self.assertEqual(
common_dns_suffix(
[
"api.seaweedfs.s3.infinito.test",
"filer.seaweedfs.s3.infinito.test",
"master.seaweedfs.s3.infinito.test",
f"api.seaweedfs.s3.{DOMAIN}",
f"filer.seaweedfs.s3.{DOMAIN}",
f"master.seaweedfs.s3.{DOMAIN}",
]
),
"seaweedfs.s3.infinito.test",
f"seaweedfs.s3.{DOMAIN}",
)
def test_subdomain_alias_keeps_minimal_shared_suffix(self):
self.assertEqual(
common_dns_suffix(["app.infinito.test", "www.app.infinito.test"]),
"app.infinito.test",
common_dns_suffix([f"app.{DOMAIN}", f"www.app.{DOMAIN}"]),
f"app.{DOMAIN}",
)
def test_dict_input_uses_values_multi(self):
self.assertEqual(
common_dns_suffix(
{
"filer": "filer.seaweedfs.s3.infinito.test",
"master": "master.seaweedfs.s3.infinito.test",
"api": "api.seaweedfs.s3.infinito.test",
"filer": f"filer.seaweedfs.s3.{DOMAIN}",
"master": f"master.seaweedfs.s3.{DOMAIN}",
"api": f"api.seaweedfs.s3.{DOMAIN}",
}
),
"seaweedfs.s3.infinito.test",
f"seaweedfs.s3.{DOMAIN}",
)
def test_dict_input_single_value(self):
self.assertEqual(
common_dns_suffix({"web": "cloud.infinito.test"}),
"cloud.infinito.test",
common_dns_suffix({"web": f"cloud.{DOMAIN}"}),
f"cloud.{DOMAIN}",
)
def test_string_input(self):
self.assertEqual(
common_dns_suffix("cloud.infinito.test"), "cloud.infinito.test"
)
self.assertEqual(common_dns_suffix(f"cloud.{DOMAIN}"), f"cloud.{DOMAIN}")
def test_empty_input_returns_empty_string(self):
self.assertEqual(common_dns_suffix([]), "")
self.assertEqual(common_dns_suffix(None), "")
def test_blank_entries_ignored(self):
self.assertEqual(
common_dns_suffix(["", "cloud.infinito.test"]), "cloud.infinito.test"
)
self.assertEqual(common_dns_suffix(["", f"cloud.{DOMAIN}"]), f"cloud.{DOMAIN}")
if __name__ == "__main__":
@@ -2,9 +2,10 @@ import copy
import unittest
from plugins.filter.csp_filters import FilterModule
from utils.domains.default_primary import default_domain_primary
NODE = "ndck3kzcxbcem2oskbhytxwevvpzwn7j5dj6q36vbijyrnw3rjf2heqd.onion"
PRIMARY = "infinito.test"
PRIMARY = default_domain_primary()
class TestCspOnionMirror(unittest.TestCase):
@@ -3,6 +3,9 @@ import unittest
from ansible.errors import AnsibleFilterError
from plugins.filter.canonical_domains_map import FilterModule
from utils.domains.default_primary import default_domain_primary
DOMAIN = default_domain_primary()
class TestDomainFilters(unittest.TestCase):
@@ -117,14 +120,14 @@ class TestDomainFilters(unittest.TestCase):
import os
prev = os.environ.get("DOMAIN")
os.environ["DOMAIN"] = "infinito.test"
os.environ["DOMAIN"] = DOMAIN
try:
primary = (
"{{ lookup('env', 'DOMAIN') | default('infinito.localhost', true) }}"
)
apps = {"web-app-app1": {}}
result = self.filter_module.canonical_domains_map(apps, primary)
self.assertEqual(result, {"web-app-app1": ["app1.infinito.test"]})
self.assertEqual(result, {"web-app-app1": [f"app1.{DOMAIN}"]})
finally:
if prev is None:
os.environ.pop("DOMAIN", None)
@@ -1,8 +1,10 @@
import unittest
from plugins.filter.network_of import FilterModule
from utils.domains.default_primary import default_domain_primary
ONION = "abc123def456ghij789klmno000pqrstuvwx111yz222abc333def444gh.onion"
DOMAIN = default_domain_primary()
class TestNetworkFilters(unittest.TestCase):
@@ -11,13 +13,11 @@ class TestNetworkFilters(unittest.TestCase):
def test_network_of_is_the_registry_lookup(self):
self.assertEqual(self.filters["network_of"]("x.abc.onion"), "tor")
self.assertEqual(self.filters["network_of"]("x.infinito.test"), "clearnet")
self.assertEqual(self.filters["network_of"](f"x.{DOMAIN}"), "clearnet")
def test_network_sibling_translates_the_primary(self):
self.assertEqual(
self.filters["network_sibling"](
"infinito.test", "tor", "infinito.test", ONION
),
self.filters["network_sibling"](DOMAIN, "tor", DOMAIN, ONION),
ONION,
)
@@ -32,18 +32,16 @@ class TestNetworkFilters(unittest.TestCase):
self.assertEqual(self.filters["network_suffixes"](["clearnet"]), {})
def test_in_network_keeps_the_domains_of_one_network(self):
domains = ["a.infinito.test", f"a.{ONION}", "b.infinito.test"]
domains = [f"a.{DOMAIN}", f"a.{ONION}", f"b.{DOMAIN}"]
self.assertEqual(
self.filters["in_network"](domains, "clearnet"),
["a.infinito.test", "b.infinito.test"],
[f"a.{DOMAIN}", f"b.{DOMAIN}"],
)
self.assertEqual(self.filters["in_network"](domains, "tor"), [f"a.{ONION}"])
def test_network_sibling_is_empty_without_a_node(self):
self.assertEqual(
self.filters["network_sibling"](
"infinito.test", "tor", "infinito.test", ""
),
self.filters["network_sibling"](DOMAIN, "tor", DOMAIN, ""),
"",
)
@@ -168,7 +168,7 @@ class TestTheBridgeSurvivesTheFirstRun(unittest.TestCase):
``ansible_facts.docker0`` is still absent. Deriving the address from the
fact alone emitted the clearnet resolver on its own, and the inner
containers then asked a public resolver for a domain only the node dnsmasq
knows: ``server can't find infinito.test: NXDOMAIN``.
knows: ``server can't find <domain>: NXDOMAIN``.
"""
POOLS: ClassVar[list] = [{"base": "10.208.0.0/12", "size": 24}]
@@ -4,6 +4,9 @@ import unittest
from unittest.mock import MagicMock, patch
from plugins.lookup.current_play_redirect_domains import LookupModule
from utils.domains.default_primary import default_domain_primary
DOMAIN = default_domain_primary()
class _DummyTemplar:
@@ -57,7 +60,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
def test_primary_redirect_appended_when_both_domains_set(self):
lm = self._make_lookup()
variables = {
"DOMAIN_PRIMARY": "infinito.test",
"DOMAIN_PRIMARY": DOMAIN,
"DOMAIN_HOMEPAGE": "infinito.nexus",
}
with self._patch_lookups(
@@ -65,28 +68,28 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
):
result = lm.run(terms=[], variables=variables)[0]
self.assertIn(
{"source": "infinito.test", "target": "infinito.nexus"},
{"source": DOMAIN, "target": "infinito.nexus"},
result,
)
def test_primary_redirect_appended_even_when_rdr_domains_not_in_deployed(self):
lm = self._make_lookup()
variables = {
"DOMAIN_PRIMARY": "infinito.test",
"DOMAIN_PRIMARY": DOMAIN,
"DOMAIN_HOMEPAGE": "infinito.nexus",
}
with self._patch_lookups(deployed=["web-opt-rdr-www"], current_play_apps={}):
result = lm.run(terms=[], variables=variables)[0]
self.assertEqual(
result,
[{"source": "infinito.test", "target": "infinito.nexus"}],
[{"source": DOMAIN, "target": "infinito.nexus"}],
)
def test_primary_redirect_absent_when_primary_equals_homepage(self):
lm = self._make_lookup()
variables = {
"DOMAIN_PRIMARY": "infinito.test",
"DOMAIN_HOMEPAGE": "infinito.test",
"DOMAIN_PRIMARY": DOMAIN,
"DOMAIN_HOMEPAGE": DOMAIN,
}
with self._patch_lookups(
deployed=["web-opt-rdr-domains"], current_play_apps={}
@@ -96,7 +99,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
def test_primary_redirect_absent_when_domain_homepage_missing(self):
lm = self._make_lookup()
variables = {"DOMAIN_PRIMARY": "infinito.test"}
variables = {"DOMAIN_PRIMARY": DOMAIN}
with self._patch_lookups(
deployed=["web-opt-rdr-domains"], current_play_apps={}
):
@@ -167,7 +170,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
}
}
variables = {
"DOMAIN_PRIMARY": "infinito.test",
"DOMAIN_PRIMARY": DOMAIN,
"DOMAIN_HOMEPAGE": "infinito.nexus",
"AUTO_BUILD_ALIASES": False,
"redirect_domain_mappings": [
@@ -180,7 +183,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
result = lm.run(terms=[], variables=variables)[0]
sources = {entry["source"]: entry["target"] for entry in result}
self.assertEqual(sources.get("legacy.example.com"), "current.example.com")
self.assertEqual(sources.get("infinito.test"), "infinito.nexus")
self.assertEqual(sources.get(DOMAIN), "infinito.nexus")
self.assertEqual(sources.get("alt-foo.example.com"), "foo.example.com")
def test_non_list_redirect_domain_mappings_treated_as_empty(self):
@@ -193,7 +196,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
def test_non_mapping_applications_current_play_skipped(self):
lm = self._make_lookup()
variables = {
"DOMAIN_PRIMARY": "infinito.test",
"DOMAIN_PRIMARY": DOMAIN,
"DOMAIN_HOMEPAGE": "infinito.nexus",
}
with self._patch_lookups(
@@ -202,7 +205,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
result = lm.run(terms=[], variables=variables)[0]
self.assertEqual(
result,
[{"source": "infinito.test", "target": "infinito.nexus"}],
[{"source": DOMAIN, "target": "infinito.nexus"}],
)
def test_jinja_tagged_domain_primary_is_templated(self):
@@ -219,7 +222,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
lm = LookupModule()
lm._templar = _ResolvingTemplar(
{
"{{ lookup('env','INFINITO_DOMAIN') }}": "infinito.test",
"{{ lookup('env','INFINITO_DOMAIN') }}": DOMAIN,
"{{ lookup('domain','web-app-dashboard') }}": "infinito.nexus",
}
)
@@ -235,7 +238,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
self.assertEqual(
result,
[{"source": "infinito.test", "target": "infinito.nexus"}],
[{"source": DOMAIN, "target": "infinito.nexus"}],
)
self.assertIn(
"{{ lookup('env','INFINITO_DOMAIN') }}",
@@ -244,7 +247,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
def _onion_variables(self, **overrides):
variables = {
"DOMAIN_PRIMARY": "infinito.test",
"DOMAIN_PRIMARY": DOMAIN,
"DOMAIN_HOMEPAGE": "dashboard.abcdefonion.onion",
"group_names": ["svc-net-tor", "web-app-dashboard"],
"applications": {
@@ -267,7 +270,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
result,
[
{
"source": "infinito.test",
"source": DOMAIN,
"target": "dashboard.abcdefonion.onion",
},
{
@@ -288,7 +291,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
result,
[
{
"source": "infinito.test",
"source": DOMAIN,
"target": "dashboard.abcdefonion.onion",
},
],
@@ -307,7 +310,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
result,
[
{
"source": "infinito.test",
"source": DOMAIN,
"target": "dashboard.abcdefonion.onion",
},
],
@@ -331,7 +334,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
result = lm.run(terms=[], variables=variables)[0]
self.assertEqual(
result,
[{"source": "infinito.test", "target": "abcdefonion.onion"}],
[{"source": DOMAIN, "target": "abcdefonion.onion"}],
)
def test_onion_apex_node_value_templated(self):
@@ -374,7 +377,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
lm._templar = _FailingTemplar()
lm._loader = None
variables = {
"DOMAIN_PRIMARY": "infinito.test",
"DOMAIN_PRIMARY": DOMAIN,
"DOMAIN_HOMEPAGE": "infinito.nexus",
}
with self._patch_lookups(
@@ -383,7 +386,7 @@ class CurrentPlayRedirectDomainsLookupTests(unittest.TestCase):
result = lm.run(terms=[], variables=variables)[0]
self.assertEqual(
result,
[{"source": "infinito.test", "target": "infinito.nexus"}],
[{"source": DOMAIN, "target": "infinito.nexus"}],
)
@@ -6,48 +6,49 @@ from __future__ import annotations
import unittest
from plugins.lookup.network_siblings import served_siblings
from utils.domains.default_primary import default_domain_primary
ONION = "abc123def456ghij789klmno000pqrstuvwx111yz222abc333def444gh.onion"
PRIMARY = "infinito.test"
PRIMARY = default_domain_primary()
class TestServedSiblings(unittest.TestCase):
def test_multi_app_renders_both_networks_from_the_canonical_domain(self) -> None:
domains = {"web-app-x": ["x.infinito.test", f"x.{ONION}"]}
domains = {"web-app-x": [f"x.{PRIMARY}", f"x.{ONION}"]}
self.assertEqual(
served_siblings("x.infinito.test", domains, PRIMARY, ONION),
["x.infinito.test", f"x.{ONION}"],
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ONION),
[f"x.{PRIMARY}", f"x.{ONION}"],
)
def test_multi_app_skips_the_non_canonical_sibling(self) -> None:
domains = {"web-app-x": ["x.infinito.test", f"x.{ONION}"]}
domains = {"web-app-x": [f"x.{PRIMARY}", f"x.{ONION}"]}
self.assertEqual(served_siblings(f"x.{ONION}", domains, PRIMARY, ONION), [])
def test_tor_only_app_maps_a_raw_clearnet_domain_to_its_onion(self) -> None:
domains = {"web-app-x": [f"x.{ONION}"]}
self.assertEqual(
served_siblings("x.infinito.test", domains, PRIMARY, ONION), [f"x.{ONION}"]
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ONION), [f"x.{ONION}"]
)
def test_clearnet_only_app_renders_one_vhost(self) -> None:
domains = {"web-app-x": ["x.infinito.test"]}
domains = {"web-app-x": [f"x.{PRIMARY}"]}
self.assertEqual(
served_siblings("x.infinito.test", domains, PRIMARY, ONION),
["x.infinito.test"],
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ONION),
[f"x.{PRIMARY}"],
)
def test_named_canonicals_fan_out_per_key(self) -> None:
domains = {
"web-app-x": {
"api": "api.infinito.test",
"web": "web.infinito.test",
"api": f"api.{PRIMARY}",
"web": f"web.{PRIMARY}",
"api_onion": f"api.{ONION}",
"web_onion": f"web.{ONION}",
}
}
self.assertEqual(
served_siblings("web.infinito.test", domains, PRIMARY, ONION),
["web.infinito.test", f"web.{ONION}"],
served_siblings(f"web.{PRIMARY}", domains, PRIMARY, ONION),
[f"web.{PRIMARY}", f"web.{ONION}"],
)
def test_unknown_domain_renders_as_given(self) -> None:
@@ -57,10 +58,10 @@ class TestServedSiblings(unittest.TestCase):
)
def test_node_without_tor_renders_as_given(self) -> None:
domains = {"web-app-x": ["x.infinito.test"]}
domains = {"web-app-x": [f"x.{PRIMARY}"]}
self.assertEqual(
served_siblings("x.infinito.test", domains, PRIMARY, ""),
["x.infinito.test"],
served_siblings(f"x.{PRIMARY}", domains, PRIMARY, ""),
[f"x.{PRIMARY}"],
)
@@ -12,9 +12,12 @@ import unittest
from ansible.errors import AnsibleError
from utils.domains.default_primary import default_domain_primary
from . import PROJECT_ROOT
RELAY = "mail.infinito.test"
DOMAIN = default_domain_primary()
RELAY = f"mail.{DOMAIN}"
MANAGER = "swarm-manager-01"
@@ -11,9 +11,12 @@ from ansible.errors import AnsibleError
from plugins.lookup.users import LookupModule, _reset_cache_for_tests
from utils.cache import base as runtime_data_base
from utils.cache.yaml import dump_yaml_str
from utils.domains.default_primary import default_domain_primary
from utils.paths import FILE_TOKENS
from utils.roles.mapping import ROLE_FILE_META_USERS
DOMAIN = default_domain_primary()
def _write_users(base_dir: Path, role_name: str, users: dict) -> None:
"""Write meta/users.yml — file root IS the users map."""
@@ -190,11 +193,11 @@ class TestUsersLookup(unittest.TestCase):
result = self.lookup.run(
["sld"],
variables={"domain": "auth.infinito.test"},
variables={"domain": f"auth.{DOMAIN}"},
roles_dir=str(self._tmp / "roles"),
)[0]
self.assertEqual(result["username"], "infinito")
self.assertEqual(result["username"], DOMAIN.split(".", maxsplit=1)[0])
def test_materializes_sld_from_env_backed_domain_primary(self) -> None:
_write_users(