Skip to content

Commit

Permalink
test invalid channel value
Browse files Browse the repository at this point in the history
use the actual error message from NetworkManager
  • Loading branch information
jkt628 committed Feb 1, 2025
1 parent e69653e commit 2b17e26
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/api/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,31 @@ async def test_api_network_interface_update_wifi_error(api_client: TestClient):
)


async def test_api_network_interface_update_wifi_bad_channel(api_client: TestClient):
"""Test network interface WiFi API error handling for bad channel."""
# Simulate frontend WiFi interface edit where the user selects a bad channel.
resp = await api_client.post(
f"/network/interface/{TEST_INTERFACE_WLAN_NAME}/update",
json={
"enabled": True,
"ipv4": {
"method": "shared",
"address": ["10.42.0.1/24"],
},
"ipv6": {
"method": "auto",
},
"wifi": {"mode": "ap", "ssid": "HotSpot", "band": "bg", "channel": 17},
},
)
result = await resp.json()
assert result["result"] == "error"
assert (
result["message"]
== "Can't create config and activate wlan0: 802-11-wireless.channel: '17' is not a valid channel"
)


async def test_api_network_interface_update_remove(api_client: TestClient):
"""Test network manager api."""
resp = await api_client.post(
Expand Down
9 changes: 9 additions & 0 deletions tests/dbus_service_mocks/network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ def AddAndActivateConnection(
"org.freedesktop.NetworkManager.Device.InvalidConnection",
"A 'wireless' setting with a valid SSID is required if no AP path was given.",
)
if (
"channel" in connection["802-11-wireless"]
and connection["802-11-wireless"]["channel"].value > 14
):
raise DBusError(
"org.freedesktop.NetworkManager.Device.InvalidConnection",
# this is the actual error from NetworkManager
f"802-11-wireless.channel: '{connection['802-11-wireless']['channel'].value}' is not a valid channel",
)

return [
"/org/freedesktop/NetworkManager/Settings/1",
Expand Down

0 comments on commit 2b17e26

Please sign in to comment.