mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigatewayv2): map $request.path to the request path without the stage (#8993)
AWS documents $request.path and ${request.path} as an HTTP API mapping
source that yields the request path without the stage name. The AWS
service integration validator accepted only $request.path.<name>, so
CreateIntegration rejected it, and ContextValueResolver had no case for
it, so it resolved to nothing. The resolver now returns
RequestContext.path(), which already excludes the stage, and the
validator accepts the bare source.
Closes #8991
This commit is contained in:
1 parent
ade40d7940
commit
82ac1eabaa
4 files changed
+27
-2
No files matched your search
+3
-2
@@ -29,10 +29,11 @@ public class AwsServiceIntegrationMapper {
|
||||
|
||||
private static final Pattern EMBEDDED_EXPRESSION = Pattern.compile("\\$\\{([^}]+)}");
|
||||
private static final String BODY = "$request.body";
|
||||
private static final String REQUEST_PATH = "$request.path";
|
||||
private static final String STAGE_VARIABLES = "$stageVariables.";
|
||||
private static final String CONTEXT = "$context.";
|
||||
private static final List<String> SOURCE_PREFIXES = List.of("$request.header.", "$request.querystring.",
|
||||
"$request.path.", BODY + ".", CONTEXT, STAGE_VARIABLES);
|
||||
REQUEST_PATH + ".", BODY + ".", CONTEXT, STAGE_VARIABLES);
|
||||
private static final ObjectMapper TEMPLATE_READER = new ObjectMapper()
|
||||
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
|
||||
|
||||
@@ -121,7 +122,7 @@ public class AwsServiceIntegrationMapper {
|
||||
}
|
||||
|
||||
private static boolean isSupportedSource(String expression) {
|
||||
if (expression.equals(BODY)) {
|
||||
if (expression.equals(BODY) || expression.equals(REQUEST_PATH)) {
|
||||
return true;
|
||||
}
|
||||
for (String prefix : SOURCE_PREFIXES) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
* <li>{@code $context.<name>}: any other context variable the request carries</li>
|
||||
* <li>{@code $request.header.<name>}: case-insensitive header lookup</li>
|
||||
* <li>{@code $request.querystring.<name>}: query parameter</li>
|
||||
* <li>{@code $request.path}: the request path without the stage name</li>
|
||||
* <li>{@code $request.path.<name>}: captured path parameter</li>
|
||||
* <li>{@code $request.body}: the request body as text, null when it is empty</li>
|
||||
* <li>{@code $request.body.<JSONPath>}: a value selected from a JSON request body</li>
|
||||
@@ -92,6 +93,9 @@ public class ContextValueResolver {
|
||||
String name = expression.substring("$request.querystring.".length());
|
||||
return ctx.queryParams() == null ? null : ctx.queryParams().get(name);
|
||||
}
|
||||
if (expression.equals("$request.path")) {
|
||||
return ctx.path();
|
||||
}
|
||||
if (expression.startsWith("$request.path.")) {
|
||||
String name = expression.substring("$request.path.".length());
|
||||
return ctx.pathParams() == null ? null : ctx.pathParams().get(name);
|
||||
|
||||
+14
@@ -474,6 +474,20 @@ class ApiGatewayV2SqsSendMessageIntegrationTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeResolvesRequestPathWithoutTheStage() {
|
||||
String attributes = "{\"Path\":{\"DataType\":\"String\",\"StringValue\":\"${request.path}\"}}";
|
||||
withSendMessageRoute("sqs-invoke-request-path",
|
||||
queueUrl -> Map.of("QueueUrl", queueUrl, "MessageBody", "$request.path",
|
||||
"MessageAttributes", attributes),
|
||||
(sqs, queueUrl, api) -> {
|
||||
given().post("/execute-api/" + api + "/test/send").then().statusCode(200);
|
||||
Message message = onlyMessage(sqs, queueUrl);
|
||||
assertThat(message.body(), equalTo("/send"));
|
||||
assertThat(message.messageAttributes().get("Path").stringValue(), equalTo("/send"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeResolvesAccountDomainRequestIdAndRequestTimeContextVariables() {
|
||||
String attributes = "{\"Account\":{\"DataType\":\"String\",\"StringValue\":\"${context.accountId}\"},"
|
||||
|
||||
@@ -99,6 +99,12 @@ class ContextValueResolverTest {
|
||||
assertEquals("42", r.resolve("$request.path.id", c));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestPathWithoutNameResolvesToTheRequestPath() {
|
||||
ContextValueResolver r = new ContextValueResolver();
|
||||
assertEquals("/foo", r.resolve("$request.path", ctx(Map.of(), Map.of(), Map.of(), Map.of(), Map.of())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownExpressionReturnsNull() {
|
||||
ContextValueResolver r = new ContextValueResolver();
|
||||
|
||||
Reference in new issue
Block a user