mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
fix(api): declare the auth gate's 403 on every operation behind it
requireAuth answers 403 auth.scope.insufficient to a narrow Bearer token on a route that names no scope it holds, and requireAdmin answers 403 auth.admin.required to a session that is not an administrator's. Both run before any route body, and the contract only said so in the prose of the shared 401, so a client generated from it had no typed branch for either. The route kit accepted the scope refusal on any operation that declared a 401 for the same reason. The 403 is added to the assembled path table rather than to stdResponses. That set is spread into most operations, about three hundred of them carry a 403 of their own, and most spread the set after it, so a shared 403 there would have overwritten every module-off and sharing refusal in the document. withScopeRefusal adds the shared response where an operation has none and prefixes an operation's own 403 with the gate's code, keeping the sharing sentence last. Operations that take no credential, and the three surfaces that authenticate by a credential of their own, are left as they were. The kit no longer tolerates the refusal on an operation's behalf, and a guard holds every operation behind the gate to declaring it.
This commit is contained in:
1 parent
4f2af7c544
commit
c272324c1e
7 files changed
+1371
-689
No files matched your search
+1094
-657
File diff suppressed because it is too large.
Load diff
@@ -89,10 +89,12 @@ Every call is also a contract check. The status must be one the registry
|
||||
(`src/lib/openapi/routes/`) declares for that path and method, a JSON body
|
||||
must parse with the registered schema, and a key the schema does not declare
|
||||
fails the call: a client generated from the contract cannot see that field, so
|
||||
nobody promised to keep it. The one generic answer accepted without its own
|
||||
entry is the scope gate's 403 `auth.scope.insufficient`, which the shared 401
|
||||
documents for every authenticated operation. A test that calls an unregistered
|
||||
route on purpose passes `contract: { skip: "<reason>" }`.
|
||||
nobody promised to keep it. There is no generic answer the kit accepts on an
|
||||
operation's behalf: the scope gate's 403 `auth.scope.insufficient` is declared
|
||||
on every operation that passes the gate (`withScopeRefusal` in
|
||||
`src/lib/openapi/routes/shared.ts`), so it is checked like any other status. A
|
||||
test that calls an unregistered route on purpose passes
|
||||
`contract: { skip: "<reason>" }`.
|
||||
`tests/integration/routes/kit-contract.test.ts` proves the check can fail.
|
||||
|
||||
Assert what a person or a client would notice: the stored row, the response,
|
||||
|
||||
Reference in new issue
Block a user