|
24 | 24 | import java.net.URLEncoder;
|
25 | 25 | import java.nio.charset.StandardCharsets;
|
26 | 26 | import java.util.Locale;
|
| 27 | +import java.util.concurrent.CountDownLatch; |
27 | 28 | import java.util.concurrent.ExecutionException;
|
28 | 29 | import java.util.concurrent.TimeUnit;
|
| 30 | +import java.util.concurrent.atomic.AtomicReference; |
29 | 31 | import javax.servlet.ServletException;
|
30 | 32 | import javax.servlet.http.HttpServletRequest;
|
31 | 33 | import javax.servlet.http.HttpServletResponse;
|
|
36 | 38 | import org.eclipse.jetty.http.HttpHeader;
|
37 | 39 | import org.eclipse.jetty.http.HttpMethod;
|
38 | 40 | import org.eclipse.jetty.http.HttpStatus;
|
| 41 | +import org.eclipse.jetty.http.UriCompliance; |
| 42 | +import org.eclipse.jetty.server.HttpConfiguration; |
39 | 43 | import org.eclipse.jetty.server.handler.AbstractHandler;
|
40 | 44 | import org.eclipse.jetty.toolchain.test.Net;
|
41 | 45 | import org.eclipse.jetty.util.Fields;
|
@@ -77,6 +81,52 @@ public void testIPv6Host(Scenario scenario) throws Exception
|
77 | 81 | assertEquals(HttpStatus.OK_200, request.send().getStatus());
|
78 | 82 | }
|
79 | 83 |
|
| 84 | + @ParameterizedTest |
| 85 | + @ArgumentsSource(ScenarioProvider.class) |
| 86 | + public void testPathWithPathParameter(Scenario scenario) throws Exception |
| 87 | + { |
| 88 | + AtomicReference<CountDownLatch> serverLatchRef = new AtomicReference<>(); |
| 89 | + start(scenario, new EmptyServerHandler() |
| 90 | + { |
| 91 | + @Override |
| 92 | + protected void service(String target, org.eclipse.jetty.server.Request jettyRequest, HttpServletRequest request, HttpServletResponse response) |
| 93 | + { |
| 94 | + if (jettyRequest.getHttpURI().hasAmbiguousEmptySegment()) |
| 95 | + response.setStatus(400); |
| 96 | + serverLatchRef.get().countDown(); |
| 97 | + } |
| 98 | + }); |
| 99 | + // Allow empty segments to test them. |
| 100 | + connector.getContainedBeans(HttpConfiguration.class) |
| 101 | + .forEach(httpConfig -> httpConfig.setUriCompliance(UriCompliance.from("DEFAULT,AMBIGUOUS_EMPTY_SEGMENT"))); |
| 102 | + |
| 103 | + serverLatchRef.set(new CountDownLatch(1)); |
| 104 | + ContentResponse response1 = client.newRequest("localhost", connector.getLocalPort()) |
| 105 | + .scheme(scenario.getScheme()) |
| 106 | + .path("/url;p=v") |
| 107 | + .send(); |
| 108 | + assertEquals(HttpStatus.OK_200, response1.getStatus()); |
| 109 | + assertTrue(serverLatchRef.get().await(5, TimeUnit.SECONDS)); |
| 110 | + |
| 111 | + // Ambiguous empty segment. |
| 112 | + serverLatchRef.set(new CountDownLatch(1)); |
| 113 | + ContentResponse response2 = client.newRequest("localhost", connector.getLocalPort()) |
| 114 | + .scheme(scenario.getScheme()) |
| 115 | + .path(";p=v/url") |
| 116 | + .send(); |
| 117 | + assertEquals(HttpStatus.BAD_REQUEST_400, response2.getStatus()); |
| 118 | + assertTrue(serverLatchRef.get().await(5, TimeUnit.SECONDS)); |
| 119 | + |
| 120 | + // Ambiguous empty segment. |
| 121 | + serverLatchRef.set(new CountDownLatch(1)); |
| 122 | + ContentResponse response3 = client.newRequest("localhost", connector.getLocalPort()) |
| 123 | + .scheme(scenario.getScheme()) |
| 124 | + .path(";@host.org/url") |
| 125 | + .send(); |
| 126 | + assertEquals(HttpStatus.BAD_REQUEST_400, response3.getStatus()); |
| 127 | + assertTrue(serverLatchRef.get().await(5, TimeUnit.SECONDS)); |
| 128 | + } |
| 129 | + |
80 | 130 | @ParameterizedTest
|
81 | 131 | @ArgumentsSource(ScenarioProvider.class)
|
82 | 132 | public void testIDNHost(Scenario scenario) throws Exception
|
|
0 commit comments