mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): format unexpected query errors as XML error envelope (#3121)
* fix(rds): format unexpected query errors as XML error envelope Unhandled runtime exceptions in RdsQueryHandler and NeptuneQueryHandler previously returned plain text Response.serverError entities, causing AWS CLI and SDK XML parsers to fail with syntax errors. Wrap unexpected exceptions in AwsQueryResponse.error with InternalFailure and ensure 5xx status codes render with <Type>Receiver</Type> in accordance with AWS Query protocol specifications. Also add unit tests covering default platform image cache eviction and unexpected RDS handler errors. Closes #3110 * test(neptune): add unit tests for query handler error responses Verify NeptuneQueryHandler unexpected exceptions return an XML InternalFailure error response with HTTP 500 status and Receiver error type.
This commit is contained in:
1 parent
c0b5461f10
commit
daeea78ee6
6 files changed
+167
-3
No files matched your search
+31
@@ -206,6 +206,37 @@ class ImageCacheServiceTest {
|
||||
verify(pullImage).exec(any(PullImageResultCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void repullsDefaultImageWhenCachedImageWasRemoved() throws Exception {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
InspectImageCmd inspectImage = mock(InspectImageCmd.class);
|
||||
InspectImageCmd inspectCachedImage = mock(InspectImageCmd.class);
|
||||
PullImageCmd pullImage = mock(PullImageCmd.class);
|
||||
PullImageResultCallback callback = mock(PullImageResultCallback.class);
|
||||
when(dockerClient.inspectImageCmd(IMAGE)).thenReturn(inspectImage);
|
||||
when(dockerClient.inspectImageCmd("sha256:default-old")).thenReturn(inspectCachedImage);
|
||||
when(inspectImage.exec())
|
||||
.thenReturn(new InspectImageResponse()
|
||||
.withId("sha256:default-old")
|
||||
.withOs("linux")
|
||||
.withArch("amd64"))
|
||||
.thenThrow(new NotFoundException("image not found locally"))
|
||||
.thenReturn(new InspectImageResponse()
|
||||
.withId("sha256:default-new")
|
||||
.withOs("linux")
|
||||
.withArch("amd64"));
|
||||
when(inspectCachedImage.exec()).thenThrow(new NotFoundException("image was removed"));
|
||||
when(dockerClient.pullImageCmd(IMAGE)).thenReturn(pullImage);
|
||||
when(pullImage.withAuthConfig(any())).thenReturn(pullImage);
|
||||
when(pullImage.exec(any(PullImageResultCallback.class))).thenReturn(callback);
|
||||
|
||||
ImageCacheService service = newService(dockerClient);
|
||||
assertEquals("sha256:default-old", service.ensureImageExists(IMAGE));
|
||||
|
||||
assertEquals("sha256:default-new", service.ensureImageExists(IMAGE));
|
||||
verify(pullImage).exec(any(PullImageResultCallback.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void succeedsOnFirstAttempt() throws Exception {
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package io.github.hectorvent.floci.services.neptune;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class NeptuneQueryHandlerTest {
|
||||
|
||||
private NeptuneService service;
|
||||
private NeptuneQueryHandler handler;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = mock(NeptuneService.class);
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.defaultAvailabilityZone()).thenReturn("us-east-1a");
|
||||
handler = new NeptuneQueryHandler(service, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unhandledExceptionRendersXmlInternalFailure() {
|
||||
when(service.createDbCluster(any(), any(), anyBoolean(), any(), any()))
|
||||
.thenThrow(new RuntimeException("Docker daemon connection failed"));
|
||||
|
||||
MultivaluedMap<String, String> p = new MultivaluedHashMap<>();
|
||||
p.add("DBClusterIdentifier", "mycluster");
|
||||
|
||||
Response response = handler.handle("CreateDBCluster", p);
|
||||
assertEquals(500, response.getStatus());
|
||||
assertEquals("application/xml", response.getMediaType().toString());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<ErrorResponse xmlns=\"http://rds.amazonaws.com/doc/2014-10-31/\">"), body);
|
||||
assertTrue(body.contains("<Type>Receiver</Type>"), body);
|
||||
assertTrue(body.contains("<Code>InternalFailure</Code>"), body);
|
||||
assertTrue(body.contains("<Message>Unexpected error: Docker daemon connection failed</Message>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unhandledExceptionInCreateDbInstanceRendersXmlInternalFailure() {
|
||||
when(service.createDbInstance(any(), any(), any(), any(), anyBoolean(), any(), any()))
|
||||
.thenThrow(new RuntimeException("Container startup timed out"));
|
||||
|
||||
MultivaluedMap<String, String> p = new MultivaluedHashMap<>();
|
||||
p.add("DBInstanceIdentifier", "myinstance");
|
||||
p.add("DBClusterIdentifier", "mycluster");
|
||||
|
||||
Response response = handler.handle("CreateDBInstance", p);
|
||||
assertEquals(500, response.getStatus());
|
||||
assertEquals("application/xml", response.getMediaType().toString());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<ErrorResponse xmlns=\"http://rds.amazonaws.com/doc/2014-10-31/\">"), body);
|
||||
assertTrue(body.contains("<Type>Receiver</Type>"), body);
|
||||
assertTrue(body.contains("<Code>InternalFailure</Code>"), body);
|
||||
assertTrue(body.contains("<Message>Unexpected error: Container startup timed out</Message>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsExceptionRendersXmlError() {
|
||||
when(service.getDbCluster("missing"))
|
||||
.thenThrow(new AwsException("DBClusterNotFoundFault", "DBCluster missing not found.", 404));
|
||||
|
||||
MultivaluedMap<String, String> p = new MultivaluedHashMap<>();
|
||||
p.add("DBClusterIdentifier", "missing");
|
||||
|
||||
Response response = handler.handle("DescribeDBClusters", p);
|
||||
assertEquals(404, response.getStatus());
|
||||
assertEquals("application/xml", response.getMediaType().toString());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<Code>DBClusterNotFoundFault</Code>"), body);
|
||||
assertTrue(body.contains("<Type>Sender</Type>"), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedOperationReturnsQueryError() {
|
||||
Response response = handler.handle("NoSuchAction", new MultivaluedHashMap<>());
|
||||
assertEquals(400, response.getStatus());
|
||||
assertEquals("application/xml", response.getMediaType().toString());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<Code>UnsupportedOperation</Code>"), body);
|
||||
assertTrue(body.contains("<Type>Sender</Type>"), body);
|
||||
}
|
||||
}
|
||||
@@ -2385,4 +2385,27 @@ class RdsQueryHandlerTest {
|
||||
isNull(), isNull(), captor.capture());
|
||||
assertEquals(new DbInstanceSettings(null, null, 3, "01:00-01:30", null, true), captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unhandledExceptionRendersXmlInternalFailure() {
|
||||
when(service.createDbInstance(any(), any(), any(), any(), any(), any(),
|
||||
any(), anyInt(), anyBoolean(), any(), any(), any(), any(), anyBoolean(),
|
||||
anyBoolean(), any(), any(), any(), any(), any(), anyBoolean(), any()))
|
||||
.thenThrow(new RuntimeException("Docker daemon connection failed"));
|
||||
|
||||
MultivaluedMap<String, String> p = params();
|
||||
p.add("DBInstanceIdentifier", "mydb");
|
||||
p.add("Engine", "postgres");
|
||||
p.add("DBInstanceClass", "db.t3.micro");
|
||||
|
||||
Response response = handler.handle("CreateDBInstance", p);
|
||||
assertEquals(500, response.getStatus());
|
||||
assertEquals("application/xml", response.getMediaType().toString());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<ErrorResponse xmlns=\"http://rds.amazonaws.com/doc/2014-10-31/\">"), body);
|
||||
assertTrue(body.contains("<Type>Receiver</Type>"), body);
|
||||
assertTrue(body.contains("<Code>InternalFailure</Code>"), body);
|
||||
assertTrue(body.contains("<Message>Unexpected error: Docker daemon connection failed</Message>"), body);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user