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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Validation for Proxy Base URL in SSO Settings (#16082)
yuneng-jiang5c71455d22b6
diff --git a/ui/litellm-dashboard/src/components/SSOModals.test.tsx b/ui/litellm-dashboard/src/components/SSOModals.test.tsxnew file mode 100644index 00000000000..7d4b0254e0a--- /dev/null+++ b/ui/litellm-dashboard/src/components/SSOModals.test.tsx@@ -0,0 +1,98 @@+import { render, fireEvent, waitFor } from "@testing-library/react";+import { describe, expect, it, beforeAll } from "vitest";+import { Form } from "antd";+import SSOModals from "./SSOModals";+import React from "react";++// Mock window.matchMedia for Ant Design components+beforeAll(() => {+ Object.defineProperty(window, "matchMedia", {+ writable: true,+ value: (query: string) => ({+ matches: false,+ media: query,+ onchange: null,+ addListener: () => {}, // deprecated+ removeListener: () => {}, // deprecated+ addEventListener: () => {},+ removeEventListener: () => {},+ dispatchEvent: () => true,+ }),+ });+});++describe("SSOModals", () => {+ it("should render the SSOModals component", () => {+ const TestWrapper = () => {+ const [form] = Form.useForm();++ return (+ <SSOModals+ isAddSSOModalVisible={true}+ isInstructionsModalVisible={false}+ handleAddSSOOk={() => {}}+ handleAddSSOCancel={() => {}}+ handleShowInstructions={() => {}}+ handleInstructionsOk={() => {}}+ handleInstructionsCancel={() => {}}+ form={form}+ accessToken={null}+ ssoConfigured={false}+ />+ );+ };++ const { getByText } = render(<TestWrapper />);+ expect(getByText("Add SSO")).toBeInTheDocument();+ });++ it("should have a validation error if the proxy base url is not a valid URL", async () => {+ const TestWrapper = () => {+ const [form] = Form.useForm();+ return (+ <SSOModals+ isAddSSOModalVisible={true}+ isInstructionsModalVisible={false}+ handleAddSSOOk={() => {}}+ handleAddSSOCancel={() => {}}+ handleShowInstructions={() => {}}+ handleInstructionsOk={() => {}}+ handleInstructionsCancel={() => {}}+ form={form}+ accessToken={null}+ ssoConfigured={false}+ />+ );+ };++ const { getByLabelText, getByText, container } = render(<TestWrapper />);++ // Find and interact with the SSO provider select+ const ssoProviderSelect = container.querySelector("#sso_provider");+ if (ssoProviderSelect) {+ fireEvent.mouseDown(ssoProviderSelect);+ // Wait for dropdown and select Google+ await waitFor(() => {+ const googleOption = getByText("Google SSO");+ fireEvent.click(googleOption);+ });+ }++ // Fill in the email field+ const emailInput = getByLabelText("Proxy Admin Email");+ fireEvent.change(emailInput, { target: { value: "[email protected]" } });++ // Fill in an invalid URL+ const urlInput = getByLabelText("PROXY BASE URL");+ fireEvent.change(urlInput, { target: { value: "invalid-url" } });++ // Submit the form+ const saveButton = getByText("Save");+ fireEvent.click(saveButton);++ // Check for validation error+ await waitFor(() => {+ expect(getByText("URL must start with http:// or https://")).toBeInTheDocument();+ });+ });+});diff --git a/ui/litellm-dashboard/src/components/SSOModals.tsx b/ui/litellm-dashboard/src/components/SSOModals.tsxindex 3c484214980..6c5904a8ffa 100644--- a/ui/litellm-dashboard/src/components/SSOModals.tsx+++ b/ui/litellm-dashboard/src/components/SSOModals.tsx@@ -309,7 +309,14 @@ const SSOModals: React.FC<SSOModalsProps> = ({<Form.Itemlabel="PROXY BASE URL"name="proxy_base_url"- rules={[{ required: true, message: "Please enter the proxy base url" }]}+ normalize={(value) => value?.trim()}+ rules={[+ { required: true, message: "Please enter the proxy base url" },+ {+ pattern: /^https?:\/\/.+/,+ message: "URL must start with http:// or https://",+ },+ ]}><TextInput /></Form.Item>