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 <oyi77@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
This commit is contained in:
Paijo
2026-07-12 20:27:42 +07:00
committed by GitHub
parent 2a5f9a5ed7
commit 19d1a5d391
2 changed files with 32 additions and 0 deletions

View File

@@ -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 ");

View File

@@ -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",