Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/src/components/MCP/CustomUserVarsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ function AuthField({ name, config, hasValue, control, errors, autoFocus }: AuthF
render={({ field }) => (
<Input
id={name}
type="text"
// Prevent autofill: browser DOM mutations bypass React's synthetic
// onChange, silently emptying react-hook-form state on submit.
type="new-password"
autoComplete="new-password"
data-lpignore="true"
data-1p-ignore="true"
/* autoFocus is generally disabled due to the fact that it can disorient users,
* but in this case, the required field would logically be immediately navigated to anyways, and the component's
* functionality emulates that of a new modal opening, where users would expect focus to be shifted to the new content */
Expand Down
34 changes: 34 additions & 0 deletions client/src/components/MCP/__tests__/CustomUserVarsSection.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import CustomUserVarsSection from '../CustomUserVarsSection';

jest.mock('~/data-provider/Tools/queries', () => ({
useMCPAuthValuesQuery: () => ({ data: { authValueFlags: {} } }),
}));

jest.mock('~/hooks', () => ({
useLocalize: () => (key: string) => key,
}));

describe('CustomUserVarsSection', () => {
const fields = {
api_key: { title: 'My API Key', description: 'Your API key' },
};

it('renders autofill-prevention attributes on credential inputs', () => {
render(
<CustomUserVarsSection
serverName="test-server"
fields={fields}
onSave={jest.fn()}
onRevoke={jest.fn()}
/>,
);

const input = screen.getByLabelText(/My API Key/);
expect(input).toHaveAttribute('autocomplete', 'new-password');
expect(input).toHaveAttribute('type', 'new-password');
expect(input).toHaveAttribute('data-lpignore', 'true');
expect(input).toHaveAttribute('data-1p-ignore', 'true');
});
});
Loading