mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 06:42:12 +03:00
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:
@@ -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 ");
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user