Adding some extra proxy tests around spaces in query parameters

This commit is contained in:
Joakim Erdfelt 2014-08-01 14:50:54 -07:00
parent 38501a9e97
commit 7406a280b3
1 changed files with 42 additions and 0 deletions

View File

@ -672,6 +672,48 @@ public class ProxyServletTest
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
}
@Test
public void testTransparentProxyWithQueryWithSpaces() throws Exception
{
final String target = "/test";
final String query = "a=1&b=2&c=1234%205678&d=hello+world";
prepareServer(new HttpServlet()
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
if (req.getHeader("Via") != null)
resp.addHeader(PROXIED_HEADER, "true");
if (target.equals(req.getRequestURI()))
{
if (query.equals(req.getQueryString()))
{
resp.setStatus(200);
return;
}
}
resp.setStatus(404);
}
});
String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
String prefix = "/proxy";
proxyServlet = new ProxyServlet.Transparent();
Map<String, String> params = new HashMap<>();
params.put("proxyTo", proxyTo);
params.put("prefix", prefix);
prepareProxy(params);
// Make the request to the proxy, it should transparently forward to the server
ContentResponse response = client.newRequest("localhost", proxyConnector.getLocalPort())
.path(prefix + target + "?" + query)
.timeout(5, TimeUnit.SECONDS)
.send();
Assert.assertEquals(200, response.getStatus());
Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
}
@Test
public void testTransparentProxyWithoutPrefix() throws Exception