mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(core): return UnknownOperationException when X-Amz-Target is missing (#3925)
This commit is contained in:
1 parent
68425d942a
commit
ca98384b4a
5 files changed
+169
-8
No files matched your search
@@ -266,7 +266,7 @@ public class AwsJson11Controller {
|
||||
String body) {
|
||||
|
||||
if (target == null) {
|
||||
return null;
|
||||
return JsonErrorResponseUtils.createMissingTargetErrorResponse();
|
||||
}
|
||||
|
||||
ServiceCatalog.TargetMatch targetMatch = catalog.matchTarget(target).orElse(null);
|
||||
|
||||
@@ -385,16 +385,15 @@ public class AwsJsonCborController {
|
||||
byte[] body) {
|
||||
|
||||
if (target == null) {
|
||||
return null;
|
||||
return cborUnknownOperationError("Missing X-Amz-Target header.", httpHeaders);
|
||||
}
|
||||
|
||||
// Upstream CBOR behavior is to return null for targets this controller
|
||||
// does not dispatch (JAX-RS then serves 204). The JSON 1.0/1.1
|
||||
// controllers return UnknownOperationException instead; CBOR stays on
|
||||
// null here to preserve pre-refactor semantics.
|
||||
// Symmetric with the JSON 1.0/1.1 controllers: a target this controller cannot
|
||||
// resolve is an unknown operation, not an empty 204. The 204 fallback now applies
|
||||
// only to a resolved service whose action this handler does not dispatch.
|
||||
ServiceCatalog.TargetMatch targetMatch = catalog.matchTarget(target).orElse(null);
|
||||
if (targetMatch == null) {
|
||||
return null;
|
||||
return cborUnknownOperationError("Unknown operation: " + target, httpHeaders);
|
||||
}
|
||||
|
||||
String serviceKey = targetMatch.descriptor().externalKey();
|
||||
@@ -491,6 +490,12 @@ public class AwsJsonCborController {
|
||||
};
|
||||
}
|
||||
|
||||
private Response cborUnknownOperationError(String message, HttpHeaders httpHeaders) {
|
||||
return cborErrorResponse(
|
||||
new AwsException("UnknownOperationException", message, 404),
|
||||
"smithy-protocol", responseContentType(httpHeaders));
|
||||
}
|
||||
|
||||
private Response cborErrorResponse(AwsException e, String protocolHeader, String mediaType) {
|
||||
try {
|
||||
byte[] errBytes = CBOR_MAPPER.writeValueAsBytes(
|
||||
|
||||
@@ -101,7 +101,7 @@ public class AwsJsonController {
|
||||
String body) {
|
||||
|
||||
if (target == null) {
|
||||
return null;
|
||||
return JsonErrorResponseUtils.createMissingTargetErrorResponse();
|
||||
}
|
||||
|
||||
ServiceCatalog.TargetMatch targetMatch = catalog.matchTarget(target).orElse(null);
|
||||
|
||||
@@ -57,6 +57,18 @@ public class JsonErrorResponseUtils {
|
||||
"Unknown operation: " + target, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A JSON request with no X-Amz-Target names no operation, so there is nothing to route on.
|
||||
* It fails as an unknown operation but with a message about the missing header rather than
|
||||
* concatenating a literal {@code null} into {@link #createUnknownOperationErrorResponse}.
|
||||
*/
|
||||
public static Response createMissingTargetErrorResponse() {
|
||||
return createErrorResponse(404,
|
||||
"UnknownOperationException",
|
||||
"UnknownOperationException",
|
||||
"Missing X-Amz-Target header.", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A request body that is not valid JSON is a client (deserialization) error, not a server
|
||||
* fault. AWS's JSON protocols reject it with 400 SerializationException; without this the
|
||||
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* A JSON POST without an X-Amz-Target header must fail with
|
||||
* UnknownOperationException (404) rather than be served as an empty success.
|
||||
* The status and error name follow the AWS Common Errors entry for an
|
||||
* unrecognized operation; Smithy requires the header but does not specify a
|
||||
* server response when it is absent, so this pins Floci's chosen behavior.
|
||||
* Both the JSON 1.0 and JSON 1.1 controllers share the null-target branch.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class UnknownOperationMissingTargetIntegrationTest {
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void json10RequestWithoutTargetReturnsUnknownOperation() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.0")
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.header("x-amzn-query-error", equalTo("UnknownOperationException;Sender"))
|
||||
.body("__type", equalTo("UnknownOperationException"))
|
||||
.body("message", equalTo("Missing X-Amz-Target header."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void json10RequestWithEmptyBodyAndNoTargetReturnsUnknownOperation() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.0")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("UnknownOperationException"))
|
||||
.body("message", equalTo("Missing X-Amz-Target header."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void json11RequestWithoutTargetReturnsUnknownOperation() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.header("x-amzn-query-error", equalTo("UnknownOperationException;Sender"))
|
||||
.body("__type", equalTo("UnknownOperationException"))
|
||||
.body("message", equalTo("Missing X-Amz-Target header."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void json11RequestWithEmptyBodyAndNoTargetReturnsUnknownOperation() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("UnknownOperationException"))
|
||||
.body("message", equalTo("Missing X-Amz-Target header."));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownTargetReturnsUnknownOperation() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.0")
|
||||
.header("X-Amz-Target", "Nope.Nope")
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("UnknownOperationException"))
|
||||
.body("message", equalTo("Unknown operation: Nope.Nope"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void json10ValidTargetStillReachesTheHandler() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.0")
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.ListTables")
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("__type", not(equalTo("UnknownOperationException")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void json11ValidTargetStillReachesTheHandler() {
|
||||
given()
|
||||
.contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "AmazonSSM.DescribeParameters")
|
||||
.body("{}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("__type", not(equalTo("UnknownOperationException")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cborRequestWithoutTargetReturnsUnknownOperation() {
|
||||
given()
|
||||
.contentType("application/x-amz-cbor-1.1")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.header("x-amzn-query-error", equalTo("UnknownOperationException;Sender"))
|
||||
.header("smithy-protocol", equalTo("rpc-v2-cbor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cborRequestWithUnknownTargetReturnsUnknownOperation() {
|
||||
given()
|
||||
.contentType("application/x-amz-cbor-1.1")
|
||||
.header("X-Amz-Target", "Nope.Nope")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.header("x-amzn-query-error", equalTo("UnknownOperationException;Sender"))
|
||||
.header("smithy-protocol", equalTo("rpc-v2-cbor"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user