Skip to content

Commit a1397ad

Browse files
Souvik Ghoshapupier
authored andcommitted
Add http non proxy host tests usecase
1 parent 43366eb commit a1397ad

File tree

2 files changed

+57
-0
lines changed
  • integration-test-groups/http/http/src

2 files changed

+57
-0
lines changed

integration-test-groups/http/http/src/main/java/org/apache/camel/quarkus/component/http/http/HttpResource.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,25 @@ public String httpProxy() {
120120
.request(String.class);
121121
}
122122

123+
@Path("/nonProxy")
124+
@GET
125+
@Produces(MediaType.APPLICATION_XML)
126+
public String nonProxy(@QueryParam("non-proxy-hosts") String nonProxyHosts, @QueryParam("proxy-host") String proxyHost,
127+
@QueryParam("proxy-port") int proxyPort) {
128+
return producerTemplate
129+
.toF("%s?"
130+
+ "proxyAuthMethod=Basic"
131+
+ "&proxyAuthScheme=http"
132+
+ "&proxyAuthHost=%s"
133+
+ "&proxyAuthPort=%d"
134+
+ "&proxyAuthUsername=%s"
135+
+ "&proxyAuthPassword=%s"
136+
+ "&nonProxyHosts=%s", String.format(PROXIED_URL, "http"),
137+
proxyHost, proxyPort, USER_ADMIN,
138+
USER_ADMIN_PASSWORD, nonProxyHosts)
139+
.request(String.class);
140+
}
141+
123142
@Path("/send-dynamic")
124143
@GET
125144
@Produces(MediaType.APPLICATION_JSON)

integration-test-groups/http/http/src/test/java/org/apache/camel/quarkus/component/http/http/it/HttpTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.camel.quarkus.component.http.http.it;
1818

19+
import java.util.stream.Stream;
20+
1921
import io.quarkus.test.common.QuarkusTestResource;
2022
import io.quarkus.test.junit.QuarkusTest;
2123
import io.restassured.RestAssured;
@@ -25,11 +27,16 @@
2527
import org.apache.camel.quarkus.component.http.common.AbstractHttpTest;
2628
import org.apache.camel.quarkus.component.http.common.HttpTestResource;
2729
import org.apache.camel.quarkus.test.support.certificate.TestCertificates;
30+
import org.eclipse.microprofile.config.ConfigProvider;
2831
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.params.ParameterizedTest;
33+
import org.junit.jupiter.params.provider.Arguments;
34+
import org.junit.jupiter.params.provider.MethodSource;
2935

3036
import static org.hamcrest.Matchers.empty;
3137
import static org.hamcrest.Matchers.is;
3238
import static org.hamcrest.Matchers.not;
39+
import static org.junit.jupiter.params.provider.Arguments.arguments;
3340

3441
@TestCertificates(certificates = {
3542
@Certificate(name = HttpTestResource.KEYSTORE_NAME, formats = {
@@ -91,4 +98,35 @@ public void compression() {
9198
.body(is("Compressed response"));
9299
}
93100

101+
@ParameterizedTest
102+
@MethodSource("proxyProviders")
103+
void testNonProxyRouting(String nonProxyHosts, int proxyPort, String proxyHost, int status, String expectedBody) {
104+
var response = RestAssured.given()
105+
.queryParam("non-proxy-hosts", nonProxyHosts)
106+
.queryParam("proxy-port", proxyPort)
107+
.queryParam("proxy-host", proxyHost)
108+
.when()
109+
.get("/test/client/{component}/nonProxy", component())
110+
.then()
111+
.statusCode(status);
112+
113+
// Only check the body if an expected value was provided and not null
114+
if (expectedBody != null) {
115+
response.body("metadata.groupId", is(expectedBody));
116+
}
117+
}
118+
119+
static Stream<Arguments> proxyProviders() {
120+
var config = ConfigProvider.getConfig();
121+
String host = config.getValue("proxy.host", String.class);
122+
int actualPort = config.getValue("proxy.port", Integer.class);
123+
int fakePort = RestAssured.port;
124+
String expectedGroupId = "org.apache.camel.quarkus";
125+
126+
return Stream.of(
127+
arguments("repo.maven.apache.org", actualPort, host, 200, expectedGroupId),
128+
arguments("*.apache.org", fakePort, host, 200, expectedGroupId),
129+
arguments("*localhost*", fakePort, host, 500, null));
130+
}
131+
94132
}

0 commit comments

Comments
 (0)