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


##########
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerEncodedUriTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.undertow;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The undertow producer must not write a request path, query or header value 
that it cannot put on the wire as it is: a
+ * percent-encoded CR/LF in {@code CamelHttpPath} or {@code CamelHttpQuery}, 
or a CR/LF in a header value, is refused
+ * rather than written into the request line or a header line. An ordinary 
query is still sent.
+ */
+class UndertowProducerEncodedUriTest extends BaseUndertowTest {
+
+    @Test
+    void rejectsEncodedCrlfInQuery() {
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
+                e -> e.getIn().setHeader(Exchange.HTTP_QUERY, 
"q=x%0D%0AX-Injected:%201"));
+        assertRejected(out, "request target");
+    }
+
+    @Test
+    void rejectsEncodedCrlfInPath() {
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
+                e -> e.getIn().setHeader(Exchange.HTTP_PATH, "a%0D%0Ab"));
+        assertRejected(out, "request target");
+    }
+
+    @Test
+    void rejectsHeaderValueWithCrlf() {
+        Exchange out = 
template.request("undertow:http://localhost:{{port}}/echo";,
+                e -> e.getIn().setHeader("MyHeader", "value\r\nX-Injected: 
1"));
+        assertRejected(out, "HTTP header");
+    }
+
+    @Test
+    void sendsAnOrdinaryQuery() {
+        String out = 
template.requestBodyAndHeader("undertow:http://localhost:{{port}}/echo";,
+                null, Exchange.HTTP_QUERY, "q=hello", String.class);
+        assertEquals("q=hello", out);
+    }

Review Comment:
   Added `rejectsNarrowingCharacterInQuery` in 333f977 — it sets 
`CamelHttpQuery` to `q=Ċ` (U+010A), which the producer decodes to a single char 
above `0xFF`; the client would narrow it to `0x0A` (LF), so `checkWriteable` 
now rejects it via the `ch > 0xFF` branch. Thanks for catching the gap in 
coverage.
   
   _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