Files
multica/apps/web/test/helpers.tsx
Bohan Jiang 762e64d469 fix(agent): restrict custom_env visibility to owner/admin (#1046)
* fix(agent): restrict custom_env visibility to agent owner and workspace admin

Agent environment variables (custom_env) were visible to all workspace
members, exposing sensitive tokens. Now only the agent owner and
workspace owner/admin can view them — regular members receive the field
omitted (null) from API responses, and the frontend hides the
Environment tab accordingly.

Closes #1018

* fix(agent): show masked env keys to non-authorized users instead of hiding tab

Instead of completely hiding the Environment tab for non-owner/non-admin
users, show the variable keys with masked values (****) in a read-only
view. This lets members see which variables are configured without
exposing the actual values.

- Backend: mask values with "****" instead of nullifying custom_env
- Added custom_env_redacted boolean to API response
- Frontend: EnvTab supports readOnly mode with lock icon and muted styling
2026-04-15 13:06:49 +08:00

106 lines
2.5 KiB
TypeScript

import React from "react";
import { vi } from "vitest";
import { render, type RenderOptions } from "@testing-library/react";
import type { User, Workspace, MemberWithUser, Agent } from "@multica/core/types";
// Mock user
export const mockUser: User = {
id: "user-1",
name: "Test User",
email: "test@multica.ai",
avatar_url: null,
created_at: "2026-01-01T00:00:00Z",
updated_at: "2026-01-01T00:00:00Z",
};
// Mock workspace
export const mockWorkspace: Workspace = {
id: "ws-1",
name: "Test Workspace",
slug: "test-ws",
description: "A test workspace",
context: null,
settings: {},
repos: [],
issue_prefix: "TES",
created_at: "2026-01-01T00:00:00Z",
updated_at: "2026-01-01T00:00:00Z",
};
// Mock members
export const mockMembers: MemberWithUser[] = [
{
id: "member-1",
workspace_id: "ws-1",
user_id: "user-1",
role: "owner",
created_at: "2026-01-01T00:00:00Z",
name: "Test User",
email: "test@multica.ai",
avatar_url: null,
},
];
// Mock agents
export const mockAgents: Agent[] = [
{
id: "agent-1",
workspace_id: "ws-1",
runtime_id: "runtime-1",
name: "Claude Agent",
description: "",
instructions: "",
avatar_url: null,
status: "idle",
runtime_mode: "cloud",
runtime_config: {},
custom_env: {},
custom_env_redacted: false,
visibility: "workspace",
max_concurrent_tasks: 3,
owner_id: null,
skills: [],
created_at: "2026-01-01T00:00:00Z",
updated_at: "2026-01-01T00:00:00Z",
archived_at: null,
archived_by: null,
},
];
// Mock auth context value
export const mockAuthValue: Record<string, any> = {
user: mockUser,
workspace: mockWorkspace,
members: mockMembers,
agents: mockAgents,
isLoading: false,
login: vi.fn(),
logout: vi.fn(),
switchWorkspace: vi.fn(),
updateWorkspace: vi.fn(),
updateCurrentUser: vi.fn(),
getMemberName: (userId: string) => {
const m = mockMembers.find((m) => m.user_id === userId);
return m?.name ?? "Unknown";
},
getAgentName: (agentId: string) => {
const a = mockAgents.find((a) => a.id === agentId);
return a?.name ?? "Unknown Agent";
},
getActorName: (type: string, id: string) => {
if (type === "member") {
const m = mockMembers.find((m) => m.user_id === id);
return m?.name ?? "Unknown";
}
if (type === "agent") {
const a = mockAgents.find((a) => a.id === id);
return a?.name ?? "Unknown Agent";
}
return "System";
},
getActorInitials: (type: string, id: string) => {
return "TU";
},
};