mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
* fix(apigateway): fall back to a parameterised sibling on method mismatch
A literal resource that declares some methods but not the requested one
returned 405 even when a parameterised sibling could serve it. Resource
candidates are ordered exact, then parameterised, then greedy, and the
selection loop stopped at the first candidate with any methods configured.
For /users/me declaring only PATCH, GET /users/me therefore returned 405
instead of resolving against /users/{userId}, where "me" is an ordinary
parameter value. Adding a literal child for one method silently removes
every other method a parameterised sibling already served, so this surfaces
as a regression in an application that was working.
The stop was there for a narrower reason, which the existing tests pin: a
method mismatch on a concrete resource must not be absorbed by a greedy
/{proxy+} catch-all. That rule is kept. Only the concrete-to-concrete case
changes, so a literal now yields to a parameterised sibling that can serve
the method, while /devices declaring POST still returns 405 for GET rather
than falling through to /{proxy+}.
Extends ApiGatewayRoutingFallthroughIntegrationTest, which already covers
the greedy cases, with /users/{userId} GET alongside a literal /users/me
PATCH: GET /users/me resolves to the parameterised resource, PATCH still
prefers the literal, and an ordinary id is unaffected.
* fix(apigateway): resolve the method against every matching resource
The selection loop stopped considering less specific siblings once a
resource declaring methods had been passed, so a method mismatch on a
concrete resource was terminal for the greedy half of the rule.
Captured against a real REST API in us-west-2: AWS picks the most
specific resource that can serve the requested method, searching
literal, then path parameter, then greedy {proxy+}, and refuses the
request only when no candidate declares it.
Drop concreteWithMethodsSeen and the greedy break so both fallbacks
follow that single rule. /users/me declaring only PATCH no longer hides
GET /users/{userId}, and /devices declaring only POST now falls through
to GET /{proxy+}.
getDevicesReturns405 pinned the greedy half of the old behaviour and is
updated to assert the fallthrough. Adds compatibility coverage for the
sibling and greedy fallbacks from the same AWS repro.
The no-match response is unchanged: AWS returns 403 Missing
Authentication Token where floci returns 405, tracked separately.
* fix(apigateway): answer an unmatched REST request with 403, not 404/405
A REST request that reached no method returned 404 "Not Found" when the
path matched nothing and 405 "Method Not Allowed" when it matched
resources declaring no usable method. AWS returns neither.
Captured against a real REST API in us-west-2 with /users/{userId} GET
and a literal /users/me PATCH deployed. POST /users/me, DELETE
/users/abc123, GET /zzz, GET /users/a/b/c and GET / all answered:
403 {"message":"Missing Authentication Token"}
x-amzn-ErrorType: MissingAuthenticationTokenException
AWS resolves the path and the method as one step, so an unknown path and
a known path carrying no usable method are the same failure and share one
response. This is the well-known "Missing Authentication Token" result of
calling a REST API with the wrong verb, which callers match on.
Route both branches through restNoMatch(), rendering the status, body and
error-type header AWS pairs with this failure, alongside the existing
AWS_IAM MISSING rejection that already returns that shape.
HTTP APIs are untouched: they answer an unmatched route with 404
{"message":"Not Found"}, which the v2 dispatch path continues to do.
* test(apigateway): expect 403 for a path that reaches no resource
ApiGatewayGreedyPathParameterIntegrationTest arrived on main after this
branch was cut, and pinned the old 404 for a REST path matching no
resource. This branch changes that contract to 403 "Missing Authentication
Token", so the assertion was stale rather than a real regression.
The test's intent is unchanged: /other/img/logo.png must not be swallowed
by the greedy resource. Only the no-match response it asserts moves.
HTTP API v2 is untouched and still answers an unmatched route with 404
"Not Found".