gnodet-bot commented on code in PR #31122:
URL: https://github.com/apache/camel/pull/31122#discussion_r4738245737


##########
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:
   💡 The acceptance test verifies that a generic `"tenant"` extension passes 
through, but it doesn't cover `aliyuneventbusname` — the actual 
Alibaba-specific extension that `extractEventBusName` reads from `extensions`. 
If that name were accidentally added to `RESERVED_ATTRIBUTE_NAMES` in a future 
change, event-bus-name extraction would break silently with no test failing.
   
   Consider adding an explicit assertion that `aliyuneventbusname` is still 
present (and that the validator doesn't throw), since it is the 
production-critical non-reserved extension:
   
   ```suggestion
       @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);
   
           // Must not throw — non-reserved extensions (including the 
Alibaba-specific
           // aliyuneventbusname that extractEventBusName reads) must remain 
allowed.
           validator.validateCloudEvent(event, config, eventBridgeClient);
           assertThat(event.getExtensions()).containsKey("tenant");
           assertThat(event.getExtensions()).containsKey("aliyuneventbusname");
   ```
   



-- 
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