mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(core): repeat a request ID a controller set in every request ID header (#6914)
* fix(core): repeat a request ID a controller set in every request ID header AwsRequestIdFilter filled the missing request ID headers with a new UUID, so a Lambda Invoke answered x-amz-request-id with the invocation's ID and x-amzn-RequestId, which the SDKs read first, with another one. The filter now reuses the ID already set. * test(lambda): check the Invoke request ID with the qualifier tests' function fixture
This commit is contained in:
1 parent
981b885348
commit
d2a5a82ca2
3 files changed
+48
-2
No files matched your search
@@ -21,7 +21,8 @@ import java.util.UUID;
|
||||
*
|
||||
* <p>This filter emits all three so that every AWS SDK variant can find the
|
||||
* header it expects. If a controller already set {@code x-amz-request-id}
|
||||
* (e.g. Lambda invoke), the existing value is preserved.
|
||||
* (e.g. Lambda invoke) or {@code x-amzn-RequestId}, that value is preserved and
|
||||
* repeated in the other headers, so every SDK reads the same ID.
|
||||
*/
|
||||
@Provider
|
||||
public class AwsRequestIdFilter implements ContainerResponseFilter {
|
||||
@@ -35,7 +36,7 @@ public class AwsRequestIdFilter implements ContainerResponseFilter {
|
||||
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
|
||||
|
||||
// Reuse the same ID across all header variants for this response
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
String requestId = existingRequestId(headers);
|
||||
|
||||
if (!headers.containsKey(AMZ_REQUEST_ID)) {
|
||||
headers.putSingle(AMZ_REQUEST_ID, requestId);
|
||||
@@ -47,4 +48,14 @@ public class AwsRequestIdFilter implements ContainerResponseFilter {
|
||||
headers.putSingle(AMZ_ID_2, requestId);
|
||||
}
|
||||
}
|
||||
|
||||
private static String existingRequestId(MultivaluedMap<String, Object> headers) {
|
||||
for (String name : new String[] {AMZ_REQUEST_ID, AMZN_REQUEST_ID}) {
|
||||
Object value = headers.getFirst(name);
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
+21
@@ -2,11 +2,13 @@ package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Verifies that {@link AwsRequestIdFilter} injects {@code x-amz-request-id} and
|
||||
@@ -132,6 +134,25 @@ class AwsRequestIdFilterIntegrationTest {
|
||||
.header("x-amzn-RequestId", notNullValue());
|
||||
}
|
||||
|
||||
// --- An ID the controller set ---
|
||||
|
||||
@Test
|
||||
void aRequestIdTheControllerSetIsRepeatedInTheOtherHeaders() {
|
||||
// Lake Formation sets only x-amzn-RequestId
|
||||
Response response = given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20201022/us-east-1/"
|
||||
+ "lakeformation/aws4_request, SignedHeaders=host;x-amz-date, Signature=dummy")
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/GetDataLakeSettings");
|
||||
|
||||
response.then().statusCode(200);
|
||||
String requestId = response.header("x-amzn-RequestId");
|
||||
assertEquals(requestId, response.header("x-amz-request-id"));
|
||||
assertEquals(requestId, response.header("x-amz-id-2"));
|
||||
}
|
||||
|
||||
// --- JSON 1.1 protocol (SSM) ---
|
||||
|
||||
@Test
|
||||
|
||||
+14
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.lambda;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -13,6 +14,7 @@ import java.util.zip.ZipOutputStream;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Invoke ignored the {@code Qualifier} query parameter, so {@code ?Qualifier=} ran {@code $LATEST}
|
||||
@@ -191,4 +193,16 @@ class LambdaInvokeQualifierIntegrationTest {
|
||||
.when().post("/2015-03-31/functions/" + fn + "/invocations")
|
||||
.then().statusCode(400).body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInvokeAnswersWithTheInvocationRequestIdInEveryHeader() throws Exception {
|
||||
// Invoke sets X-Amz-Request-Id; the SDKs read x-amzn-RequestId first
|
||||
String fn = createFunction("v1");
|
||||
|
||||
Response response = given().header("X-Amz-Invocation-Type", "DryRun").body("{}")
|
||||
.when().post("/2015-03-31/functions/" + fn + "/invocations");
|
||||
|
||||
response.then().statusCode(204);
|
||||
assertEquals(response.header("x-amz-request-id"), response.header("x-amzn-RequestId"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user