feat: make DDNS domain_name the effective domain across all services
Unit Tests / test (push) Successful in 11m35s
Unit Tests / test (push) Successful in 11m35s
- ConfigManager.get_effective_domain(): returns domain_name when DDNS
active (pic_ngo/cloudflare/duckdns), domain otherwise. Used by all
public-facing services so they use the real registered FQDN.
- ConfigManager.get_internal_domain(): always returns _identity.domain
(CoreDNS zone name, dnsmasq, cell-link invites — stays internal).
- Silent migration: if domain_mode != lan and domain is generic "cell",
auto-set to {cell_name}.local for unique CoreDNS zone naming.
- caddy_manager: fix custom_domain bug — cloudflare/http01 modes were
reading identity.get('custom_domain') which never exists; now reads
domain_name correctly.
- routes/config, app: expose effective_domain in GET /api/config and
/api/status responses.
- email_manager, routes/email: use get_effective_domain() for
OVERRIDE_HOSTNAME, POSTMASTER_ADDRESS, and new-user email defaults.
- ServiceBus.IDENTITY_CHANGED event: emitted from PUT /api/config and
POST /api/ddns/register after identity writes; caddy_manager and
email_manager subscribe to regenerate config automatically.
- Settings.jsx: hide Local Domain input in non-LAN modes; show
read-only effective_domain with "managed by DDNS" badge and an
Advanced toggle for the internal CoreDNS zone name.
- 11 new test classes covering all new helpers, event subscriptions,
caddy/email handlers, and the custom_domain fix.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -77,7 +77,7 @@ class TestGenerateCaddyfileCloudflare(unittest.TestCase):
|
||||
identity = {
|
||||
'cell_name': 'beta',
|
||||
'domain_mode': 'cloudflare',
|
||||
'custom_domain': 'example.com',
|
||||
'domain_name': 'example.com',
|
||||
}
|
||||
out = mgr.generate_caddyfile(identity, [])
|
||||
self.assertIn('dns cloudflare {$CF_API_TOKEN}', out)
|
||||
@@ -85,6 +85,23 @@ class TestGenerateCaddyfileCloudflare(unittest.TestCase):
|
||||
self.assertIn('email {$ACME_EMAIL}', out)
|
||||
self.assertIn('acme_ca {$ACME_CA_URL}', out)
|
||||
|
||||
def test_caddyfile_cloudflare_uses_domain_name(self):
|
||||
"""Caddyfile must use domain_name for TLS host, not any 'custom_domain' key."""
|
||||
mgr = _mgr()
|
||||
identity = {
|
||||
'cell_name': 'beta',
|
||||
'domain_mode': 'cloudflare',
|
||||
'domain_name': 'home.example.com',
|
||||
'domain': 'home.local',
|
||||
}
|
||||
out = mgr.generate_caddyfile(identity, [])
|
||||
self.assertIn('*.home.example.com', out)
|
||||
self.assertIn('home.example.com', out)
|
||||
# Must not use the internal domain for TLS
|
||||
self.assertNotIn('*.home.local', out)
|
||||
# 'custom_domain' must not appear literally as a key in the output
|
||||
self.assertNotIn('custom_domain', out)
|
||||
|
||||
|
||||
class TestGenerateCaddyfileDuckDns(unittest.TestCase):
|
||||
def test_duckdns_has_dns_duckdns(self):
|
||||
@@ -101,7 +118,7 @@ class TestGenerateCaddyfileHttp01(unittest.TestCase):
|
||||
identity = {
|
||||
'cell_name': 'delta',
|
||||
'domain_mode': 'http01',
|
||||
'custom_domain': 'delta.noip.me',
|
||||
'domain_name': 'delta.noip.me',
|
||||
}
|
||||
services = [
|
||||
{'name': 'calendar', 'caddy_route':
|
||||
@@ -224,5 +241,37 @@ class TestCertStatus(unittest.TestCase):
|
||||
self.assertEqual(out['days_remaining'], 84)
|
||||
|
||||
|
||||
class TestCaddyManagerIdentityChangedSubscription(unittest.TestCase):
|
||||
def test_subscribes_to_identity_changed_on_init(self):
|
||||
"""When service_bus is provided, CaddyManager subscribes to IDENTITY_CHANGED."""
|
||||
from service_bus import EventType
|
||||
mock_bus = MagicMock()
|
||||
mgr = CaddyManager(config_manager=MagicMock(), service_bus=mock_bus)
|
||||
mock_bus.subscribe_to_event.assert_called_once_with(
|
||||
EventType.IDENTITY_CHANGED, mgr._on_identity_changed
|
||||
)
|
||||
|
||||
def test_no_subscription_without_service_bus(self):
|
||||
"""When service_bus is omitted, no subscription is attempted."""
|
||||
mock_bus = MagicMock()
|
||||
CaddyManager(config_manager=MagicMock())
|
||||
mock_bus.subscribe_to_event.assert_not_called()
|
||||
|
||||
def test_on_identity_changed_calls_regenerate_with_installed(self):
|
||||
"""_on_identity_changed calls regenerate_with_installed([])."""
|
||||
mgr = _mgr()
|
||||
with patch.object(mgr, 'regenerate_with_installed', return_value=True) as mock_regen:
|
||||
event = MagicMock()
|
||||
mgr._on_identity_changed(event)
|
||||
mock_regen.assert_called_once_with([])
|
||||
|
||||
def test_on_identity_changed_swallows_exceptions(self):
|
||||
"""_on_identity_changed must not propagate exceptions."""
|
||||
mgr = _mgr()
|
||||
with patch.object(mgr, 'regenerate_with_installed', side_effect=Exception('boom')):
|
||||
event = MagicMock()
|
||||
mgr._on_identity_changed(event) # must not raise
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user