fix(webui): allow switching Default permissions back to Full Access (#6175)
* fix(webui): allow authenticated access mode switching * refactor(webui): remove constant full access eligibility helpers * refactor(webui): remove obsolete full access policy parameter * docs(webui): remove redundant access switching paragraph * refactor(webui): remove obsolete full access capability
This commit is contained in:
1 parent
ae186cb18d
commit
73af08efab
14 files changed
+87
-204
No files matched your search
@@ -2117,7 +2117,7 @@ async def test_remote_webui_scope_allows_access_reduction(
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
|
||||
async def test_in_flight_message_without_scope_uses_latest_access_mode(
|
||||
bus: MagicMock,
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
@@ -2154,10 +2154,6 @@ async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
|
||||
"chat_id": chat_id,
|
||||
"content": "hello",
|
||||
"webui": True,
|
||||
"workspace_scope": {
|
||||
"project_path": str(default_workspace),
|
||||
"access_mode": "full",
|
||||
},
|
||||
},
|
||||
)
|
||||
)
|
||||
@@ -2178,18 +2174,16 @@ async def test_remote_access_reduction_rejects_stale_in_flight_message_scope(
|
||||
release_hydrate.set()
|
||||
await message_task
|
||||
|
||||
assert sessions.read_session_file(f"websocket:{chat_id}") is None
|
||||
saved = sessions.read_session_file(f"websocket:{chat_id}")
|
||||
assert saved["metadata"]["workspace_scope"]["access_mode"] == "restricted"
|
||||
assert channel.gateway.workspaces.scope_for_session_key(
|
||||
f"websocket:{chat_id}"
|
||||
).access_mode == "restricted"
|
||||
payload = json.loads(message_conn.send.await_args.args[0])
|
||||
assert payload["event"] == "error"
|
||||
assert payload["detail"] == "workspace_scope_rejected"
|
||||
bus.publish_inbound.assert_not_awaited()
|
||||
bus.publish_inbound.assert_awaited_once()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remote_webui_scope_rejects_full_access_for_custom_scope(
|
||||
async def test_remote_webui_scope_allows_full_access_for_custom_scope(
|
||||
bus: MagicMock,
|
||||
tmp_path,
|
||||
) -> None:
|
||||
@@ -2220,11 +2214,11 @@ async def test_remote_webui_scope_rejects_full_access_for_custom_scope(
|
||||
)
|
||||
|
||||
payload = json.loads(conn.send.await_args.args[0])
|
||||
assert payload["event"] == "error"
|
||||
assert payload["detail"] == "workspace_scope_rejected"
|
||||
assert payload["reason"] == "full workspace access is unavailable for this connection"
|
||||
assert payload["chat_id"] == "chat-remote"
|
||||
assert sessions.read_session_file("websocket:chat-remote") is None
|
||||
assert payload["event"] == "session_updated"
|
||||
assert payload["workspace_scope"]["access_mode"] == "full"
|
||||
assert channel.gateway.workspaces.scope_for_session_key(
|
||||
"websocket:chat-remote"
|
||||
).project_path == project.resolve()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -6621,15 +6615,12 @@ def test_handle_webui_thread_get_does_not_backfill_hidden_subagent_result(
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("headers,allowed", [
|
||||
(None, False),
|
||||
([], False),
|
||||
({}, False),
|
||||
({"Host": "localhost:8765"}, True),
|
||||
({"Host": "remote.example"}, False),
|
||||
({"Host": "localhost:8765", "X-Forwarded-For": "203.0.113.8"}, False),
|
||||
@pytest.mark.parametrize("headers", [
|
||||
{"Host": "localhost:8765"},
|
||||
{"Host": "remote.example"},
|
||||
{"Host": "localhost:8765", "X-Forwarded-For": "203.0.113.8"},
|
||||
])
|
||||
async def test_full_access_requires_local_handshake(bus, tmp_path, headers, allowed):
|
||||
async def test_webui_access_mode_can_toggle_back_to_full(bus, tmp_path, headers):
|
||||
sessions = SessionManager(tmp_path / "sessions")
|
||||
channel = WebSocketChannel(
|
||||
{"enabled": True, "allowFrom": ["*"], "host": "127.0.0.1"},
|
||||
@@ -6639,17 +6630,17 @@ async def test_full_access_requires_local_handshake(bus, tmp_path, headers, allo
|
||||
)
|
||||
conn = AsyncMock()
|
||||
conn.remote_address = ("127.0.0.1", 50123)
|
||||
conn.request = SimpleNamespace(headers=headers) if headers is not None else None
|
||||
await channel._dispatch_envelope(conn, "client", {
|
||||
"type": "set_workspace_scope",
|
||||
"chat_id": "handshake-scope",
|
||||
"workspace_scope": {"project_path": str(tmp_path), "access_mode": "full"},
|
||||
})
|
||||
result = json.loads(conn.send.await_args.args[0])
|
||||
if allowed:
|
||||
conn.request = SimpleNamespace(headers=headers)
|
||||
for mode in ("full", "restricted", "full"):
|
||||
conn.send.reset_mock()
|
||||
await channel._dispatch_envelope(conn, "client", {
|
||||
"type": "set_workspace_scope",
|
||||
"chat_id": "handshake-scope",
|
||||
"workspace_scope": {"project_path": str(tmp_path), "access_mode": mode},
|
||||
})
|
||||
result = json.loads(conn.send.await_args.args[0])
|
||||
assert result["event"] == "session_updated"
|
||||
assert result["workspace_scope"]["access_mode"] == "full"
|
||||
else:
|
||||
assert result["event"] == "error"
|
||||
assert result["reason"] == "full workspace access is unavailable for this connection"
|
||||
assert sessions.read_session_file("websocket:handshake-scope") is None
|
||||
assert result["workspace_scope"]["access_mode"] == mode
|
||||
assert channel.gateway.workspaces.scope_for_session_key(
|
||||
"websocket:handshake-scope"
|
||||
).access_mode == mode
|
||||
@@ -2531,7 +2531,7 @@ async def test_webui_automation_result_is_authenticated_and_returns_only_selecte
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remote_new_chat_accepts_server_project_path_but_rejects_remote_full_access(
|
||||
async def test_remote_new_chat_accepts_server_project_path_and_full_access(
|
||||
bus: MagicMock, tmp_path: Path
|
||||
) -> None:
|
||||
project = tmp_path / "remote-project"
|
||||
@@ -2585,18 +2585,15 @@ async def test_remote_new_chat_accepts_server_project_path_but_rejects_remote_fu
|
||||
},
|
||||
)
|
||||
|
||||
rejected = [
|
||||
json.loads(call.args[0])
|
||||
for call in connection.send.await_args_list
|
||||
if json.loads(call.args[0]).get("event") == "error"
|
||||
]
|
||||
assert rejected == [
|
||||
{
|
||||
"event": "error",
|
||||
"detail": "workspace_scope_rejected",
|
||||
"reason": "full workspace access is unavailable for this connection",
|
||||
}
|
||||
]
|
||||
attached = next(
|
||||
json.loads(call.args[0]) for call in connection.send.await_args_list
|
||||
if json.loads(call.args[0]).get("event") == "attached"
|
||||
)
|
||||
scope = channel.gateway.workspaces.scope_for_session_key(
|
||||
f"websocket:{attached['chat_id']}"
|
||||
)
|
||||
assert scope.project_path == other_project.resolve()
|
||||
assert scope.access_mode == "full"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -3656,18 +3653,17 @@ async def test_recovery_mutation_uses_authenticated_websocket_action(bus: MagicM
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("connection", "headers", "can_use_full_access"),
|
||||
("connection", "headers"),
|
||||
[
|
||||
(_REMOTE, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}, False),
|
||||
(_LOCAL, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}, False),
|
||||
(_LOCAL, {"Host": "127.0.0.1:8765"}, True),
|
||||
(_REMOTE, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}),
|
||||
(_LOCAL, {"Host": "nas.example", "X-Forwarded-For": "203.0.113.42"}),
|
||||
(_LOCAL, {"Host": "127.0.0.1:8765"}),
|
||||
],
|
||||
)
|
||||
def test_workspace_payload_separates_remote_project_selection_from_full_access(
|
||||
def test_workspace_payload_allows_access_selection_for_local_and_remote_clients(
|
||||
bus: MagicMock,
|
||||
connection: _FakeConn,
|
||||
headers: dict[str, str],
|
||||
can_use_full_access: bool,
|
||||
) -> None:
|
||||
channel = _ch(bus)
|
||||
token = channel.gateway.tokens.issue_api_token(300)
|
||||
@@ -3681,7 +3677,6 @@ def test_workspace_payload_separates_remote_project_selection_from_full_access(
|
||||
assert response.status_code == 200
|
||||
controls = json.loads(response.body.decode())["controls"]
|
||||
assert controls["can_change_project"] is True
|
||||
assert controls["can_use_full_access"] is can_use_full_access
|
||||
assert controls["can_browse_directories"] is True
|
||||
assert controls["can_resolve_project"] is True
|
||||
assert controls["can_manage_favorites"] is True
|
||||
@@ -4178,11 +4173,11 @@ async def test_project_selection_remembers_resolved_path_without_changing_access
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"name": "project", "path": str(project)}
|
||||
assert channel.gateway.workspaces.default_scope() == scope
|
||||
payload = channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)
|
||||
payload = channel.gateway.workspaces.payload(can_change_project=True)
|
||||
assert payload["recent_projects"] == [{"name": "project", "path": str(project)}]
|
||||
rejected = await _webui_mutate(channel, "workspace.resolve_project", {"path": str(tmp_path / "missing")}, connection=connection)
|
||||
assert rejected.status_code == 400
|
||||
assert channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)["recent_projects"] == payload["recent_projects"]
|
||||
assert channel.gateway.workspaces.payload(can_change_project=True)["recent_projects"] == payload["recent_projects"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -4196,7 +4191,7 @@ async def test_project_favorites_mutation_persists_without_selecting_project(
|
||||
response = await _webui_mutate(channel, "workspace.favorite", {"path": str(project), "pinned": True}, connection=connection)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"favorite_projects": [{"name": "pinned", "path": str(project)}]}
|
||||
payload = channel.gateway.workspaces.payload(can_change_project=True, can_use_full_access=False)
|
||||
payload = channel.gateway.workspaces.payload(can_change_project=True)
|
||||
assert payload["favorite_projects"] == response.json()["favorite_projects"]
|
||||
assert payload["recent_projects"] == []
|
||||
assert payload["default_scope"]["project_path"] == str(tmp_path)
|
||||
|
||||
Reference in new issue
Block a user