fix(core): answer a disabled service's CBOR error in the request's media type (#9662)

A CBOR request to a disabled service got its ServiceNotAvailableException
as application/cbor, even when it was sent as
application/x-amz-cbor-1.1. The error now goes through
ProtocolErrorResponses.cbor and the shared CBOR writer, so it answers in
the media type the request sent, as Floci's other CBOR errors do. Its
body and headers are unchanged.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-28 14:47:13 -04:00
1 parent 82d5c18018
commit d44f29cc15
2 files changed
+24 -18

No files matched your search

@@ -1,7 +1,5 @@
package io.floci.aws.core.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import jakarta.inject.Inject;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
@@ -16,8 +14,6 @@ import java.util.Optional;
@Provider
public class ServiceEnabledFilter implements ContainerRequestFilter {
private static final ObjectMapper CBOR_MAPPER = new ObjectMapper(new CBORFactory());
@Context
ResourceInfo resourceInfo;
@@ -37,7 +33,7 @@ public class ServiceEnabledFilter implements ContainerRequestFilter {
return;
}
if (!serviceConfigAccess.isEnabled(request.serviceKey())) {
ctx.abortWith(disabledResponse(request));
ctx.abortWith(disabledResponse(ctx, request));
}
}
@@ -78,22 +74,11 @@ public class ServiceEnabledFilter implements ContainerRequestFilter {
return resourceInfo != null ? resourceInfo.getResourceClass() : null;
}
private Response disabledResponse(ResolvedRequest request) {
private Response disabledResponse(ContainerRequestContext ctx, ResolvedRequest request) {
String message = "Service " + request.serviceKey() + " is not enabled.";
if (request.protocol() == ServiceProtocol.CBOR) {
try {
byte[] errBytes = CBOR_MAPPER.writeValueAsBytes(
new AwsErrorResponse("ServiceNotAvailableException", message));
return Response.status(400)
.header("smithy-protocol", "rpc-v2-cbor")
.header("x-amzn-query-error", "ServiceNotAvailableException;Sender")
.type("application/cbor")
.entity(errBytes)
.build();
} catch (Exception ignored) {
return Response.status(400).build();
}
return ProtocolErrorResponses.cbor(ctx, "ServiceNotAvailableException", message, 400);
}
if (request.protocol() == ServiceProtocol.JSON || request.protocol() == ServiceProtocol.REST_JSON) {
@@ -151,6 +151,27 @@ class ServiceEnablementIntegrationTest {
assertEquals("Service dynamodb is not enabled.", body.get("message").asText());
}
@Test
void anAmzCborRequestGetsItsErrorInTheMediaTypeItSent() throws Exception {
JsonNode body = cborBody(
given()
.contentType("application/x-amz-cbor-1.1")
.accept("application/x-amz-cbor-1.1")
.header("X-Amz-Target", "DynamoDB_20120810.ListTables")
.body(CBOR_MAPPER.writeValueAsBytes(Map.of()))
.when()
.post("/")
.then()
.statusCode(400)
.contentType("application/x-amz-cbor-1.1")
.header("x-amzn-query-error", "ServiceNotAvailableException;Sender")
.extract().asByteArray()
);
assertEquals("ServiceNotAvailableException", body.get("__type").asText());
assertEquals("Service dynamodb is not enabled.", body.get("message").asText());
}
@Test
void dynamodbSmithyCborRequestsReturnCborErrors() throws Exception {
JsonNode body = cborBody(