controller: address hotspot protocol review findings
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

- Reset a saved protocol the newly probed device does not support
  instead of offering it (both UIs); a successful probe is
  authoritative, the saved value is only kept when probing fails.
- Ignore out-of-order protocol probe responses when switching devices
  quickly (both UIs).
- Verify the WPA2 rollback after a failed WPA3 activation; report that
  the hotspot may be down instead of claiming the revert succeeded.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-28 20:59:10 -06:00
parent 8687816b84
commit 2baa9cbd2e
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 67 additions and 12 deletions

View file

@ -1451,16 +1451,32 @@ function HotspotSettingsForm() {
if (!form.device) {
return;
}
// Ignore out-of-order responses when the user switches devices quickly.
let cancelled = false;
const fetchProtocols = async () => {
try {
const response = await getHotspotProtocols(form.device);
setProtocols(response.protocols || []);
if (cancelled) {
return;
}
const supported = response.protocols || [];
setProtocols(supported);
// Reset a selection the probed device does not support (e.g. WPA3 kept
// after switching to a WPA2-only adapter).
if (supported.length) {
setForm(f => supported.includes(f.protocol) ? f : {...f, protocol: supported[0]});
}
} catch (e) {
console.error('Failed to fetch hotspot protocols', e);
setProtocols([]);
if (!cancelled) {
console.error('Failed to fetch hotspot protocols', e);
setProtocols([]);
}
}
};
fetchProtocols();
return () => {
cancelled = true;
};
}, [form.device]);
const handleSave = async () => {

View file

@ -208,6 +208,19 @@ describe('ControllerPage', () => {
});
});
test('a saved protocol the device does not support is reset to a supported one', async () => {
const controllerApi = require('../../api/controller');
controllerApi.getHotspotSettings.mockResolvedValue(
{device: 'wlan0', ssid: 'WROLPi', password: 'wrolpi hotspot', protocol: 'wpa3'});
controllerApi.getHotspotProtocols.mockResolvedValue({device: 'wlan0', protocols: ['wpa2']});
renderControllerPage();
// The stale WPA3 selection is replaced by the only protocol the device supports.
await waitFor(() => {
expect(screen.getAllByText('WPA2 (most compatible)').length).toBeGreaterThan(0);
});
expect(screen.queryByText('WPA3')).not.toBeInTheDocument();
});
test('hotspot protocol dropdown only offers WPA2 on a Raspberry Pi', async () => {
const {getHotspotProtocols} = require('../../api/controller');
getHotspotProtocols.mockResolvedValue({device: 'wlan0', protocols: ['wpa2']});