|
10 | 10 | import io.micrometer.core.instrument.simple.SimpleMeterRegistry; |
11 | 11 | import io.vertx.core.Handler; |
12 | 12 | import io.vertx.core.Vertx; |
| 13 | +import io.vertx.core.http.HttpHeaders; |
| 14 | +import io.vertx.core.http.HttpMethod; |
| 15 | +import io.vertx.core.http.RequestOptions; |
13 | 16 | import io.vertx.core.json.JsonObject; |
| 17 | +import io.vertx.ext.web.AllowForwardHeaders; |
14 | 18 | import io.vertx.ext.web.Router; |
15 | 19 | import io.vertx.ext.web.RoutingContext; |
16 | 20 | import io.vertx.ext.web.client.WebClient; |
17 | 21 | import io.vertx.junit5.VertxExtension; |
18 | 22 | import io.vertx.junit5.VertxTestContext; |
19 | | -import org.assertj.core.condition.AnyOf; |
20 | 23 | import org.junit.jupiter.api.Assertions; |
21 | 24 | import org.junit.jupiter.api.BeforeEach; |
22 | 25 | import org.junit.jupiter.api.Test; |
23 | 26 | import org.junit.jupiter.api.extension.ExtendWith; |
24 | 27 | import org.junit.jupiter.params.ParameterizedTest; |
25 | 28 | import org.junit.jupiter.params.provider.Arguments; |
26 | 29 | import org.junit.jupiter.params.provider.MethodSource; |
27 | | -import org.mockito.Mock; |
28 | 30 | import org.mockito.Mockito; |
29 | 31 |
|
30 | 32 | import java.time.Instant; |
31 | | -import java.util.HashSet; |
32 | 33 | import java.util.Set; |
33 | 34 | import java.util.stream.Stream; |
34 | 35 |
|
35 | | -import static org.mockito.ArgumentMatchers.anyInt; |
36 | 36 | import static org.mockito.Mockito.when; |
37 | 37 |
|
38 | 38 | @ExtendWith(VertxExtension.class) |
@@ -147,6 +147,32 @@ public void captureUnknownPath(Vertx vertx, VertxTestContext testContext) { |
147 | 147 | })); |
148 | 148 | } |
149 | 149 |
|
| 150 | + @Test |
| 151 | + public void handleIncorrectRemoteAddress(Vertx vertx, VertxTestContext testContext) { |
| 152 | + Router router = Router.router(vertx); |
| 153 | + router.allowForward(AllowForwardHeaders.X_FORWARD); |
| 154 | + router.route().handler(new RequestCapturingHandler(siteStore)); |
| 155 | + |
| 156 | + vertx.createHttpServer().requestHandler(router).listen(Port, testContext.succeeding(id -> { |
| 157 | + WebClient client = WebClient.create(vertx); |
| 158 | + RequestOptions requestOptions = new RequestOptions(); |
| 159 | + requestOptions.setHost("localhost"); |
| 160 | + requestOptions.setPort(Integer.valueOf(Port)); |
| 161 | + requestOptions.addHeader(HttpHeaders.createOptimized("X-Forwarded-Host"), "[2001:db8::1"); // Incorrect IPV6 |
| 162 | + client.request(HttpMethod.GET, requestOptions).sendJsonObject(new JsonObject(), testContext.succeeding(response -> testContext.verify(() -> { |
| 163 | + Assertions.assertDoesNotThrow(() -> |
| 164 | + Metrics.globalRegistry |
| 165 | + .get("uid2.http_requests") |
| 166 | + .tag("status", "404") |
| 167 | + .tag("method", "GET") |
| 168 | + .tag("path", "unknown") |
| 169 | + .counter() |
| 170 | + ); |
| 171 | + testContext.completeNow(); |
| 172 | + }))); |
| 173 | + })); |
| 174 | + } |
| 175 | + |
150 | 176 | @ParameterizedTest |
151 | 177 | @MethodSource("siteIdRoutingContextData") |
152 | 178 | public void getSiteIdFromRoutingContextData(String key, Object value, String siteId, String siteName, Vertx vertx, VertxTestContext testContext) { |
|
0 commit comments