dynamicdns: Convert entered domain name to lower case

Domain name is not case sensitive, but Let's Encrypt certificate paths
use lower-case domain name.

Add an extra 1 second delay to tests that configure DynamicDNS domain.

Test: DynamicDNS functional tests are passing.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
James Valleroy 2021-03-23 14:33:23 -04:00 committed by Veiko Aasa
parent bdd078a406
commit 929e7626f0
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
3 changed files with 67 additions and 9 deletions

View File

@ -14,6 +14,11 @@ Background:
Given I'm a logged in user Given I'm a logged in user
And the dynamicdns application is installed And the dynamicdns application is installed
Scenario: Capitalized domain name
Given dynamicdns is configured
When I change the domain name to FreedomBox.example.com
Then the domain name should be freedombox.example.com
@backups @backups
Scenario: Backup and restore configuration Scenario: Backup and restore configuration
Given dynamicdns is configured Given dynamicdns is configured

View File

@ -3,7 +3,9 @@
Functional, browser based tests for dynamicdns app. Functional, browser based tests for dynamicdns app.
""" """
from pytest_bdd import given, scenarios, then, when import time
from pytest_bdd import given, parsers, scenarios, then, when
from plinth.tests import functional from plinth.tests import functional
@ -20,11 +22,21 @@ def dynamicdns_change_config(session_browser):
_change_config(session_browser) _change_config(session_browser)
@when(parsers.parse('I change the domain name to {domain:S}'))
def dynamicdns_change_domain(session_browser, domain):
_configure_domain(session_browser, domain)
@then('dynamicdns should have the original configuration') @then('dynamicdns should have the original configuration')
def dynamicdns_has_original_config(session_browser): def dynamicdns_has_original_config(session_browser):
assert _has_original_config(session_browser) assert _has_original_config(session_browser)
@then(parsers.parse('the domain name should be {domain:S}'))
def dynamicdns_has_domain(session_browser, domain):
assert _get_domain(session_browser) == domain
def _configure(browser): def _configure(browser):
functional.nav_to_module(browser, 'dynamicdns') functional.nav_to_module(browser, 'dynamicdns')
browser.find_link_by_href( browser.find_link_by_href(
@ -41,6 +53,7 @@ def _configure(browser):
# After a domain name change, Let's Encrypt will restart the web # After a domain name change, Let's Encrypt will restart the web
# server and could cause a connection failure. # server and could cause a connection failure.
time.sleep(1)
functional.eventually(functional.nav_to_module, [browser, 'dynamicdns']) functional.eventually(functional.nav_to_module, [browser, 'dynamicdns'])
@ -78,4 +91,25 @@ def _change_config(browser):
# After a domain name change, Let's Encrypt will restart the web # After a domain name change, Let's Encrypt will restart the web
# server and could cause a connection failure. # server and could cause a connection failure.
time.sleep(1)
functional.eventually(functional.nav_to_module, [browser, 'dynamicdns']) functional.eventually(functional.nav_to_module, [browser, 'dynamicdns'])
def _configure_domain(browser, domain):
functional.nav_to_module(browser, 'dynamicdns')
browser.find_link_by_href(
'/plinth/sys/dynamicdns/configure/').first.click()
browser.find_by_id('id_dynamicdns_domain').fill(domain)
functional.submit(browser)
# After a domain name change, Let's Encrypt will restart the web
# server and could cause a connection failure.
time.sleep(1)
functional.eventually(functional.nav_to_module, [browser, 'dynamicdns'])
def _get_domain(browser):
functional.nav_to_module(browser, 'dynamicdns')
browser.find_link_by_href(
'/plinth/sys/dynamicdns/configure/').first.click()
return browser.find_by_id('id_dynamicdns_domain').value

View File

@ -129,13 +129,33 @@ def _apply_changes(request, old_status, new_status):
if new_status.get('use_ipv6'): if new_status.get('use_ipv6'):
use_ipv6 = "enabled" use_ipv6 = "enabled"
# Domain name should be ASCII. If it's unicode, convert to
# ASCII.
new_domain_name = str(new_status['dynamicdns_domain'])
# Domain name is not case sensitive, but Let's Encrypt
# certificate paths use lower-case domain name.
new_domain_name = new_domain_name.lower()
_run([ _run([
'configure', '-s', new_status['dynamicdns_server'], '-d', 'configure',
new_status['dynamicdns_domain'], '-u', '-s',
new_status['dynamicdns_user'], '-p', '-I', new_status['dynamicdns_server'],
new_status['dynamicdns_ipurl'], '-U', '-d',
new_status['dynamicdns_update_url'], '-c', disable_ssl_check, '-b', new_domain_name,
use_http_basic_auth, '-6', use_ipv6, '-u',
new_status['dynamicdns_user'],
'-p',
'-I',
new_status['dynamicdns_ipurl'],
'-U',
new_status['dynamicdns_update_url'],
'-c',
disable_ssl_check,
'-b',
use_http_basic_auth,
'-6',
use_ipv6,
], input=new_status['dynamicdns_secret'].encode()) ], input=new_status['dynamicdns_secret'].encode())
if old_status['enabled']: if old_status['enabled']:
@ -147,8 +167,7 @@ def _apply_changes(request, old_status, new_status):
if new_status['enabled']: if new_status['enabled']:
domain_added.send_robust(sender='dynamicdns', domain_added.send_robust(sender='dynamicdns',
domain_type='domain-type-dynamic', domain_type='domain-type-dynamic',
name=new_status['dynamicdns_domain'], name=new_domain_name, services='__all__')
services='__all__')
_run(['start']) _run(['start'])
messages.success(request, _('Configuration updated')) messages.success(request, _('Configuration updated'))