fix(freeradius): return the created entry's remote id from create_radius_*
add_client/add_user's response carries no id, so create_radius_client() and create_radius_user() now look the new entry up via get_radius_clients()/get_radius_users() (matched by name/username) immediately after creation. Callers need this id to address the entry in later set_*/del_* calls -- without it there was no way to store a reference to what was just created.
This commit is contained in:
@@ -1175,11 +1175,17 @@ class TestGetRadiusClients:
|
||||
|
||||
|
||||
class TestCreateRadiusClient:
|
||||
def test_success_reconfigures_service(self, driver):
|
||||
def test_success_returns_remote_id(self, driver):
|
||||
driver._post = lambda path, data=None: {"result": "saved"}
|
||||
driver._get = lambda path: RADIUS_CLIENTS_RESPONSE
|
||||
result = driver.create_radius_client("ap-lobby", "10.0.0.5/32", "s3cr3t")
|
||||
assert result == {"success": True, "id": "e5483f1b-936b-47ba-8cca-24d56ad643c6"}
|
||||
|
||||
def test_success_calls_add_then_reconfigure(self, driver):
|
||||
calls = []
|
||||
driver._post = lambda path, data=None: calls.append((path, data)) or {"result": "saved"}
|
||||
result = driver.create_radius_client("ap-lobby", "10.0.0.5/32", "s3cr3t")
|
||||
assert result == {"success": True}
|
||||
driver._get = lambda path: RADIUS_CLIENTS_RESPONSE
|
||||
driver.create_radius_client("ap-lobby", "10.0.0.5/32", "s3cr3t")
|
||||
assert calls[0] == (
|
||||
"/api/freeradius/client/add_client",
|
||||
{"client": {"name": "ap-lobby", "ip": "10.0.0.5/32", "secret": "s3cr3t"}},
|
||||
@@ -1197,6 +1203,12 @@ class TestCreateRadiusClient:
|
||||
assert result["validations"] == {"client.name": "A value is required."}
|
||||
assert calls == ["/api/freeradius/client/add_client"]
|
||||
|
||||
def test_created_entry_not_found_after_add_returns_no_id(self, driver):
|
||||
driver._post = lambda path, data=None: {"result": "saved"}
|
||||
driver._get = lambda path: {"rows": []}
|
||||
result = driver.create_radius_client("ap-lobby", "10.0.0.5/32", "s3cr3t")
|
||||
assert result == {"success": True, "id": None}
|
||||
|
||||
|
||||
class TestDeleteRadiusClient:
|
||||
def test_success_reconfigures_service(self, driver):
|
||||
@@ -1246,11 +1258,17 @@ class TestGetRadiusUsers:
|
||||
|
||||
|
||||
class TestCreateRadiusUser:
|
||||
def test_success_reconfigures_service(self, driver):
|
||||
def test_success_returns_remote_id(self, driver):
|
||||
driver._post = lambda path, data=None: {"result": "saved"}
|
||||
driver._get = lambda path: RADIUS_USERS_RESPONSE
|
||||
result = driver.create_radius_user("jdoe", "hunter2")
|
||||
assert result == {"success": True, "id": "71da23fd-03f3-4e1f-a7e1-bb25645b981e"}
|
||||
|
||||
def test_success_calls_add_then_reconfigure(self, driver):
|
||||
calls = []
|
||||
driver._post = lambda path, data=None: calls.append((path, data)) or {"result": "saved"}
|
||||
result = driver.create_radius_user("jdoe", "hunter2")
|
||||
assert result == {"success": True}
|
||||
driver._get = lambda path: RADIUS_USERS_RESPONSE
|
||||
driver.create_radius_user("jdoe", "hunter2")
|
||||
assert calls[0] == (
|
||||
"/api/freeradius/user/add_user",
|
||||
{"user": {"username": "jdoe", "password": "hunter2"}},
|
||||
@@ -1267,6 +1285,12 @@ class TestCreateRadiusUser:
|
||||
assert result["success"] is False
|
||||
assert calls == ["/api/freeradius/user/add_user"]
|
||||
|
||||
def test_created_entry_not_found_after_add_returns_no_id(self, driver):
|
||||
driver._post = lambda path, data=None: {"result": "saved"}
|
||||
driver._get = lambda path: {"rows": []}
|
||||
result = driver.create_radius_user("jdoe", "hunter2")
|
||||
assert result == {"success": True, "id": None}
|
||||
|
||||
|
||||
class TestDeleteRadiusUser:
|
||||
def test_success_reconfigures_service(self, driver):
|
||||
|
||||
Reference in New Issue
Block a user