Keep RBAC administrative recipes bounded and private

Reuse the existing private-response API helper for all role and user operations, preserving exact methods, bodies, privileges and targets. Document independent decisions and uncertain mutation readback; exercise copied commands against synthetic private success, denial, redirect and incomplete responses without exposing credentials or retrying.

Contract-Neutral: Documentation, mirrored guides and copied-recipe regression tests only; no runtime authentication, RBAC, API or frontend behaviour changes.
Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-10-09 16:51:14 +01:00
parent ad583f6d5f
commit 8a4f31b504
6 changed files with 171 additions and 66 deletions

View File

@@ -366,6 +366,39 @@ class APIAuthDocsTest(unittest.TestCase):
self.assertEqual(result.returncode, exitcode, result.stderr.decode())
self.assertEqual(len(requests), 1, "uncertain POST must not be repeated or redirected")
def test_shared_helper_preserves_method_and_body_for_existing_admin_operations(self):
with private_recording_server() as (port, requests), tempfile.TemporaryDirectory() as temporary:
for method in ("GET", "POST", "PUT", "DELETE"):
with self.subTest(method=method):
call = f"pulse_api {method} /api/admin/roles <<'JSON'\n{{\"fixture\":true}}\nJSON\n"
result = self.run_documented_request(Path(temporary), "X-API-Token: " + TEST_TOKEN,
port, request_helper() + "\n" + call)
self.assertEqual(result.returncode, 0, result.stderr.decode())
path, headers, sent_method, body = requests[-1]
self.assertEqual((sent_method, path), (method, "/api/admin/roles"))
if method in ("POST", "PUT"):
self.assertEqual(headers["Content-Type"], "application/json")
self.assertEqual(json.loads(body), {"fixture": True})
else:
self.assertEqual(body, b"")
self.assertNotIn("Content-Type", headers)
self.assertEqual(len(requests), 4)
def test_shared_helper_refuses_unsupported_methods_urls_and_missing_auth_before_transport(self):
with recording_server() as (port, requests), tempfile.TemporaryDirectory() as temporary:
env = dict(os.environ, HOME=temporary)
for call, expected_exit in (("pulse_api PATCH /api/admin/roles", 2),
("pulse_api GET https://example.invalid/api/admin/roles", 2),
("pulse_api DELETE", 2),
("pulse_api DELETE /api/admin/roles/unused", 1)):
with self.subTest(call=call):
command = (request_helper() + "\n" + call).replace("http://127.0.0.1:7655", f"http://127.0.0.1:{port}")
result = subprocess.run(["bash", "-eu", "-c", command], env=env,
capture_output=True, timeout=10)
self.assertEqual(result.returncode, expected_exit, result.stderr.decode())
self.assertEqual(requests, [])
self.assertFalse((Path(temporary) / ".config").exists())
def test_private_response_assertion_rejects_console_output_regression(self):
request = commands()[1]
self.assertEqual(request.count('--output "$result_file" '), 1)