Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(e2e): self-seed the ui suite's password-login users in global setup

Yuneng Jiangfb353423d85a
diff --git a/tests/e2e/ui/fixtures/users.ts b/tests/e2e/ui/fixtures/users.ts
index 731234b5ea9..79ee237f334 100644
--- a/tests/e2e/ui/fixtures/users.ts
+++ b/tests/e2e/ui/fixtures/users.ts
@@ -14,7 +14,9 @@ export enum Role {
TeamAdmin = "team_admin",
}
-export const users: Record<Role, { email: string; password: string }> = {
+export type SeedApiRole = "proxy_admin_viewer" | "internal_user" | "internal_user_viewer";
+
+export const users: Record<Role, { email: string; password: string; seedApiRole?: SeedApiRole }> = {
[Role.ProxyAdmin]: {
email: "admin",
password: process.env.LITELLM_MASTER_KEY || "sk-1234",
@@ -22,18 +24,22 @@ export const users: Record<Role, { email: string; password: string }> = {
[Role.ProxyAdminViewer]: {
password: "test",
+ seedApiRole: "proxy_admin_viewer",
},
[Role.InternalUser]: {
password: "test",
+ seedApiRole: "internal_user",
},
[Role.InternalUserViewer]: {
password: "test",
+ seedApiRole: "internal_user_viewer",
},
[Role.TeamAdmin]: {
password: "test",
+ seedApiRole: "internal_user",
},
};
diff --git a/tests/e2e/ui/globalSetup.ts b/tests/e2e/ui/globalSetup.ts
index 6068a51c88e..e7d1655380d 100644
--- a/tests/e2e/ui/globalSetup.ts
+++ b/tests/e2e/ui/globalSetup.ts
@@ -29,6 +29,26 @@ async function globalSetup() {
if (!settingsRes.ok()) {
throw new Error(`Enabling enable_projects_ui failed (${settingsRes.status()}): ${await settingsRes.text()}`);
}
+
+ for (const { email, password, seedApiRole } of Object.values(users)) {
+ if (!seedApiRole) {
+ continue;
+ }
+ const createRes = await api.post(`${UI_BASE_URL}${rootPath}/user/new`, {
+ headers: { Authorization: `Bearer ${masterKey}` },
+ data: { user_email: email, user_role: seedApiRole, auto_create_key: false },
+ });
+ if (!createRes.ok() && createRes.status() !== 409) {
+ throw new Error(`Seeding user ${email} failed (${createRes.status()}): ${await createRes.text()}`);
+ }
+ const passwordRes = await api.post(`${UI_BASE_URL}${rootPath}/user/update`, {
+ headers: { Authorization: `Bearer ${masterKey}` },
+ data: { user_email: email, password },
+ });
+ if (!passwordRes.ok()) {
+ throw new Error(`Setting password for ${email} failed (${passwordRes.status()}): ${await passwordRes.text()}`);
+ }
+ }
await api.dispose();
for (const role of Object.values(Role)) {