mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-18 20:18:38 +00:00
key info page internal viewer fix
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { render, waitFor, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import useTeams from "@/app/(dashboard)/hooks/useTeams";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { KeyResponse, Team } from "../key_team_helpers/key_list";
|
||||
import KeyInfoView from "./key_info_view";
|
||||
import useTeams from "@/app/(dashboard)/hooks/useTeams";
|
||||
|
||||
vi.mock("@/app/(dashboard)/hooks/useTeams", () => ({
|
||||
default: vi.fn(),
|
||||
@@ -255,4 +255,32 @@ describe("KeyInfoView", () => {
|
||||
expect(screen.queryByText("Delete Key")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("should not allow Internal Viewer to modify key even if they own it", async () => {
|
||||
vi.mocked(useTeams).mockReturnValue({
|
||||
teams: [],
|
||||
setTeams: vi.fn(),
|
||||
});
|
||||
|
||||
const ownerUserId = "internal-viewer-user-id";
|
||||
const keyData = { ...MOCK_KEY_DATA, user_id: ownerUserId };
|
||||
render(
|
||||
<KeyInfoView
|
||||
keyData={keyData}
|
||||
onClose={() => {}}
|
||||
keyId={"test-key-id"}
|
||||
onKeyDataUpdate={() => {}}
|
||||
accessToken={"test-token"}
|
||||
userID={ownerUserId}
|
||||
userRole={"Internal Viewer"}
|
||||
premiumUser={true}
|
||||
teams={[]}
|
||||
/>,
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText("Regenerate Key")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Delete Key")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -302,6 +302,7 @@ export default function KeyInfoView({
|
||||
});
|
||||
return `${dateStr} at ${timeStr}`;
|
||||
};
|
||||
console.log("userRole", userRole);
|
||||
|
||||
const canModifyKey =
|
||||
isProxyAdminRole(userRole || "") ||
|
||||
@@ -310,7 +311,7 @@ export default function KeyInfoView({
|
||||
teamsData?.filter((team) => team.team_id === currentKeyData.team_id)[0],
|
||||
userID || "",
|
||||
)) ||
|
||||
userID === currentKeyData.user_id;
|
||||
(userID === currentKeyData.user_id && userRole !== "Internal Viewer");
|
||||
|
||||
return (
|
||||
<div className="w-full h-screen p-4">
|
||||
|
||||
Reference in New Issue
Block a user