fix(radius): the getters raise when the firewall does not answer (#49)
driver / standard (pull_request) Failing after 17s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 1m0s
driver / test (3.12) (pull_request) Successful in 1m12s
driver / lowest (pull_request) Successful in 32s
driver / build (pull_request) Successful in 29s
driver / security (pull_request) Successful in 1m3s
CI / driver (pull_request) Failing after 2m21s
driver / publish (pull_request) Skipped

get_radius_clients() and get_radius_users() caught every exception and
returned [], so a caller could not tell no entries from no answer. netOrk
asks them whether an entry whose add was cut off is on the firewall, and an
empty list would have made it forget a NAS client still live there. Both now
raise for a failed request or an answer without rows; an empty list is the
firewall's answer, which RADIUS_READS_RAISE = True declares. A saved add
whose id lookup fails still answers success, with no id.

Closes #49
This commit is contained in:
Christian Manivong committed 2026-11-15 19:02:08 +01:00
1 parent 521f7c5d73
commit 9c31afd5d7
3 files changed
+72 -18

No files matched your search

+39 -2
View File
@@ -1251,12 +1251,33 @@ class TestGetRadiusClients:
driver.get_radius_clients()
assert calls == ["/api/freeradius/client/search_client"]
def test_api_error_returns_empty_list(self, driver):
def test_a_failed_read_raises_rather_than_answering_none(self, driver):
"""An empty list must mean the firewall has none (#49)."""
driver._get = lambda path: (_ for _ in ()).throw(Exception("404"))
with pytest.raises(Exception, match="404"):
driver.get_radius_clients()
def test_an_answer_without_rows_raises(self, driver):
driver._get = lambda path: {"error": "plugin not installed"}
with pytest.raises(RuntimeError, match="rows"):
driver.get_radius_clients()
def test_no_clients_is_an_empty_list(self, driver):
driver._get = lambda path: {"rows": [], "total": 0}
assert driver.get_radius_clients() == []
def test_the_driver_says_its_reads_raise(self, driver):
assert type(driver).RADIUS_READS_RAISE is True
class TestCreateRadiusClient:
def test_a_saved_add_whose_lookup_fails_is_still_a_success(self, driver):
"""The add went through: its id is unknown, the add is not undone (#49)."""
driver._post = lambda path, data=None: {"result": "saved"}
driver._get = lambda path: (_ for _ in ()).throw(Exception("timeout"))
result = driver.create_radius_client("ap-lobby", "10.0.0.5/32", "s3cr3t")
assert result == {"success": True, "id": None}
def test_success_returns_remote_id(self, driver):
driver._post = lambda path, data=None: {"result": "saved"}
driver._get = lambda path: RADIUS_CLIENTS_RESPONSE
@@ -1337,12 +1358,28 @@ class TestGetRadiusUsers:
driver.get_radius_users()
assert calls == ["/api/freeradius/user/search_user"]
def test_api_error_returns_empty_list(self, driver):
def test_a_failed_read_raises_rather_than_answering_none(self, driver):
driver._get = lambda path: (_ for _ in ()).throw(Exception("404"))
with pytest.raises(Exception, match="404"):
driver.get_radius_users()
def test_an_answer_without_rows_raises(self, driver):
driver._get = lambda path: {"error": "plugin not installed"}
with pytest.raises(RuntimeError, match="rows"):
driver.get_radius_users()
def test_no_users_is_an_empty_list(self, driver):
driver._get = lambda path: {"rows": [], "total": 0}
assert driver.get_radius_users() == []
class TestCreateRadiusUser:
def test_a_saved_add_whose_lookup_fails_is_still_a_success(self, driver):
driver._post = lambda path, data=None: {"result": "saved"}
driver._get = lambda path: (_ for _ in ()).throw(Exception("timeout"))
result = driver.create_radius_user("jdoe", "hunter2")
assert result == {"success": True, "id": None}
def test_success_returns_remote_id(self, driver):
driver._post = lambda path, data=None: {"result": "saved"}
driver._get = lambda path: RADIUS_USERS_RESPONSE