mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
- Change the mechanism for storing domain names in /etc/hosts. Don't write hostname to /etc/hosts. Don't prepend hostname to domain name. This means that when hostname changes, set_domain_name need not be called. - This means that domain names such as example.fbx.one were not resolvable using /etc/hosts but these will now resolve to 127.0.1.1. This is a minor concern to becoming a breaking change. - Don't use socket.getfqdn() for finding the domain name of the machine. Instead read from /etc/hosts. There does not seem to a glibc/python API for querying domain names from /etc/hosts with all variations it allows. Forward resolution properly works no matter the library. - Drop a pre-Python 3 conversion from unicode to ascii string for hostname. This is no longer relevant. - Domain name form is now domain add form. Passing domain name is mandatory. Domain delete form and view have been introduced. - Use augeas to edit hosts file. Add privileged methods to add/delete/get domains. Add method to migration from old format to new. Support reading old format too in get_domains. Tests: - Without hostname written in /etc/hosts, 'resolvectl query <hostname>' and 'ping <hostname>' work. - With old /etc/hosts format apply patches and restart service. It will be converted to new format. - Adding a domain adds a new line to /etc/hosts file. The domain is shown in domains list in Names app. Applications get reconfigured with the new domain name. - Deleting a domain adds a new line to /etc/hosts file. The domain is shown in domains list in Names app. Applications get reconfigured with the new domain name. - Restarting app triggers domain added signal for all domains and all the domains are shown in the Names app. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""Tests for forms in names app."""
|
|
|
|
from ..forms import DomainAddForm, HostnameForm
|
|
|
|
|
|
def test_hostname_field():
|
|
"""Test that hostname field accepts only valid hostnames."""
|
|
valid_hostnames = [
|
|
'a', '0a', 'a0', 'AAA', '00', '0-0', 'example-hostname', 'example',
|
|
'012345678901234567890123456789012345678901234567890123456789012'
|
|
]
|
|
invalid_hostnames = [
|
|
'', '-', '-a', 'a-', '.a', 'a.', 'a.a', '?', 'a?a',
|
|
'0123456789012345678901234567890123456789012345678901234567890123'
|
|
]
|
|
|
|
for hostname in valid_hostnames:
|
|
form = HostnameForm({'hostname': hostname})
|
|
assert form.is_valid()
|
|
|
|
for hostname in invalid_hostnames:
|
|
form = HostnameForm({'hostname': hostname})
|
|
assert not form.is_valid()
|
|
|
|
|
|
def test_domain_name_field():
|
|
"""Test that domain name field accepts only valid domain names."""
|
|
valid_domain_names = [
|
|
'a', '0a', 'a0', 'AAA', '00', '0-0', 'example-hostname', 'example',
|
|
'example.org', 'a.b.c.d', 'a-0.b-0.c-0',
|
|
'012345678901234567890123456789012345678901234567890123456789012',
|
|
((('x' * 63) + '.') * 3) + 'x' * 61
|
|
]
|
|
invalid_domain_names = [
|
|
'', '-', '-a', 'a-', '.a', 'a.', '?', 'a?a', 'a..a', 'a.-a', '.',
|
|
((('x' * 63) + '.') * 3) + 'x' * 62, 'x' * 64
|
|
]
|
|
|
|
for domain_name in valid_domain_names:
|
|
form = DomainAddForm({'domain_name': domain_name})
|
|
assert form.is_valid()
|
|
|
|
for domain_name in invalid_domain_names:
|
|
form = DomainAddForm({'domain_name': domain_name})
|
|
assert not form.is_valid()
|