wireguard: Added functional test for auto add client flow

Signed-off-by: Frederico Gomes <fredericojfgomes@gmail.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Frederico Gomes 2026-04-21 19:50:28 +01:00 committed by James Valleroy
parent 050a5366c1
commit ea48448a72
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 54 additions and 5 deletions

View File

@ -21,13 +21,15 @@
<table class="table table-sm">
<tr><td>{% trans "IP Address" %}</td><td>{{ next_ip }}</td></tr>
<tr><td>{% trans "Endpoint" %}</td><td>{{ endpoint }}</td></tr>
<tr><td>{% trans "Public Key" %}</td><td>{{ client_pubkey }}</td></tr>
<tr><td>{% trans "Public Key" %}</td>
<td class="pubkey-val">{{ client_pubkey }}</td></tr>
<tr><td>{% trans "Private Key" %}</td>
<td>
<details><summary>{% trans "Click to reveal" %}</summary>
<details class="privkey-val">
<summary>{% trans "Click to reveal" %}</summary>
{{ client_privkey }}
</details>
</td></tr>
</details>
</td></tr>
</table>
<div class="alert alert-warning">
@ -65,7 +67,7 @@
</div>
<div class="form-actions">
<input type="submit" class="btn btn-primary"
<input type="submit" class="btn btn-primary btn-auto-add-connection"
value="{% trans "Add Connection" %}"/>
<a href="{% url 'wireguard:index' %}" class="btn btn-secondary">
{% trans "Cancel" %}

View File

@ -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."""