mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 15:21:05 -05:00
fix(apigateway): fall back to a parameterised sibling on method mismatch (#3399)
* 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.
This commit is contained in:
1 parent
28105c08ec
commit
f03a716e90
3 files changed
+211
-16
No files matched your search
+17
-11
@@ -338,18 +338,24 @@ public class ApiGatewayExecuteController {
|
||||
|
||||
ApiGatewayResource matched = null;
|
||||
MethodConfig method = null;
|
||||
// Candidates are ordered exact, then parameterised, then greedy. AWS picks the most
|
||||
// specific resource that can serve the method, so one declaring methods but not this
|
||||
// one yields to a less specific sibling that declares it: /users/me carrying only PATCH
|
||||
// does not hide GET /users/{userId}, and /devices carrying only POST falls through to
|
||||
// GET /{proxy+}. The request is refused only when no candidate declares the method.
|
||||
for (ApiGatewayResource r : matchedResources) {
|
||||
if (r.getResourceMethods() != null && !r.getResourceMethods().isEmpty()) {
|
||||
MethodConfig m = r.getResourceMethods().get(httpMethod.toUpperCase());
|
||||
if (m == null) {
|
||||
m = r.getResourceMethods().get("ANY");
|
||||
}
|
||||
if (m != null) {
|
||||
matched = r;
|
||||
method = m;
|
||||
}
|
||||
// Once we match a path that has methods configured, we must not fall back
|
||||
// to less specific sibling resources (e.g. /{proxy+}), even on method mismatch.
|
||||
Map<String, MethodConfig> resourceMethods = r.getResourceMethods();
|
||||
if (resourceMethods == null || resourceMethods.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MethodConfig m = resourceMethods.get(httpMethod.toUpperCase());
|
||||
if (m == null) {
|
||||
m = resourceMethods.get("ANY");
|
||||
}
|
||||
if (m != null) {
|
||||
matched = r;
|
||||
method = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user