Commit 55b5723a by PLN (Algolia)

devname: derive the LAN-face host name instead of hard-coding mac.local

Names answer as <name>.<lan host>.local. The host is DEVNAME_LAN_HOST,
else lan_host in DEVNAME_HOME/config.json, else the platform default:
mac on macOS (unchanged, so phones and the issued cert keep working)
and the short hostname elsewhere, the name avahi already announces.
The ssh gate host is configurable the same way (lan_gate_ssh). The
index page script and CA banner follow the derived names.
parent c8f78544
......@@ -14,8 +14,9 @@ from unittest import mock
ROOT = pathlib.Path(__file__).resolve().parent.parent
def load_module(conf):
def load_module(conf, lan_host="mac"):
os.environ["DEVNAME_HOME"] = conf
os.environ["DEVNAME_LAN_HOST"] = lan_host # pinned: the LAN-face tests below speak the historic mac.local
loader = importlib.machinery.SourceFileLoader("devname_under_test", str(ROOT / "bin" / "devname"))
spec = importlib.util.spec_from_loader("devname_under_test", loader)
mod = importlib.util.module_from_spec(spec)
......@@ -377,6 +378,35 @@ class DevnameTests(unittest.TestCase):
self.assertIn("domovoy-admin", self.dn.HANDSHAKE_ARGS)
self.assertIn("BatchMode=yes", self.dn.HANDSHAKE_ARGS) # never hangs on a passphrase prompt
def test_lan_host_env_then_config_then_platform_default(self):
with mock.patch.dict(os.environ, {"DEVNAME_LAN_HOST": ""}):
with mock.patch.object(self.dn, "PLAT", self.dn.MacPlatform()):
self.assertEqual(self.dn.lan_host({}), "mac") # the Mac keeps mac.local with no config at all
with mock.patch.object(self.dn, "PLAT", self.dn.LinuxPlatform({}, systemd=True)), \
mock.patch.object(self.dn.socket, "gethostname", return_value="XPS24.lan"):
self.assertEqual(self.dn.lan_host({}), "xps24") # Linux: the short hostname avahi already announces
self.assertEqual(self.dn.PLAT.own_mdns_name(), "xps24.local")
self.assertEqual(self.dn.lan_host({"lan_host": "Desk Box"}), "desk-box") # config wins
with mock.patch.dict(os.environ, {"DEVNAME_LAN_HOST": "studio"}):
self.assertEqual(self.dn.lan_host({"lan_host": "desk"}), "studio") # env wins over config
def test_lan_host_from_config_file_drives_every_face(self):
conf = pathlib.Path(self._tmp.name)
(conf / "config.json").write_text('{"lan_host": "xps24", "lan_gate_ssh": "pi-admin"}')
with mock.patch.dict(os.environ, {"DEVNAME_LAN_HOST": ""}):
dn = load_module(self._tmp.name, lan_host="")
self.assertEqual((dn.GATEWAY_HOST, dn.LAN_SUFFIX), ("xps24.local", ".xps24.local"))
self.assertIn("pi-admin", dn.HANDSHAKE_ARGS)
reg = {"entries": {"bench.sre.localhost": {"port": 8895, "rewrite": True}}}
text = dn.render_caddyfile(reg, True, lan=True)
self.assertIn("https://bench.sre.xps24.local {", text)
self.assertIn("http://xps24.local {", text)
self.assertNotIn("mac.local", text)
page = dn.index_page(lan=True)
self.assertIn("http://xps24.local/CA", page)
self.assertIn(r"/(^|\.)xps24\.local$/", page) # the hydration script follows the same face
self.assertNotIn("mac.local", page)
def test_lan_page_rewrites_links_and_shows_the_ca_banner(self):
self.run_cli("ensure", "sre", "--service", "bench", "--port", "8895")
local = self.dn.index_page()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment