Split handleRequest into pipeline + internal route table; auth/OAuth2 endpoints become named handlers in src/auth/routes.ts

This commit is contained in:
2026-07-02 13:05:54 +02:00
parent 8621cf24b6
commit 535902e69b
7 changed files with 434 additions and 264 deletions
+29
View File
@@ -0,0 +1,29 @@
// Internal route-table matching: exact path, a GET route also answering HEAD (like the plugin
// router), method-distinct entries on the same path.
import { test } from "node:test";
import assert from "node:assert/strict";
import { type BuiltinRoute, matchBuiltinRoute } from "./builtin-routes.ts";
const entry = (method: "GET" | "POST", path: string): BuiltinRoute => ({ handler: () => null, method, path });
test("matches exact path + method; GET also answers HEAD", () => {
const get = entry("GET", "/error");
const post = entry("POST", "/logout");
const routes = [get, post];
assert.equal(matchBuiltinRoute(routes, "GET", "/error"), get);
assert.equal(matchBuiltinRoute(routes, "HEAD", "/error"), get);
assert.equal(matchBuiltinRoute(routes, "POST", "/logout"), post);
assert.equal(matchBuiltinRoute(routes, "GET", "/logout"), undefined, "a POST route does not answer GET");
assert.equal(matchBuiltinRoute(routes, "HEAD", "/logout"), undefined, "a POST route does not answer HEAD");
assert.equal(matchBuiltinRoute(routes, "POST", "/error"), undefined, "a GET route does not answer POST");
assert.equal(matchBuiltinRoute(routes, "GET", "/nope"), undefined);
assert.equal(matchBuiltinRoute(routes, "GET", "/error/sub"), undefined, "exact path, no prefix matching");
});
test("the same path may carry method-distinct entries (consent screen GET + decision POST)", () => {
const screen = entry("GET", "/oauth2/consent");
const decision = entry("POST", "/oauth2/consent");
const routes = [screen, decision];
assert.equal(matchBuiltinRoute(routes, "GET", "/oauth2/consent"), screen);
assert.equal(matchBuiltinRoute(routes, "POST", "/oauth2/consent"), decision);
});