* Issue #6327 Fix cookie leak test Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
parent
9cc7517d65
commit
de37267ae5
|
@ -1427,69 +1427,80 @@ public class RequestTest
|
||||||
assertEquals("value", cookies.get(0).getValue());
|
assertEquals("value", cookies.get(0).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("No longer relevant")
|
|
||||||
@Test
|
@Test
|
||||||
public void testCookieLeak() throws Exception
|
public void testCookieLeak() throws Exception
|
||||||
{
|
{
|
||||||
final String[] cookie = new String[10];
|
CookieRequestTester tester = new CookieRequestTester();
|
||||||
|
_handler._checker = tester;
|
||||||
|
|
||||||
_handler._checker = (request, response) ->
|
String[] cookies = new String[10];
|
||||||
{
|
tester.setCookieArray(cookies);
|
||||||
Arrays.fill(cookie, null);
|
LocalEndPoint endp = _connector.connect();
|
||||||
|
endp.addInput("POST / HTTP/1.1\r\n" +
|
||||||
Cookie[] cookies = request.getCookies();
|
|
||||||
for (int i = 0; cookies != null && i < cookies.length; i++)
|
|
||||||
{
|
|
||||||
cookie[i] = cookies[i].getValue();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
String request = "POST / HTTP/1.1\r\n" +
|
|
||||||
"Host: whatever\r\n" +
|
"Host: whatever\r\n" +
|
||||||
"Cookie: other=cookie\r\n" +
|
"Cookie: other=cookie\r\n" +
|
||||||
"\r\n" +
|
"\r\n");
|
||||||
"POST / HTTP/1.1\r\n" +
|
endp.getResponse();
|
||||||
|
assertEquals("cookie", cookies[0]);
|
||||||
|
assertNull(cookies[1]);
|
||||||
|
|
||||||
|
cookies = new String[10];
|
||||||
|
tester.setCookieArray(cookies);
|
||||||
|
endp.addInput("POST / HTTP/1.1\r\n" +
|
||||||
"Host: whatever\r\n" +
|
"Host: whatever\r\n" +
|
||||||
"Cookie: name=value\r\n" +
|
"Cookie: name=value\r\n" +
|
||||||
"Connection: close\r\n" +
|
"Connection: close\r\n" +
|
||||||
"\r\n";
|
"\r\n");
|
||||||
|
endp.getResponse();
|
||||||
|
assertEquals("value", cookies[0]);
|
||||||
|
assertNull(cookies[1]);
|
||||||
|
|
||||||
_connector.getResponse(request);
|
endp = _connector.connect();
|
||||||
|
cookies = new String[10];
|
||||||
assertEquals("value", cookie[0]);
|
tester.setCookieArray(cookies);
|
||||||
assertNull(cookie[1]);
|
endp.addInput("POST / HTTP/1.1\r\n" +
|
||||||
|
|
||||||
request = "POST / HTTP/1.1\r\n" +
|
|
||||||
"Host: whatever\r\n" +
|
"Host: whatever\r\n" +
|
||||||
"Cookie: name=value\r\n" +
|
"Cookie: name=value\r\n" +
|
||||||
"\r\n" +
|
"\r\n");
|
||||||
"POST / HTTP/1.1\r\n" +
|
endp.getResponse();
|
||||||
|
assertEquals("value", cookies[0]);
|
||||||
|
assertNull(cookies[1]);
|
||||||
|
|
||||||
|
cookies = new String[10];
|
||||||
|
tester.setCookieArray(cookies);
|
||||||
|
endp.addInput("POST / HTTP/1.1\r\n" +
|
||||||
"Host: whatever\r\n" +
|
"Host: whatever\r\n" +
|
||||||
"Cookie: \r\n" +
|
"Cookie: \r\n" +
|
||||||
"Connection: close\r\n" +
|
"Connection: close\r\n" +
|
||||||
"\r\n";
|
"\r\n");
|
||||||
|
endp.getResponse();
|
||||||
|
assertNull(cookies[0]);
|
||||||
|
assertNull(cookies[1]);
|
||||||
|
|
||||||
_connector.getResponse(request);
|
endp = _connector.connect();
|
||||||
assertNull(cookie[0]);
|
cookies = new String[10];
|
||||||
assertNull(cookie[1]);
|
tester.setCookieArray(cookies);
|
||||||
|
endp.addInput("POST / HTTP/1.1\r\n" +
|
||||||
request = "POST / HTTP/1.1\r\n" +
|
|
||||||
"Host: whatever\r\n" +
|
"Host: whatever\r\n" +
|
||||||
"Cookie: name=value\r\n" +
|
"Cookie: name=value\r\n" +
|
||||||
"Cookie: other=cookie\r\n" +
|
"Cookie: other=cookie\r\n" +
|
||||||
"\r\n" +
|
"\r\n");
|
||||||
"POST / HTTP/1.1\r\n" +
|
endp.getResponse();
|
||||||
|
assertEquals("value", cookies[0]);
|
||||||
|
assertEquals("cookie", cookies[1]);
|
||||||
|
assertNull(cookies[2]);
|
||||||
|
|
||||||
|
cookies = new String[10];
|
||||||
|
tester.setCookieArray(cookies);
|
||||||
|
endp.addInput("POST / HTTP/1.1\r\n" +
|
||||||
"Host: whatever\r\n" +
|
"Host: whatever\r\n" +
|
||||||
"Cookie: name=value\r\n" +
|
"Cookie: name=value\r\n" +
|
||||||
"Cookie:\r\n" +
|
"Cookie:\r\n" +
|
||||||
"Connection: close\r\n" +
|
"Connection: close\r\n" +
|
||||||
"\r\n";
|
"\r\n");
|
||||||
|
endp.getResponse();
|
||||||
_connector.getResponse(request);
|
assertEquals("value", cookies[0]);
|
||||||
|
assertNull(cookies[1]);
|
||||||
assertEquals("value", cookie[0]);
|
|
||||||
assertNull(cookie[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1878,6 +1889,29 @@ public class RequestTest
|
||||||
boolean check(HttpServletRequest request, HttpServletResponse response) throws IOException;
|
boolean check(HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class CookieRequestTester implements RequestTester
|
||||||
|
{
|
||||||
|
private String[] _cookieValues;
|
||||||
|
|
||||||
|
public void setCookieArray(String[] cookieValues)
|
||||||
|
{
|
||||||
|
_cookieValues = cookieValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check(HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||||
|
{
|
||||||
|
Arrays.fill(_cookieValues, null);
|
||||||
|
|
||||||
|
Cookie[] cookies = request.getCookies();
|
||||||
|
for (int i = 0; cookies != null && i < cookies.length; i++)
|
||||||
|
{
|
||||||
|
_cookieValues[i] = cookies[i].getValue();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class TestRequest extends Request
|
private static class TestRequest extends Request
|
||||||
{
|
{
|
||||||
public static final String TEST_SESSION_ID = "abc123";
|
public static final String TEST_SESSION_ID = "abc123";
|
||||||
|
|
Loading…
Reference in New Issue