davsclaus commented on code in PR #25571: URL: https://github.com/apache/camel/pull/25571#discussion_r3852349187
########## components/camel-http/src/test/java/org/apache/camel/component/http/HttpUriHeaderPlaceholderTest.java: ########## @@ -0,0 +1,70 @@ +/* + * 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.http; + +import java.util.Properties; + +import org.apache.camel.Exchange; +import org.apache.camel.http.common.HttpHelper; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.support.DefaultExchange; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Property placeholders are resolved at build time on the endpoint uri written in the route, never on the + * {@code CamelHttpUri} header, which carries message content. See CAMEL-24282 / CAMEL-24418. + */ +class HttpUriHeaderPlaceholderTest { + + @Test + void placeholderInHttpUriHeaderIsNotResolved() throws Exception { + try (DefaultCamelContext context = new DefaultCamelContext()) { + Properties prop = new Properties(); + prop.setProperty("secretValue", "s3cr3t"); + context.getPropertiesComponent().setInitialProperties(prop); + context.start(); + + HttpEndpoint endpoint = context.getEndpoint("http://localhost/base", HttpEndpoint.class); + Exchange exchange = new DefaultExchange(context); + exchange.getIn().setHeader(Exchange.HTTP_URI, "http://localhost/api?k={{secretValue}}"); + + // the token survives as a literal (percent-encoded by UnsafeUriCharactersEncoder, as any other + // unsafe character in a header-supplied uri would be) and is never expanded + assertThat(HttpHelper.createURL(exchange, endpoint)) + .isEqualTo("http://localhost/api?k=%7B%7BsecretValue%7D%7D") + .doesNotContain("s3cr3t"); + } + } + + @Test + void placeholderInEndpointUriIsResolvedAtBuildTime() throws Exception { + try (DefaultCamelContext context = new DefaultCamelContext()) { + Properties prop = new Properties(); + prop.setProperty("basePath", "resolved"); + context.getPropertiesComponent().setInitialProperties(prop); + context.start(); + + // control: a placeholder written in the route's endpoint uri is still resolved, as before + HttpEndpoint endpoint = context.getEndpoint("http://localhost/{{basePath}}", HttpEndpoint.class); + Exchange exchange = new DefaultExchange(context); + + assertThat(HttpHelper.createURL(exchange, endpoint)).isEqualTo("http://localhost/resolved"); + } + } Review Comment: Non-blocking suggestion: the PR body rightly stresses that the `createMethod` family is a *separate* risk from `createURL` (`bridgeEndpoint=true` bounds `createURL` but not `createMethod`), yet this test only exercises `HttpHelper.createURL`. The `createMethod` "leave `{{}}` literal" behavior is only covered indirectly. Consider adding a small assertion on `createMethod` with a `{{...}}` token in the `HTTP_URI` header query — it is the higher-risk path per your own analysis and currently the least directly tested. -- 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]
