Skip to content

Commit

Permalink
fix(frontend): Prevent from send a SET API key (All-Hands-AI#6235)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanape authored and AlexCuadron committed Jan 13, 2025
1 parent 2fc5a9c commit 80dfa1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frontend/__tests__/components/features/sidebar/sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,30 @@ describe("Sidebar", () => {
llm_api_key: undefined, // null or undefined
});
});

it("should not send the api key if its SET", async () => {
const user = userEvent.setup();
renderSidebar();

const settingsButton = screen.getByTestId("settings-button");
await user.click(settingsButton);

const settingsModal = screen.getByTestId("ai-config-modal");

const apiKeyInput = within(settingsModal).getByLabelText(/api key/i);
await user.type(apiKeyInput, "SET");

const saveButton = within(settingsModal).getByTestId(
"save-settings-button",
);
await user.click(saveButton);

expect(saveSettingsSpy).toHaveBeenCalledWith({
...MOCK_USER_PREFERENCES.settings,
llm_api_key: undefined,
llm_base_url: undefined,
security_analyzer: undefined,
});
});
});
});
5 changes: 5 additions & 0 deletions frontend/src/context/settings-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export function SettingsProvider({ children }: SettingsProviderProps) {
...userSettings,
...newSettings,
};

if (updatedSettings.LLM_API_KEY === "SET") {
delete updatedSettings.LLM_API_KEY;
}

await saveSettings(updatedSettings, {
onSuccess: () => {
if (!isUpToDate) {
Expand Down

0 comments on commit 80dfa1f

Please sign in to comment.