mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(eventbridge): omit event-bus-name from delivered event envelopes (#9189)
EventBridgeService.buildEventEnvelope added an extra top-level event-bus-name field that real AWS EventBridge envelopes do not include. Remove event-bus-name from the delivered envelope, update existing EventBridge and SES integration tests to assert it is omitted, and add a unit test verifying the exact set of AWS envelope fields on custom buses. Closes #9188
This commit is contained in:
1 parent
2985a3b224
commit
c0e1728d99
6 files changed
+41
-9
No files matched your search
@@ -1210,7 +1210,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
if (matchesPattern(entry, rule.getEventPattern())) {
|
||||
String ruleKey = ruleKey(region, effectiveBus, rule.getName());
|
||||
List<Target> targets = getInAccount(targetStore, accountId, ruleKey).orElse(List.of());
|
||||
String eventJson = buildEventEnvelope(entry, effectiveBus, eventId, region, accountId);
|
||||
String eventJson = buildEventEnvelope(entry, eventId, region, accountId);
|
||||
for (Target target : targets) {
|
||||
dispatcher.dispatch(rule.getArn(), target, eventJson, region,
|
||||
() -> getInAccount(targetStore, accountId, ruleKey).orElse(List.of()));
|
||||
@@ -1598,7 +1598,7 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
// ──────────────────────────── Target Routing ────────────────────────────
|
||||
|
||||
|
||||
private String buildEventEnvelope(Map<String, Object> entry, String busName, String eventId,
|
||||
private String buildEventEnvelope(Map<String, Object> entry, String eventId,
|
||||
String callRegion, String callAccountId) {
|
||||
try {
|
||||
String source = (String) entry.getOrDefault("Source", "");
|
||||
@@ -1630,7 +1630,6 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
node.put("region", envelopeRegion);
|
||||
node.putArray("resources").addAll(resources);
|
||||
node.set("detail", objectMapper.readTree(detail));
|
||||
node.put("event-bus-name", busName);
|
||||
return objectMapper.writeValueAsString(node);
|
||||
} catch (Exception e) {
|
||||
return "{}";
|
||||
|
||||
+3
-2
@@ -14,6 +14,7 @@ import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
@@ -146,7 +147,7 @@ class EventBridgeBusToBusIntegrationTest {
|
||||
// Detail must be unwrapped, not the whole envelope re-wrapped.
|
||||
.body("Messages[0].Body", containsString("\"detail\":{\"orderId\":\"o-1\"}"))
|
||||
.body("Messages[0].Body", containsString("\"resources\":[\"arn:aws:s3:::b2b-bucket\"]"))
|
||||
.body("Messages[0].Body", containsString("\"event-bus-name\":\"" + TARGET_BUS + "\""));
|
||||
.body("Messages[0].Body", not(containsString("event-bus-name")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,7 +230,7 @@ class EventBridgeBusToBusIntegrationTest {
|
||||
.then().statusCode(200)
|
||||
.body("Messages", hasSize(1))
|
||||
.body("Messages[0].Body", containsString("\"detail\":{\"orderId\":\"xa-1\"}"))
|
||||
.body("Messages[0].Body", containsString("\"event-bus-name\":\"" + XA_TARGET_BUS + "\""))
|
||||
.body("Messages[0].Body", not(containsString("event-bus-name")))
|
||||
// The envelope keeps the originating account, not the target bus's.
|
||||
.body("Messages[0].Body", containsString("\"account\":\"000000000001\""));
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class EventBridgeIntegrationTest {
|
||||
|
||||
String expectedMessage = "\\{\"version\":\"0\",\"id\":\"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\",\"source\":\"com.mycompany.myapp\"," +
|
||||
"\"detail-type\":\"myDetailType\",\"account\":\"000000000000\",\"time\":\"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z\"," +
|
||||
"\"region\":\"us-east-1\",\"resources\":\\[\"resource1\",\"resource2\"],\"detail\":\\{\"key1\":\"value1\",\"key2\":\"value2\"},\"event-bus-name\":\"default\"}";
|
||||
"\"region\":\"us-east-1\",\"resources\":\\[\"resource1\",\"resource2\"],\"detail\":\\{\"key1\":\"value1\",\"key2\":\"value2\"}}";
|
||||
|
||||
given()
|
||||
.contentType(SQS_CONTENT_TYPE)
|
||||
|
||||
+4
-1
@@ -12,6 +12,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
@@ -88,7 +89,9 @@ class EventBridgePartnerEventBusIntegrationTest {
|
||||
.when().post(queuePath)
|
||||
.then().statusCode(200)
|
||||
.body("Messages", hasSize(1))
|
||||
.body("Messages[0].Body", containsString("\"event-bus-name\":\"" + bus + "\""));
|
||||
.body("Messages[0].Body", containsString("\"source\":\"example.com\""))
|
||||
.body("Messages[0].Body", containsString("\"detail\":{\"orderId\":\"o-1\"}"))
|
||||
.body("Messages[0].Body", not(containsString("event-bus-name")));
|
||||
|
||||
given().contentType(EB_CT).header("X-Amz-Target", "AWSEvents.RemoveTargets")
|
||||
.body("{\"Rule\":\"partner-rule\",\"EventBusName\":\"" + bus + "\",\"Ids\":[\"sink\"]}")
|
||||
|
||||
@@ -34,8 +34,10 @@ import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -1592,10 +1594,37 @@ class EventBridgeServiceTest {
|
||||
assertNotNull(result.entries().get(1).get("EventId"));
|
||||
assertEquals("MalformedDetail", result.entries().get(2).get("ErrorCode"));
|
||||
verify(dispatcherMock).dispatch(anyString(), any(Target.class),
|
||||
contains("\"event-bus-name\":\"default\""), anyString(), any());
|
||||
contains("\"id\":\"" + result.entries().get(1).get("EventId") + "\""), anyString(), any());
|
||||
verify(dispatcherMock).dispatch(anyString(), any(Target.class), anyString(), anyString(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putEventsOnCustomBusOmitsEventBusNameFromDeliveredEnvelope() throws Exception {
|
||||
service.createEventBus("orders", null, null, REGION);
|
||||
service.putRule("r1", "orders", "{\"source\":[\"shop\"]}", null, RuleState.ENABLED,
|
||||
null, null, null, REGION);
|
||||
Target target = new Target();
|
||||
target.setId("1");
|
||||
target.setArn("arn:aws:sqs:us-east-1:000000000000:ebq");
|
||||
service.putTargets("r1", "orders", List.of(target), REGION);
|
||||
|
||||
EventBridgeService.PutEventsResult result = service.putEvents(List.of(Map.of(
|
||||
"EventBusName", "orders",
|
||||
"Source", "shop",
|
||||
"DetailType", "Order Shipped",
|
||||
"Detail", "{\"id\":1}")), REGION);
|
||||
|
||||
assertEquals(0, result.failedCount());
|
||||
ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(dispatcherMock).dispatch(anyString(), eq(target), payloadCaptor.capture(), eq(REGION), any());
|
||||
JsonNode envelope = OBJECT_MAPPER.readTree(payloadCaptor.getValue());
|
||||
assertFalse(envelope.has("event-bus-name"));
|
||||
Set<String> fieldNames = new HashSet<>();
|
||||
envelope.fieldNames().forEachRemaining(fieldNames::add);
|
||||
assertEquals(Set.of("version", "id", "source", "detail-type", "account", "time", "region", "resources", "detail"),
|
||||
fieldNames);
|
||||
}
|
||||
|
||||
@Test
|
||||
void putEventsShouldInvokeLambdaTarget() {
|
||||
service.putRule("my-rule", null, "{\"source\":[\"my.app\"]}", null, RuleState.ENABLED,
|
||||
|
||||
@@ -886,7 +886,7 @@ class SesEventPublishingV2IntegrationTest {
|
||||
JsonNode envelope = envelopes.get(0);
|
||||
assertEquals("aws.ses", envelope.path("source").asText());
|
||||
assertEquals("Email Sent", envelope.path("detail-type").asText());
|
||||
assertEquals("default", envelope.path("event-bus-name").asText());
|
||||
assertFalse(envelope.has("event-bus-name"), "EventBridge envelopes must not include event-bus-name");
|
||||
// AWS always emits a `resources` array on the envelope, and SesEventPublisher mirrors
|
||||
// that contract. SesService derives sourceArn from FromEmailAddress, so this case
|
||||
// produces a one-element array carrying the SES identity ARN; the sourceArn-null
|
||||
|
||||
Reference in new issue
Block a user