mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 11:26:25 -05:00
captive portal: let acknowledged clients finish so the OS offers "Done"
A phone's sign-in sheet only shows "Done" once the OS re-probes and gets the genuine success reply. The Controller now remembers each client (by hotspot IP) that has loaded the portal page and answers its later probes with the reply each OS expects (Apple "Success" HTML, Android 204, Windows "Microsoft Connect Test", ...). The set is cleared when the hotspot starts so a new session shows the page again. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
66151df6c6
commit
f182e64e17
7 changed files with 108 additions and 15 deletions
|
|
@ -1089,6 +1089,13 @@ class TestStartHotspot:
|
|||
assert 'address=/captive.apple.com/10.42.1.1' in captive_portal.INCLUDE_FILE.read_text()
|
||||
assert run.call_args_list[-1][0][0] == ["nmcli", "connection", "up", "Hotspot"]
|
||||
|
||||
def test_start_forgets_acknowledged_clients(self, reset_runtime_config):
|
||||
"""A new hotspot session shows every device the portal page again."""
|
||||
captive_portal.acknowledge_client('10.42.0.210')
|
||||
result, _ = self._start_with_nmcli()
|
||||
assert result["success"] is True
|
||||
assert not captive_portal.is_client_acknowledged('10.42.0.210')
|
||||
|
||||
def test_no_reactivation_when_ip_matches(self, reset_runtime_config):
|
||||
result, run = self._start_with_nmcli()
|
||||
ups = [c for c in run.call_args_list if c[0][0][:3] == ['nmcli', 'connection', 'up']]
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@ from controller.lib.captive_portal import (
|
|||
FRIENDLY_NAME,
|
||||
PROBE_HOSTS,
|
||||
PROBE_PATHS,
|
||||
PROBE_SUCCESS_RESPONSES,
|
||||
acknowledge_client,
|
||||
apply_dnsmasq_config,
|
||||
is_client_acknowledged,
|
||||
reset_acknowledged_clients,
|
||||
dnsmasq_config_ip,
|
||||
get_hotspot_ip,
|
||||
is_captive_portal_enabled,
|
||||
|
|
@ -164,6 +168,49 @@ class TestProbeRedirects:
|
|||
assert response.status_code == 404
|
||||
|
||||
|
||||
class TestAcknowledgedClients:
|
||||
"""Once a client has seen the portal page, its probes say "online" so the OS offers Done."""
|
||||
|
||||
@pytest.mark.parametrize("path", PROBE_PATHS)
|
||||
def test_probe_succeeds_after_portal_seen(self, test_client, path):
|
||||
with mock.patch("controller.api.captive_portal.get_hotspot_ip", return_value='10.42.0.1'):
|
||||
assert test_client.get('/portal').status_code == 200
|
||||
response = test_client.get(path, follow_redirects=False)
|
||||
status, media_type, body = PROBE_SUCCESS_RESPONSES[path]
|
||||
assert response.status_code == status
|
||||
assert response.text == body
|
||||
assert response.headers['cache-control'] == 'no-store'
|
||||
if body:
|
||||
assert response.headers['content-type'].startswith(media_type)
|
||||
|
||||
def test_apple_probe_says_success(self, test_client):
|
||||
"""iOS looks for this exact body before it shows the Done button."""
|
||||
acknowledge_client('testclient')
|
||||
response = test_client.get('/hotspot-detect.html')
|
||||
assert response.status_code == 200
|
||||
assert '<BODY>Success</BODY>' in response.text
|
||||
|
||||
def test_portal_404_does_not_acknowledge(self, test_client):
|
||||
"""A hotspot-down 404 is not the client seeing the address."""
|
||||
with mock.patch("controller.api.captive_portal.get_hotspot_ip", return_value=None):
|
||||
assert test_client.get('/portal').status_code == 404
|
||||
assert test_client.get('/generate_204', follow_redirects=False).status_code == 302
|
||||
|
||||
def test_other_clients_still_redirected(self, test_client):
|
||||
acknowledge_client('10.42.0.99')
|
||||
assert not is_client_acknowledged('testclient')
|
||||
assert test_client.get('/generate_204', follow_redirects=False).status_code == 302
|
||||
|
||||
def test_reset_shows_portal_again(self, test_client):
|
||||
acknowledge_client('testclient')
|
||||
reset_acknowledged_clients()
|
||||
assert test_client.get('/generate_204', follow_redirects=False).status_code == 302
|
||||
|
||||
def test_acknowledge_ignores_missing_ip(self):
|
||||
acknowledge_client(None)
|
||||
assert not is_client_acknowledged(None)
|
||||
|
||||
|
||||
class TestPortalPage:
|
||||
|
||||
def test_shows_address_and_links(self, test_client):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue