From 19d1a5d3911757a0ebff58602aed0059bed88909 Mon Sep 17 00:00:00 2001 From: Paijo <14921983+oyi77@users.noreply.github.com> Date: Sun, 12 Jul 2026 20:27:42 +0700 Subject: [PATCH] fix(db): add authType filter support to getProviderConnections (#6946) getProviderConnections ignored the authType query param, causing callers like tokenHealthCheck.ts and /api/token-health to fetch and decrypt every connection instead of only the OAuth ones they asked for. Add the missing auth_type WHERE clause and a regression test. Rebased to drop the unrelated 46-icon commit (duplicate of #6926) and the accidentally-committed tests/unit/authz/__stub_apiKeys.mjs runtime artifact; replaced with a real unit test asserting the authType filter excludes non-matching connections. Co-authored-by: oyi77 Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --- src/lib/db/providers.ts | 4 ++++ tests/unit/db-providers-crud.test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/lib/db/providers.ts b/src/lib/db/providers.ts index d22842b2ed..47a18fee9f 100644 --- a/src/lib/db/providers.ts +++ b/src/lib/db/providers.ts @@ -55,6 +55,10 @@ export async function getProviderConnections(filter: JsonRecord = {}) { conditions.push("is_active = @isActive"); params.isActive = filter.isActive ? 1 : 0; } + if (filter.authType) { + conditions.push("auth_type = @authType"); + params.authType = filter.authType; + } if (conditions.length > 0) { sql += " WHERE " + conditions.join(" AND "); diff --git a/tests/unit/db-providers-crud.test.ts b/tests/unit/db-providers-crud.test.ts index 38babb66b1..9c005fc179 100644 --- a/tests/unit/db-providers-crud.test.ts +++ b/tests/unit/db-providers-crud.test.ts @@ -81,6 +81,34 @@ test("createProviderConnection assigns provider-scoped priorities and supports f assert.equal(second.isActive, false); }); +test("getProviderConnections filters by authType", async () => { + const apiKeyConnection = await providersDb.createProviderConnection({ + provider: "openai", + authType: "apikey", + name: "API Key Connection", + apiKey: "sk-apikey", + }); + const oauthConnection = await providersDb.createProviderConnection({ + provider: "claude", + authType: "oauth", + email: "oauth@example.com", + accessToken: "token-a", + refreshToken: "refresh-a", + }); + + const oauthOnly = await providersDb.getProviderConnections({ authType: "oauth" }); + const apiKeyOnly = await providersDb.getProviderConnections({ authType: "apikey" }); + + assert.deepEqual( + oauthOnly.map((connection) => connection.id), + [oauthConnection.id] + ); + assert.deepEqual( + apiKeyOnly.map((connection) => connection.id), + [apiKeyConnection.id] + ); +}); + test("oauth connections upsert by provider and email instead of duplicating rows", async () => { const original = await providersDb.createProviderConnection({ provider: "claude",