feat(settings): check sandbox launchers and configure protected paths
This commit is contained in:
1 parent
f158779c60
commit
5b84b78cac
33 files changed
+1179
-20
No files matched your search
@@ -17,6 +17,7 @@
|
||||
"tools.exec.path_prepend",
|
||||
"tools.exec.path_append",
|
||||
"tools.exec.sandbox",
|
||||
"tools.exec.sandbox_launcher",
|
||||
"tools.exec.sandbox_ro_binds",
|
||||
"tools.exec.sandbox_rw_binds",
|
||||
"tools.exec.allowed_env_keys",
|
||||
|
||||
@@ -65,6 +65,31 @@ def _mutation_request(path: str, payload: dict[str, object]) -> SimpleNamespace:
|
||||
return request
|
||||
|
||||
|
||||
async def test_sandbox_check_is_authenticated_explicit_and_serialized(tmp_path, monkeypatch):
|
||||
path = "/api/settings/sandbox/check"
|
||||
router = _router(config_path=tmp_path / "config.json")
|
||||
response = await router.dispatch(None, SimpleNamespace(path=path, headers=Headers()), path)
|
||||
assert response.status_code == 405
|
||||
unauthorized = _router(authorized=False, config_path=tmp_path / "config.json")
|
||||
assert (await unauthorized.dispatch(None, _mutation_request(path, {}), path)).status_code == 401
|
||||
started, release = asyncio.Event(), asyncio.Event()
|
||||
|
||||
async def probe(config, workspace):
|
||||
started.set()
|
||||
await release.wait()
|
||||
return {"state": "passed", "reason": "", "launcher": "/usr/bin/bwrap", "revision": "test", "supported_backend": "bwrap"}
|
||||
|
||||
monkeypatch.setattr("nanobot.webui.settings_system.check_sandbox", probe)
|
||||
first = asyncio.create_task(router.dispatch(None, _mutation_request(path, {}), path))
|
||||
await asyncio.wait_for(started.wait(), 2)
|
||||
try:
|
||||
assert (await router.dispatch(None, _mutation_request(path, {}), path)).status_code == 409
|
||||
finally:
|
||||
release.set()
|
||||
assert (await first).status_code == 200
|
||||
assert (await router.dispatch(None, _mutation_request(path, {}), path)).status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nanobot_update_requires_auth_local_permission_and_websocket(tmp_path, monkeypatch):
|
||||
router = _router(config_path=tmp_path / "config.json")
|
||||
|
||||
@@ -35,6 +35,22 @@ def test_shared_proxy_roundtrip_preserves_independent_feature_switches(tmp_path)
|
||||
assert load_config(path).tools.web.use_proxy is True
|
||||
|
||||
|
||||
def test_legacy_sandbox_config_roundtrip_and_rejected_override_are_atomic(tmp_path):
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text(json.dumps({"tools": {"exec": {"sandbox": "bwrap", "sandboxRoBinds": ["/opt/tools"]}}}))
|
||||
config = load_config(path)
|
||||
assert config.tools.exec.sandbox_launcher == ""
|
||||
payload = update_runtime_config_settings({"tools.exec.timeout": 75}, config_path=path)
|
||||
assert payload["runtime_config"]["tools.exec.sandbox_launcher"] == ""
|
||||
assert load_config(path).tools.exec.sandbox_ro_binds == ["/opt/tools"]
|
||||
before = path.read_bytes()
|
||||
with pytest.raises(WebUISettingsError, match="sandbox_launcher_path_not_absolute"):
|
||||
update_runtime_config_settings({"tools.exec.sandbox_launcher": "bin/bwrap", "tools.exec.timeout": 99}, config_path=path)
|
||||
assert path.read_bytes() == before
|
||||
update_runtime_config_settings({"tools.exec.sandbox_launcher": ""}, config_path=path)
|
||||
assert load_config(path).tools.exec.sandbox == "bwrap"
|
||||
|
||||
|
||||
def test_enabling_web_proxy_without_an_address_preserves_config(tmp_path):
|
||||
path = tmp_path / "config.json"
|
||||
save_config(Config(), path)
|
||||
|
||||
Reference in new issue
Block a user