Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🥸 test: Cover Overlapping Web Search Secret Patches (#17390)

lia-by-librechat[bot]8d921e6f7e53
diff --git a/packages/api/src/admin/secrets.integration.spec.ts b/packages/api/src/admin/secrets.integration.spec.ts
index 38bab92e5e..d4b5ef0c83 100644
--- a/packages/api/src/admin/secrets.integration.spec.ts
+++ b/packages/api/src/admin/secrets.integration.spec.ts
@@ -803,7 +803,7 @@ describe('config secret registry — real handlers against a real Config collect
secretPath: 'webSearch.searxngApiKey',
};
- type Entry = { fieldPath: string; value: unknown };
+ type Entry = { value: unknown } & ({ fieldPath: string } | { segments: string[] });
async function patch(principalId: string, entries: Entry[]): Promise<MockRes> {
const res = mockRes();
@@ -870,6 +870,121 @@ describe('config secret registry — real handlers against a real Config collect
expect(await readRawConfig(principalId)).toEqual(before);
});
+ describe.each([
+ { name: 'dotted paths', segmentedKey: false, segmentedSection: false },
+ { name: 'segment paths', segmentedKey: true, segmentedSection: true },
+ { name: 'segmented key and dotted section', segmentedKey: true, segmentedSection: false },
+ { name: 'dotted key and segmented section', segmentedKey: false, segmentedSection: true },
+ ])('overlapping writes with $name', ({ segmentedKey, segmentedSection }) => {
+ const REENTERED_KEY = 'sx-reentered-0002';
+ const keyTarget = segmentedKey
+ ? { segments: ['webSearch', 'searxngApiKey'] }
+ : { fieldPath: 'webSearch.searxngApiKey' };
+ const sectionTarget = segmentedSection
+ ? { segments: ['webSearch'] }
+ : { fieldPath: 'webSearch' };
+ const replacement = (url: string): Entry => ({
+ ...sectionTarget,
+ value: {
+ searxngInstanceUrl: url,
+ searchProvider: 'searxng',
+ scraperProvider: 'keenable',
+ rerankerType: 'none',
+ },
+ });
+ const key: Entry = { ...keyTarget, value: REENTERED_KEY };
+
+ it('rejects a key entry overwritten by a section that restores the stored key', async () => {
+ const principalId = nextPrincipalId();
+ const before = await storeSearxng(principalId);
+
+ const res = await patch(principalId, [key, replacement(NEW_URL)]);
+
+ expect(response(res)).toEqual(reentryRequired([SEARXNG_REENTRY]));
+ expect(await readRawConfig(principalId)).toEqual(before);
+ });
+
+ it('accepts a key entered after the section and stores only that key', async () => {
+ const principalId = nextPrincipalId();
+ const before = await storeSearxng(principalId);
+
+ const res = await patch(principalId, [replacement(NEW_URL), key]);
+
+ expect(res.statusCode).toBe(200);
+ const after = await readRawOverrides(principalId);
+ const ciphertext = getAtPath(after, 'webSearch.searxngApiKey');
+ expect(getAtPath(after, 'webSearch.searxngInstanceUrl')).toBe(NEW_URL);
+ expect(ciphertext).not.toBe(getAtPath(before.overrides, 'webSearch.searxngApiKey'));
+ expect(decryptV3(ciphertext as string)).toBe(REENTERED_KEY);
+ expect(getAtPath(after, 'webSearch.searxngApiKeyPreview')).toBe(
+ getSecretPreview(REENTERED_KEY),
+ );
+ expect(JSON.stringify(res.body)).not.toContain(REENTERED_KEY);
+ });
+
+ it('preserves the stored ciphertext and preview when the destination stays', async () => {
+ const principalId = nextPrincipalId();
+ const before = await storeSearxng(principalId);
+
+ const res = await patch(principalId, [key, replacement(STORED_URL)]);
+
+ expect(res.statusCode).toBe(200);
+ const after = await readRawOverrides(principalId);
+ for (const field of ['searxngInstanceUrl', 'searxngApiKey', 'searxngApiKeyPreview']) {
+ expect(getAtPath(after, `webSearch.${field}`)).toBe(
+ getAtPath(before.overrides, `webSearch.${field}`),
+ );
+ }
+ });
+
+ it('rechecks a restored key after a revision conflict', async () => {
+ const principalId = nextPrincipalId();
+ const before = await storeSearxng(principalId);
+ const concurrentFields = encryptConfigSecretFields({
+ 'webSearch.searxngInstanceUrl': 'https://searx.example.com/concurrent',
+ 'webSearch.searxngApiKey': 'sx-concurrent-0003',
+ });
+ const write = jest.fn<
+ ReturnType<ConfigMethods['writeConfigDocument']>,
+ Parameters<ConfigMethods['writeConfigDocument']>
+ >(async (...args) => {
+ await patchConfigFields(
+ PrincipalType.ROLE,
+ principalId,
+ PrincipalModel.ROLE,
+ concurrentFields,
+ );
+ return configMethods.writeConfigDocument(...args);
+ });
+ const racing = createRealHandlers({ writeConfigDocument: write });
+ const res = mockRes();
+
+ await racing.patchConfigField(
+ mockReq({
+ params: { principalType: 'role', principalId },
+ body: { entries: [key, replacement(STORED_URL)] },
+ }),
+ res,
+ );
+
+ expect(write).toHaveBeenCalledTimes(1);
+ expect(response(res)).toEqual(reentryRequired([SEARXNG_REENTRY]));
+ const after = await readRawOverrides(principalId);
+ expect(getAtPath(after, 'webSearch.searxngInstanceUrl')).toBe(
+ concurrentFields['webSearch.searxngInstanceUrl'],
+ );
+ expect(getAtPath(after, 'webSearch.searxngApiKey')).toBe(
+ concurrentFields['webSearch.searxngApiKey'],
+ );
+ expect(decryptV3(getAtPath(after, 'webSearch.searxngApiKey') as string)).toBe(
+ 'sx-concurrent-0003',
+ );
+ expect(getAtPath(after, 'webSearch.searxngApiKey')).not.toBe(
+ getAtPath(before.overrides, 'webSearch.searxngApiKey'),
+ );
+ });
+ });
+
it('rejects a section patch that changes the URL and omits the key', async () => {
const principalId = nextPrincipalId();
const before = await storeSearxng(principalId);