From 929e7626f0a0b67f2e8fec4a26447b07f1c1cb29 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Tue, 23 Mar 2021 14:33:23 -0400 Subject: [PATCH] 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 Reviewed-by: Veiko Aasa --- .../dynamicdns/tests/dynamicdns.feature | 5 +++ .../dynamicdns/tests/test_functional.py | 36 ++++++++++++++++++- plinth/modules/dynamicdns/views.py | 35 +++++++++++++----- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/plinth/modules/dynamicdns/tests/dynamicdns.feature b/plinth/modules/dynamicdns/tests/dynamicdns.feature index e1c281aa4..707850544 100644 --- a/plinth/modules/dynamicdns/tests/dynamicdns.feature +++ b/plinth/modules/dynamicdns/tests/dynamicdns.feature @@ -14,6 +14,11 @@ Background: Given I'm a logged in user 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 Scenario: Backup and restore configuration Given dynamicdns is configured diff --git a/plinth/modules/dynamicdns/tests/test_functional.py b/plinth/modules/dynamicdns/tests/test_functional.py index a9437558a..c4464264e 100644 --- a/plinth/modules/dynamicdns/tests/test_functional.py +++ b/plinth/modules/dynamicdns/tests/test_functional.py @@ -3,7 +3,9 @@ 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 @@ -20,11 +22,21 @@ def dynamicdns_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') def dynamicdns_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): functional.nav_to_module(browser, 'dynamicdns') browser.find_link_by_href( @@ -41,6 +53,7 @@ def _configure(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']) @@ -78,4 +91,25 @@ def _change_config(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 _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 diff --git a/plinth/modules/dynamicdns/views.py b/plinth/modules/dynamicdns/views.py index bd13de447..da6aa7ecf 100644 --- a/plinth/modules/dynamicdns/views.py +++ b/plinth/modules/dynamicdns/views.py @@ -129,13 +129,33 @@ def _apply_changes(request, old_status, new_status): if new_status.get('use_ipv6'): 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([ - 'configure', '-s', new_status['dynamicdns_server'], '-d', - new_status['dynamicdns_domain'], '-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, + 'configure', + '-s', + new_status['dynamicdns_server'], + '-d', + new_domain_name, + '-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()) if old_status['enabled']: @@ -147,8 +167,7 @@ def _apply_changes(request, old_status, new_status): if new_status['enabled']: domain_added.send_robust(sender='dynamicdns', domain_type='domain-type-dynamic', - name=new_status['dynamicdns_domain'], - services='__all__') + name=new_domain_name, services='__all__') _run(['start']) messages.success(request, _('Configuration updated'))