Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix: resolve compatibility test failures across multiple services (#109)

Kurt McAlpine137786809438
diff --git a/.github/workflows/compatibility.yml b/.github/workflows/compatibility.yml
index 97842d0431..690465a02c 100644
--- a/.github/workflows/compatibility.yml
+++ b/.github/workflows/compatibility.yml
@@ -91,10 +91,13 @@ jobs:
- name: Start floci
run: |
+ DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
docker run -d --name floci --network compat-net \
-p 4566:4566 \
-v /var/run/docker.sock:/var/run/docker.sock \
+ --group-add "$DOCKER_GID" \
-e FLOCI_SERVICES_DOCKER_NETWORK=compat-net \
+ -e FLOCI_HOSTNAME=floci \
floci:test
- name: Wait for floci to be ready
@@ -119,8 +122,10 @@ jobs:
- name: Run tests
run: |
+ FLOCI_IP=$(docker inspect -f '{{(index .NetworkSettings.Networks "compat-net").IPAddress}}' floci)
docker run --rm --network compat-net \
-e FLOCI_ENDPOINT=http://floci:4566 \
+ --add-host "sdk-vhost-bucket.floci:${FLOCI_IP}" \
compat-${{ matrix.test }}
- name: Dump floci logs
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsExceptionMapper.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsExceptionMapper.java
index ae73ec8831..161a65aada 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsExceptionMapper.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsExceptionMapper.java
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.core.common;
+import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
@@ -18,6 +19,7 @@ public class AwsExceptionMapper implements ExceptionMapper<AwsException> {
LOG.debugv("Mapping exception: {0} - {1}", exception.getErrorCode(), exception.getMessage());
return Response.status(exception.getHttpStatus())
.entity(new AwsErrorResponse(exception.getErrorCode(), exception.getMessage()))
+ .type(MediaType.APPLICATION_JSON)
.build();
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/port/PortAllocator.java b/src/main/java/io/github/hectorvent/floci/core/common/port/PortAllocator.java
index 0808a96d21..ec31cfd999 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/port/PortAllocator.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/port/PortAllocator.java
@@ -13,25 +13,25 @@ import java.util.concurrent.atomic.AtomicInteger;
public class PortAllocator {
private final AtomicInteger counter;
- private final int maxPort;
+ private final int basePort;
+ private final int range;
@Inject
public PortAllocator(EmulatorConfig config) {
- this.counter = new AtomicInteger(config.services().lambda().runtimeApiBasePort());
- this.maxPort = config.services().lambda().runtimeApiMaxPort();
+ this.basePort = config.services().lambda().runtimeApiBasePort();
+ int maxPort = config.services().lambda().runtimeApiMaxPort();
+ this.range = maxPort - basePort + 1;
+ this.counter = new AtomicInteger(0);
}
PortAllocator(int basePort, int maxPort) {
- this.counter = new AtomicInteger(basePort);
- this.maxPort = maxPort;
+ this.basePort = basePort;
+ this.range = maxPort - basePort + 1;
+ this.counter = new AtomicInteger(0);
}
public int allocate() {
- int port = counter.getAndIncrement();
- if (port > maxPort) {
- counter.set(counter.get() - (maxPort - counter.get() + 1));
- port = counter.getAndIncrement();
- }
- return port;
+ int offset = counter.getAndIncrement();
+ return basePort + (Math.abs(offset) % range);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java b/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java
index f6742696a0..a9157e1d00 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java
@@ -111,7 +111,7 @@ public class RuntimeApiServer {
});
httpServer = vertx.createHttpServer();
- httpServer.requestHandler(router).listen(port, result -> {
+ httpServer.requestHandler(router).listen(port, "0.0.0.0", result -> {
if (result.succeeded()) {
LOG.debugv("RuntimeApiServer started on port {0}", port);
started.complete(null);
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
index 25cb3ec6c0..1267e71561 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3Controller.java
@@ -368,7 +368,8 @@ public class S3Controller {
@HeaderParam("If-None-Match") String ifNoneMatch,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@HeaderParam("If-Unmodified-Since") String ifUnmodifiedSince,
- @Context UriInfo uriInfo) {
+ @Context UriInfo uriInfo,
+ @Context HttpHeaders httpHeaders) {
try {
if (hasQueryParam(uriInfo, "tagging")) {
return handleGetObjectTagging(bucket, key);
@@ -383,8 +384,11 @@ public class S3Controller {
return Response.ok(s3Service.getObjectAcl(bucket, key, versionId)).build();
}
if (hasQueryParam(uriInfo, "attributes")) {
+ // Merge all x-amz-object-attributes header values (SDK may send multiple lines)
+ List<String> attrHeaders = httpHeaders.getRequestHeader("x-amz-object-attributes");
+ String mergedAttributes = attrHeaders != null ? String.join(",", attrHeaders) : objectAttributesHeader;
return handleGetObjectAttributes(bucket, key, versionId,
- objectAttributesHeader, maxParts, partNumberMarker);
+ mergedAttributes, maxParts, partNumberMarker);
}
if (hasPreconditions(ifMatch, ifNoneMatch, ifModifiedSince, ifUnmodifiedSince)) {
// Fetch metadata only to evaluate preconditions, avoiding loading the full object unnecessarily.
diff --git a/src/main/java/io/github/hectorvent/floci/services/sns/SnsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/sns/SnsQueryHandler.java
index e6f256f0d2..086b63708e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/sns/SnsQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/sns/SnsQueryHandler.java
@@ -68,8 +68,12 @@ public class SnsQueryHandler {
private Response handleDeleteTopic(MultivaluedMap<String, String> params, String region) {
String topicArn = getParam(params, "TopicArn");
- snsService.deleteTopic(topicArn, region);
- return Response.ok(AwsQueryResponse.envelopeNoResult("DeleteTopic", AwsNamespaces.SNS)).build();
+ try {
+ snsService.deleteTopic(topicArn, region);
+ return Response.ok(AwsQueryResponse.envelopeNoResult("DeleteTopic", AwsNamespaces.SNS)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response handleListTopics(MultivaluedMap<String, String> params, String region) {
@@ -85,41 +89,57 @@ public class SnsQueryHandler {
private Response handleGetTopicAttributes(MultivaluedMap<String, String> params, String region) {
String topicArn = getParam(params, "TopicArn");
- Map<String, String> attrs = snsService.getTopicAttributes(topicArn, region);
-
- var xml = new XmlBuilder().start("Attributes");
- for (var entry : attrs.entrySet()) {
- xml.start("entry")
- .elem("key", entry.getKey())
- .elem("value", entry.getValue())
- .end("entry");
+ try {
+ Map<String, String> attrs = snsService.getTopicAttributes(topicArn, region);
+
+ var xml = new XmlBuilder().start("Attributes");
+ for (var entry : attrs.entrySet()) {
+ xml.start("entry")
+ .elem("key", entry.getKey())
+ .elem("value", entry.getValue())
+ .end("entry");
+ }
+ xml.end("Attributes");
+ return Response.ok(AwsQueryResponse.envelope("GetTopicAttributes", AwsNamespaces.SNS, xml.build())).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
}
- xml.end("Attributes");
- return Response.ok(AwsQueryResponse.envelope("GetTopicAttributes", AwsNamespaces.SNS, xml.build())).build();
}
private Response handleSetTopicAttributes(MultivaluedMap<String, String> params, String region) {
String topicArn = getParam(params, "TopicArn");
String attributeName = getParam(params, "AttributeName");
String attributeValue = getParam(params, "AttributeValue");
- snsService.setTopicAttributes(topicArn, attributeName, attributeValue, region);
- return Response.ok(AwsQueryResponse.envelopeNoResult("SetTopicAttributes", AwsNamespaces.SNS)).build();
+ try {
+ snsService.setTopicAttributes(topicArn, attributeName, attributeValue, region);
+ return Response.ok(AwsQueryResponse.envelopeNoResult("SetTopicAttributes", AwsNamespaces.SNS)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response handleSubscribe(MultivaluedMap<String, String> params, String region) {
String topicArn = getParam(params, "TopicArn");
String protocol = getParam(params, "Protocol");
String endpoint = getParam(params, "Endpoint");
- Subscription sub = snsService.subscribe(topicArn, protocol, endpoint, region);
+ try {
+ Subscription sub = snsService.subscribe(topicArn, protocol, endpoint, region);
- String result = new XmlBuilder().elem("SubscriptionArn", sub.getSubscriptionArn()).build();
- return Response.ok(AwsQueryResponse.envelope("Subscribe", AwsNamespaces.SNS, result)).build();
+ String result = new XmlBuilder().elem("SubscriptionArn", sub.getSubscriptionArn()).build();
+ return Response.ok(AwsQueryResponse.envelope("Subscribe", AwsNamespaces.SNS, result)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response handleUnsubscribe(MultivaluedMap<String, String> params, String region) {
String subscriptionArn = getParam(params, "SubscriptionArn");
- snsService.unsubscribe(subscriptionArn, region);
- return Response.ok(AwsQueryResponse.envelopeNoResult("Unsubscribe", AwsNamespaces.SNS)).build();
+ try {
+ snsService.unsubscribe(subscriptionArn, region);
+ return Response.ok(AwsQueryResponse.envelopeNoResult("Unsubscribe", AwsNamespaces.SNS)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response handleListSubscriptions(MultivaluedMap<String, String> params, String region) {
@@ -129,8 +149,12 @@ public class SnsQueryHandler {
private Response handleListSubscriptionsByTopic(MultivaluedMap<String, String> params, String region) {
String topicArn = getParam(params, "TopicArn");
- List<Subscription> subs = snsService.listSubscriptionsByTopic(topicArn, region);
- return buildSubscriptionListResponse("ListSubscriptionsByTopic", subs);
+ try {
+ List<Subscription> subs = snsService.listSubscriptionsByTopic(topicArn, region);
+ return buildSubscriptionListResponse("ListSubscriptionsByTopic", subs);
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response buildSubscriptionListResponse(String action, List<Subscription> subs) {
@@ -164,11 +188,15 @@ public class SnsQueryHandler {
if (value != null) attributes.put(name, value);
}
- String messageId = snsService.publish(topicArn, targetArn, message, subject,
- attributes, messageGroupId, messageDeduplicationId, region);
+ try {
+ String messageId = snsService.publish(topicArn, targetArn, message, subject,
+ attributes, messageGroupId, messageDeduplicationId, region);
- String result = new XmlBuilder().elem("MessageId", messageId).build();
- return Response.ok(AwsQueryResponse.envelope("Publish", AwsNamespaces.SNS, result)).build();
+ String result = new XmlBuilder().elem("MessageId", messageId).build();
+ return Response.ok(AwsQueryResponse.envelope("Publish", AwsNamespaces.SNS, result)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response handlePublishBatch(MultivaluedMap<String, String> params, String region) {
@@ -185,19 +213,23 @@ public class SnsQueryHandler {
entry.put("MessageDeduplicationId", getParam(params, "PublishBatchRequestEntries.member." + i + ".MessageDeduplicationId"));
entries.add(entry);
}
- SnsService.BatchPublishResult result = snsService.publishBatch(topicArn, entries, region);
+ try {
+ SnsService.BatchPublishResult result = snsService.publishBatch(topicArn, entries, region);
- var xml = new XmlBuilder().start("Successful");
- for (String[] s : result.successful()) {
- xml.start("member").elem("Id", s[0]).elem("MessageId", s[1]).end("member");
- }
- xml.end("Successful").start("Failed");
- for (String[] f : result.failed()) {
- xml.start("member").elem("Id", f[0]).elem("Code", f[1])
- .elem("Message", f[2]).elem("SenderFault", f[3]).end("member");
+ var xml = new XmlBuilder().start("Successful");
+ for (String[] s : result.successful()) {
+ xml.start("member").elem("Id", s[0]).elem("MessageId", s[1]).end("member");
+ }
+ xml.end("Successful").start("Failed");
+ for (String[] f : result.failed()) {
+ xml.start("member").elem("Id", f[0]).elem("Code", f[1])
+ .elem("Message", f[2]).elem("SenderFault", f[3]).end("member");
+ }
+ xml.end("Failed");
+ return Response.ok(AwsQueryResponse.envelope("PublishBatch", AwsNamespaces.SNS, xml.build())).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
}
- xml.end("Failed");
- return Response.ok(AwsQueryResponse.envelope("PublishBatch", AwsNamespaces.SNS, xml.build())).build();
}
private Response handleGetSubscriptionAttributes(MultivaluedMap<String, String> params, String region) {
@@ -242,8 +274,12 @@ public class SnsQueryHandler {
private Response handleTagResource(MultivaluedMap<String, String> params, String region) {
String resourceArn = getParam(params, "ResourceArn");
Map<String, String> tags = extractSnsTags(params);
- snsService.tagResource(resourceArn, tags, region);
- return Response.ok(AwsQueryResponse.envelopeNoResult("TagResource", AwsNamespaces.SNS)).build();
+ try {
+ snsService.tagResource(resourceArn, tags, region);
+ return Response.ok(AwsQueryResponse.envelopeNoResult("TagResource", AwsNamespaces.SNS)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response handleUntagResource(MultivaluedMap<String, String> params, String region) {
@@ -254,23 +290,31 @@ public class SnsQueryHandler {
if (key == null) break;
tagKeys.add(key);
}
- snsService.untagResource(resourceArn, tagKeys, region);
- return Response.ok(AwsQueryResponse.envelopeNoResult("UntagResource", AwsNamespaces.SNS)).build();
+ try {
+ snsService.untagResource(resourceArn, tagKeys, region);
+ return Response.ok(AwsQueryResponse.envelopeNoResult("UntagResource", AwsNamespaces.SNS)).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
+ }
}
private Response handleListTagsForResource(MultivaluedMap<String, String> params, String region) {
String resourceArn = getParam(params, "ResourceArn");
- Map<String, String> tags = snsService.listTagsForResource(resourceArn, region);
-
- var xml = new XmlBuilder().start("Tags");
- for (var entry : tags.entrySet()) {
- xml.start("member")
- .elem("Key", entry.getKey())
- .elem("Value", entry.getValue())
- .end("member");
+ try {
+ Map<String, String> tags = snsService.listTagsForResource(resourceArn, region);
+
+ var xml = new XmlBuilder().start("Tags");
+ for (var entry : tags.entrySet()) {
+ xml.start("member")
+ .elem("Key", entry.getKey())
+ .elem("Value", entry.getValue())
+ .end("member");
+ }
+ xml.end("Tags");
+ return Response.ok(AwsQueryResponse.envelope("ListTagsForResource", AwsNamespaces.SNS, xml.build())).build();
+ } catch (AwsException e) {
+ return xmlErrorResponse(e.getErrorCode(), e.getMessage(), e.getHttpStatus());
}
- xml.end("Tags");
- return Response.ok(AwsQueryResponse.envelope("ListTagsForResource", AwsNamespaces.SNS, xml.build())).build();
}
// --- Helpers ---
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 15585b4302..2954972dc8 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -2,6 +2,8 @@ quarkus:
http:
port: 4566
host: 0.0.0.0
+ limits:
+ max-body-size: 256M
native:
additional-build-args: >-
--initialize-at-run-time=org.apache.hc.client5.http.impl.auth.NTLMEngineImpl,