Prevent trailing slash in sso proxy base url input (#16244)

This commit is contained in:
yuneng-jiang
2025-11-04 14:22:50 -08:00
committed by GitHub
parent 615f76de88
commit 4d756a62d9
2 changed files with 40 additions and 2 deletions
@@ -95,4 +95,38 @@ describe("SSOModals", () => {
expect(getByText("URL must start with http:// or https://")).toBeInTheDocument();
});
});
it("should automatically remove trailing slash from the proxy base 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, container } = render(<TestWrapper />);
// Fill in the proxy base url with a trailing slash
const urlInput = getByLabelText("PROXY BASE URL") as HTMLInputElement;
fireEvent.change(urlInput, { target: { value: "https://example.com/" } });
// Trigger blur to ensure normalization is applied
fireEvent.blur(urlInput);
// Check that the trailing slash was removed by the normalize function
await waitFor(() => {
expect(urlInput.value).toBe("https://example.com");
});
});
});
@@ -309,16 +309,20 @@ const SSOModals: React.FC<SSOModalsProps> = ({
<Form.Item
label="PROXY BASE URL"
name="proxy_base_url"
normalize={(value) => value?.trim()}
normalize={(value) => value?.trim().replace(/\/+$/, "")}
rules={[
{ required: true, message: "Please enter the proxy base url" },
{
pattern: /^https?:\/\/.+/,
message: "URL must start with http:// or https://",
},
{
pattern: /^https?:\/\/[^\s]+[^\/]$/,
message: "URL must not end with a trailing slash",
},
]}
>
<TextInput />
<TextInput placeholder="https://example.com" />
</Form.Item>
</>
<div