oscerd commented on code in PR #31122:
URL: https://github.com/apache/camel/pull/31122#discussion_r4738599108


##########
components/camel-alibaba/camel-alibaba-eventbridge/src/test/java/org/apache/camel/component/alibaba/eventbridge/MapCloudEventValidationTest.java:
##########
@@ -555,4 +557,77 @@ void testSingleBusDslWithUrnAndEquals() {
         assertThat(urnSource2.source()).isEqualTo("urn:another:source");
         assertThat(urnSource2.allowedEventTypes()).isEmpty();
     }
+
+    @Test
+    void cloudEventExtensionNamedSourceIsRejected() {
+        AllowedEventSource allowedSource = new 
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+        AllowedEventBus allowedBus = new AllowedEventBus("orders-bus", 
Map.of("app.orders", allowedSource));
+        ClientConfigurations config = new ClientConfigurations(
+                null, "orders-bus", null, null, null, false, false, true,
+                Map.of("orders-bus", allowedBus), 300000L);
+
+        CloudEvent event = EventBuilder.builder()
+                .withAliyunEventBus("orders-bus")
+                .withSource(URI.create("app.orders"))
+                .withType("OrderCreated")
+                .withId("event-200")
+                .build();
+
+        // the published source would be taken from this extension, not from 
the validated dedicated field
+        Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+        extensions.put("source", "app.other");
+        event.setExtensions(extensions);
+
+        assertThatThrownBy(() -> validator.validateCloudEvent(event, config, 
eventBridgeClient))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("collides with the reserved CloudEvent 
attribute");
+    }
+
+    @Test
+    void cloudEventExtensionNamedTypeIsRejected() {
+        AllowedEventSource allowedSource = new 
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+        AllowedEventBus allowedBus = new AllowedEventBus("orders-bus", 
Map.of("app.orders", allowedSource));
+        ClientConfigurations config = new ClientConfigurations(
+                null, "orders-bus", null, null, null, false, false, true,
+                Map.of("orders-bus", allowedBus), 300000L);
+
+        CloudEvent event = EventBuilder.builder()
+                .withAliyunEventBus("orders-bus")
+                .withSource(URI.create("app.orders"))
+                .withType("OrderCreated")
+                .withId("event-201")
+                .build();
+
+        // the published type would be taken from this extension, not from the 
validated dedicated field
+        Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+        extensions.put("type", "OrderDeleted");
+        event.setExtensions(extensions);
+
+        assertThatThrownBy(() -> validator.validateCloudEvent(event, config, 
eventBridgeClient))
+                .isInstanceOf(IllegalArgumentException.class)
+                .hasMessageContaining("collides with the reserved CloudEvent 
attribute");
+    }
+
+    @Test
+    void cloudEventWithNonReservedExtensionIsAccepted() {
+        AllowedEventSource allowedSource = new 
AllowedEventSource("app.orders", Set.of("OrderCreated"));
+        AllowedEventBus allowedBus = new AllowedEventBus("orders-bus", 
Map.of("app.orders", allowedSource));
+        ClientConfigurations config = new ClientConfigurations(
+                null, "orders-bus", null, null, null, false, false, true,
+                Map.of("orders-bus", allowedBus), 300000L);
+
+        CloudEvent event = EventBuilder.builder()
+                .withAliyunEventBus("orders-bus")
+                .withSource(URI.create("app.orders"))
+                .withType("OrderCreated")
+                .withId("event-202")
+                .build();
+
+        Map<String, Object> extensions = new HashMap<>(event.getExtensions());
+        extensions.put("tenant", "tenant-a");
+        event.setExtensions(extensions);
+
+        validator.validateCloudEvent(event, config, eventBridgeClient);
+        assertThat(event.getExtensions()).containsKey("tenant");

Review Comment:
   Good point. `aliyuneventbusname` is the extension the producer reads back in 
`extractEventBusName` to resolve the target event bus, so it has to stay off 
`RESERVED_ATTRIBUTE_NAMES`, and nothing pinned that.
   
   I pushed a regression test, 
`cloudEventWithAliyunEventBusNameExtensionIsAccepted`: it configures no event 
bus name, so the bus can only be resolved from the `aliyuneventbusname` 
extension, then asserts the event validates and the extension is preserved. It 
fails both if that name is ever added to the reserved set (the reject check 
throws) and if the extraction stops reading it (validation reports a missing 
event bus name). Thanks for catching the gap.
   
   _Claude Code on behalf of oscerd_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to