fix(wireless): refuse an unknown MAC ACL mode before sending anything
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 55s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Successful in 2m41s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 55s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m9s
CI / driver (pull_request) Successful in 2m41s
driver / publish (pull_request) Skipped
push_mac_acl wrote macfilter='allow' for "whitelist" and 'deny' for any other mode but "off", so a mode the driver does not know -- a typo, or a new mode from the caller -- became a deny list. It now raises ValueError naming the mode before the first command is sent. Closes #39
This commit is contained in:
1 parent
780b635174
commit
17d9bead50
3 files changed
+20
-1
No files matched your search
@@ -70,6 +70,9 @@ recorded here; their history is the git log.
|
||||
`manage_service("lldpd", "enable")` and `manage_service("lldpd", "start")` (#8).
|
||||
|
||||
### Fixed
|
||||
- `push_mac_acl()` raises `ValueError` for a mode other than `"off"`, `"whitelist"` and
|
||||
`"blacklist"`, before anything is sent. An unknown mode was written as a deny list
|
||||
(#39).
|
||||
- `push_mac_acl()` and `push_radio_channel()` raise when the router refuses a step
|
||||
(`CommandErrorException`, naming the `uci` command or the wifi restart and what the
|
||||
router said). They used to return normally after a refused `uci set`, `add_list`,
|
||||
|
||||
@@ -29,6 +29,8 @@ _WIFI_RELOAD = "wifi reload"
|
||||
#: A full down/up of every radio; a channel needs it (see ``push_radio_channel``).
|
||||
_WIFI_RESTART = "wifi"
|
||||
_ACL_OPTIONS = ("macfilter", "maclist")
|
||||
#: The modes ``push_mac_acl`` takes, and the ``macfilter`` each writes ("off" writes none).
|
||||
_MACFILTER_BY_MODE = {"whitelist": "allow", "blacklist": "deny", "off": None}
|
||||
|
||||
|
||||
def _mac_acl_changes(sec: UciSection, mode: str, macs: list[str]) -> list[str]:
|
||||
@@ -40,7 +42,7 @@ def _mac_acl_changes(sec: UciSection, mode: str, macs: list[str]) -> list[str]:
|
||||
present = [opt for opt in _ACL_OPTIONS if opt in sec.options]
|
||||
if mode == "off":
|
||||
return [uci("delete", f"{sec.ref}.{opt}") for opt in present]
|
||||
changes = [uci("set", f"{sec.ref}.macfilter={'allow' if mode == 'whitelist' else 'deny'}")]
|
||||
changes = [uci("set", f"{sec.ref}.macfilter={_MACFILTER_BY_MODE[mode]}")]
|
||||
if "maclist" in present:
|
||||
changes.append(uci("delete", f"{sec.ref}.maclist"))
|
||||
changes += [uci("add_list", f"{sec.ref}.maclist={mac}") for mac in macs]
|
||||
@@ -634,9 +636,13 @@ class OpenWrtWirelessMixin(UciStepsMixin):
|
||||
:param macs: MAC addresses to set as the maclist. Only the entries for the
|
||||
active mode's list are ever passed in — the caller resolves whitelist
|
||||
vs. blacklist before calling.
|
||||
:raises ValueError: for a mode other than the three, before anything is sent.
|
||||
:raises CommandErrorException: when no wifi-iface carries *ssid_name*, or
|
||||
when a step is refused.
|
||||
"""
|
||||
if mode not in _MACFILTER_BY_MODE:
|
||||
known = ", ".join(map(repr, _MACFILTER_BY_MODE))
|
||||
raise ValueError(f"unknown MAC ACL mode {mode!r}; expected one of {known}")
|
||||
effective_mode = "off" if (mode == "whitelist" and not macs) else mode
|
||||
sections = [
|
||||
sec
|
||||
|
||||
@@ -293,3 +293,13 @@ def test_a_failed_wifi_restart_raises_naming_it():
|
||||
ap = _Ap({"wifi": CommandResult("", "", 1)})
|
||||
with pytest.raises(CommandErrorException, match="`wifi`.*exit status 1"):
|
||||
_driver(ap).push_radio_channel("radio0", 6)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ["deny", "Blacklist", "disable", ""])
|
||||
def test_an_unknown_mode_raises_before_anything_is_sent(mode):
|
||||
"""A mode the driver does not know was written as a deny list (#39)."""
|
||||
ap = _Ap()
|
||||
with pytest.raises(ValueError, match=repr(mode)):
|
||||
_driver(ap).push_mac_acl("CorpWiFi", mode, ["00:00:5E:00:53:0A"])
|
||||
|
||||
assert ap.commands == []
|
||||
Reference in new issue
Block a user