mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
* chore(release): bump version to v3.8.5 * fix(docker): rebuild better-sqlite3 after hardened install (#2772) Integrated into release/v3.8.5 * ci: build Docker platforms on native runners (#2774) Integrated into release/v3.8.5 * docs(release): sync v3.8.5 documentation and metadata Update changelog entries, API reference version, package metadata, and localized LLM documentation for the 3.8.5 release. Refresh generated docs source mappings and architecture counts for current executors and OAuth providers. * chore(release): bump to v3.8.5 — changelog, docs, version sync * chore(release): translate Hall of Contributors to English in workflows and changelog * fix(combos): make target timeout configurable (#2775) Merge PR #2775 — fix(combos): make target timeout configurable * feat: fix so restart of server restarts batch jobs instead of failing them (#2755) Merge PR #2755 — feat: fix so restart of server restarts batch jobs instead of failing them * chore(release): update changelog with merged PRs notes and credits * feat(api): add endpoint restrictions for client API keys (#2777) Merge PR #2777 — feat(api): add endpoint restrictions for client API keys * chore(release): update changelog with PR #2777 entry and contributor credit --------- Co-authored-by: Thanet S. <cho.112543@gmail.com> Co-authored-by: Randi <55005611+rdself@users.noreply.github.com> Co-authored-by: Markus Hartung <mail@hartmark.se> Co-authored-by: Jack <5443152+hijak@users.noreply.github.com>
116 lines
4.2 KiB
TypeScript
116 lines
4.2 KiB
TypeScript
/**
|
|
* Unit tests for endpoint category resolution and API key endpoint restrictions.
|
|
*
|
|
* Tests:
|
|
* 1. resolveEndpointCategory — path → category mapping
|
|
* 2. enforceApiKeyPolicy — endpoint restriction enforcement
|
|
*/
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
// ─── resolveEndpointCategory: pure function tests ─────────────────────────
|
|
// Import the pure resolver without DB dependencies
|
|
|
|
const { resolveEndpointCategory } = await import(
|
|
"../../src/shared/constants/endpointCategories.ts"
|
|
);
|
|
|
|
test("resolveEndpointCategory: maps /v1/chat/completions to 'chat'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/chat/completions"), "chat");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/completions to 'chat'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/completions"), "chat");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/messages to 'chat'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/messages"), "chat");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/responses to 'chat'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/responses"), "chat");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/search to 'search'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/search"), "search");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/search/analytics to 'search'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/search/analytics"), "search");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/embeddings to 'embeddings'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/embeddings"), "embeddings");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/images/generations to 'images'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/images/generations"), "images");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/images/edits to 'images'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/images/edits"), "images");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/audio/speech to 'audio'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/audio/speech"), "audio");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/audio/transcriptions to 'audio'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/audio/transcriptions"), "audio");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/videos/generations to 'video'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/videos/generations"), "video");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/music/generations to 'music'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/music/generations"), "music");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/rerank to 'rerank'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/rerank"), "rerank");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/models to 'models'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/models"), "models");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/moderations to 'moderations'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/moderations"), "moderations");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/batches to 'batches'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/batches"), "batches");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/files to 'files'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/files"), "files");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/web/fetch to 'web-fetch'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/web/fetch"), "web-fetch");
|
|
});
|
|
|
|
test("resolveEndpointCategory: maps /v1/agents/tasks to 'agents'", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/agents/tasks"), "agents");
|
|
});
|
|
|
|
test("resolveEndpointCategory: returns null for unknown path", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/unknown"), null);
|
|
});
|
|
|
|
test("resolveEndpointCategory: returns null for management /api/keys", () => {
|
|
assert.equal(resolveEndpointCategory("/api/keys"), null);
|
|
});
|
|
|
|
test("resolveEndpointCategory: returns null for root path", () => {
|
|
assert.equal(resolveEndpointCategory("/"), null);
|
|
});
|
|
|
|
test("resolveEndpointCategory: handles sub-paths under category", () => {
|
|
assert.equal(resolveEndpointCategory("/v1/files/some-file-id"), "files");
|
|
assert.equal(resolveEndpointCategory("/v1/batches/batch-123"), "batches");
|
|
assert.equal(resolveEndpointCategory("/v1/responses/some/path"), "chat");
|
|
});
|