From ea48448a72fd4828fda4717376fc6e86999f62dd Mon Sep 17 00:00:00 2001 From: Frederico Gomes Date: Tue, 21 Apr 2026 19:50:28 +0100 Subject: [PATCH] wireguard: Added functional test for auto add client flow Signed-off-by: Frederico Gomes Reviewed-by: James Valleroy --- .../templates/wireguard_auto_add_client.html | 12 +++-- .../wireguard/tests/test_functional.py | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/plinth/modules/wireguard/templates/wireguard_auto_add_client.html b/plinth/modules/wireguard/templates/wireguard_auto_add_client.html index f62346fb6..2baa8595d 100644 --- a/plinth/modules/wireguard/templates/wireguard_auto_add_client.html +++ b/plinth/modules/wireguard/templates/wireguard_auto_add_client.html @@ -21,13 +21,15 @@ - + + + +
{% trans "IP Address" %}{{ next_ip }}
{% trans "Endpoint" %}{{ endpoint }}
{% trans "Public Key" %}{{ client_pubkey }}
{% trans "Public Key" %}{{ client_pubkey }}
{% trans "Private Key" %} -
{% trans "Click to reveal" %} +
+ {% trans "Click to reveal" %} {{ client_privkey }} -
-
@@ -65,7 +67,7 @@
- {% trans "Cancel" %} diff --git a/plinth/modules/wireguard/tests/test_functional.py b/plinth/modules/wireguard/tests/test_functional.py index b9ed811fa..071d4c51a 100644 --- a/plinth/modules/wireguard/tests/test_functional.py +++ b/plinth/modules/wireguard/tests/test_functional.py @@ -113,6 +113,53 @@ class TestWireguardApp(functional.BaseAppTests): assert not self._client_exists(session_browser, self._client_public_key2) + def test_auto_add_client(self, session_browser): + """Test the automatic client generation and addition flow.""" + functional.nav_to_module(session_browser, 'wireguard') + + # Start server if needed (reuse existing logic) + # Extract to reusable method + start_server_button = session_browser.find_by_css('.btn-start-server') + if start_server_button: + with functional.wait_for_page_update(session_browser): + start_server_button.first.click() + + session_browser.find_by_css('.btn-auto-add-client').first.click() + + client_pubkey = session_browser.find_by_css( + '.pubkey-val').first.text.strip() + + # Verify private key reveal + privkey_reveal = session_browser.find_by_css( + '.privkey-val') + assert privkey_reveal, "Private key reveal should be present" + privkey_reveal.click() + client_privkey = session_browser.find_by_css( + '.privkey-val').text.splitlines()[1] + assert len(client_privkey) == 44, (("Private key should be base64 " + "(44 chars)")) + + # Verify config download and QR links + download_link = session_browser.links.find_by_href( + '/freedombox/apps/wireguard/client/auto-add/action/download/') + qr_link = session_browser.links.find_by_href( + '/freedombox/apps/wireguard/client/auto-add/action/qr/') + assert download_link, "Download config link should exist" + assert qr_link, "QR code link should exist" + + # Submit to add the client + with functional.wait_for_page_update(session_browser): + session_browser.find_by_css( + '.btn-auto-add-connection').first.click() + + # Verify client was added successfully + assert self._client_exists(session_browser, client_pubkey), (( + "Auto-generated client should exist")) + + # Clean up + self._delete_client(session_browser, client_pubkey) + assert not self._client_exists(session_browser, client_pubkey) + @staticmethod def _get_server_href(browser, key): """Return the href for server show page."""