Files
OmniRoute/tests/unit/api/services/cliproxy-accounts.test.ts
Ravi Tharuma c3cd1f94c0 feat(services): expose sanitized CLIProxyAPI account health (#11314)
Validated on a 17-PR combined board: cliproxy-accounts + cliproxy-tab + cliproxy-account-health + cliproxy-resolve-spawn-args-6877 (16/16) within the board's 287/287, typecheck:core clean, env-doc-sync clean. Exposes a sanitized read-only CLIProxyAPI account health view (5s-bounded client, explicit allowlist excluding names/paths/emails/tokens/status messages) through a management-authenticated API + dashboard card. Closes #6342. Thank you @RaviTharuma!
2026-08-24 01:55:31 -03:00

48 lines
1.7 KiB
TypeScript

import { before, after, it } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-cliproxy-accounts-api-"));
process.env.DATA_DIR = TEST_DATA_DIR;
process.env.API_KEY_SECRET = "cliproxy-accounts-api-test-secret";
process.env.DISABLE_SQLITE_AUTO_BACKUP = "true";
const core = await import("../../../../src/lib/db/core.ts");
const settingsDb = await import("../../../../src/lib/db/settings.ts");
const apiKeysDb = await import("../../../../src/lib/db/apiKeys.ts");
const { GET } = await import("../../../../src/app/api/services/cliproxy/accounts/route.ts");
before(async () => {
await settingsDb.updateSettings({ requireLogin: true });
process.env.INITIAL_PASSWORD = "cliproxy-accounts-test-password";
});
after(() => {
delete process.env.INITIAL_PASSWORD;
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
it("requires OmniRoute management authentication", async () => {
const response = await GET(
new Request("http://localhost/api/services/cliproxy/accounts")
);
assert.equal(response.status, 401);
});
it("accepts a scoped OmniRoute management API key", async () => {
const { key } = await apiKeysDb.createApiKey("cliproxy-accounts", "test", ["manage"]);
const response = await GET(
new Request("http://localhost/api/services/cliproxy/accounts", {
headers: { Authorization: `Bearer ${key}` },
})
);
assert.equal(response.status, 200);
assert.equal(response.headers.get("cache-control"), "no-store");
const body = await response.json();
assert.equal(body.state, "disabled");
assert.deepEqual(body.accounts, []);
});