mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 07:26:18 -05:00
controller: selectable hotspot protocol (WPA2/WPA3) with device capability probing
Probe the selected WiFi device with iw to determine which hotspot protocols it can host: WPA2 requires AP mode; WPA3 requires SAE in AP mode (SAE_OFFLOAD_AP, or a mac80211 driver with the CMAC cipher for software SAE). The Raspberry Pi's brcmfmac supports neither, so Pis correctly offer WPA2 only (verified against real Pi 4/Pi 5 iw output). The protocol is saved as hotspot.protocol in controller.yaml. enable_hotspot() now always sets the Hotspot connection's key-mgmt explicitly (sae + required PMF for WPA3) so a reused profile cannot keep a stale protocol, and reverts to WPA2 if the driver rejects SAE. New GET /api/hotspot/protocols endpoint; protocol dropdowns added to both the ControllerPage React UI and the fallback controller UI. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
2355095391
commit
8687816b84
10 changed files with 545 additions and 16 deletions
|
|
@ -52,6 +52,34 @@ class TestHotspotDevicesEndpoint:
|
|||
assert response.json() == {"devices": []}
|
||||
|
||||
|
||||
class TestHotspotProtocolsEndpoint:
|
||||
"""GET /api/hotspot/protocols lists the protocols a device can host."""
|
||||
|
||||
def test_protocols_endpoint_shape(self, test_client):
|
||||
"""Should probe the requested device."""
|
||||
from unittest import mock
|
||||
with mock.patch("controller.api.admin.get_device_hotspot_protocols",
|
||||
return_value=["wpa2", "wpa3"]) as mock_protocols:
|
||||
response = test_client.get("/api/hotspot/protocols?device=wlp2s0")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"device": "wlp2s0", "protocols": ["wpa2", "wpa3"]}
|
||||
mock_protocols.assert_called_once_with("wlp2s0")
|
||||
|
||||
def test_protocols_defaults_to_configured_device(self, test_client):
|
||||
"""Should probe the configured hotspot device when none is given."""
|
||||
from unittest import mock
|
||||
with mock.patch("controller.api.admin.get_device_hotspot_protocols", return_value=["wpa2"]):
|
||||
response = test_client.get("/api/hotspot/protocols")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"device": "wlan0", "protocols": ["wpa2"]}
|
||||
|
||||
def test_protocols_empty_in_docker(self, test_client_docker_mode):
|
||||
"""Docker mode cannot host a hotspot."""
|
||||
response = test_client_docker_mode.get("/api/hotspot/protocols?device=wlan0")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"device": "wlan0", "protocols": []}
|
||||
|
||||
|
||||
class TestHotspotSettingsEndpoint:
|
||||
"""GET/POST /api/hotspot/settings manage hotspot settings in controller.yaml."""
|
||||
|
||||
|
|
@ -59,23 +87,31 @@ class TestHotspotSettingsEndpoint:
|
|||
"""Should return the current hotspot settings."""
|
||||
response = test_client.get("/api/hotspot/settings")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"device": "wlan0", "ssid": "WROLPi", "password": "wrolpi hotspot"}
|
||||
assert response.json() == {"device": "wlan0", "ssid": "WROLPi", "password": "wrolpi hotspot",
|
||||
"protocol": "wpa2"}
|
||||
|
||||
def test_post_settings(self, test_client, mock_config_path):
|
||||
"""Should update settings and persist them to controller.yaml."""
|
||||
response = test_client.post(
|
||||
"/api/hotspot/settings",
|
||||
json={"device": "wlp2s0", "ssid": "RafaelPi", "password": "password123"},
|
||||
json={"device": "wlp2s0", "ssid": "RafaelPi", "password": "password123", "protocol": "wpa3"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"device": "wlp2s0", "ssid": "RafaelPi", "password": "password123"}
|
||||
assert response.json() == {"device": "wlp2s0", "ssid": "RafaelPi", "password": "password123",
|
||||
"protocol": "wpa3"}
|
||||
assert "wlp2s0" in mock_config_path.read_text()
|
||||
assert "wpa3" in mock_config_path.read_text()
|
||||
|
||||
def test_post_rejects_short_password(self, test_client, mock_config_path):
|
||||
"""Should reject a password shorter than 8 characters."""
|
||||
response = test_client.post("/api/hotspot/settings", json={"password": "short"})
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_post_rejects_invalid_protocol(self, test_client, mock_config_path):
|
||||
"""Should reject protocols other than wpa2/wpa3."""
|
||||
response = test_client.post("/api/hotspot/settings", json={"protocol": "wep"})
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_post_rejected_in_docker(self, test_client_docker_mode):
|
||||
"""Should reject settings changes in Docker mode."""
|
||||
response = test_client_docker_mode.post("/api/hotspot/settings", json={"device": "wlp2s0"})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue