use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestELInJsp method testBug57441.
/*
* BZ https://bz.apache.org/bugzilla/show_bug.cgi?id=57441
* Can't validate function names defined in lambdas (or via imports)
*/
@Test
public void testBug57441() throws Exception {
getTomcatInstanceTestWebapp(false, true);
ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug57441.jsp");
String result = res.toString();
assertEcho(result, "00-11");
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestClientCert method doTestClientCertPost.
private void doTestClientCertPost(int bodySize, boolean expectProtectedFail) throws Exception {
Assume.assumeTrue("SSL renegotiation has to be supported for this test", TesterSupport.isRenegotiationSupported(getTomcatInstance()));
getTomcatInstance().start();
byte[] body = new byte[bodySize];
Arrays.fill(body, TesterSupport.DATA);
// Unprotected resource
ByteChunk res = postUrl(body, "https://localhost:" + getPort() + "/unprotected");
assertEquals("OK-" + bodySize, res.toString());
// Protected resource
res.recycle();
int rc = postUrl(body, "https://localhost:" + getPort() + "/protected", res, null);
if (expectProtectedFail) {
assertEquals(401, rc);
} else {
assertEquals("OK-" + bodySize, res.toString());
}
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestCookieProcessorGenerationHttp method testUtf8CookieValue.
@Test
public void testUtf8CookieValue() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.setCookieProcessor(new Rfc6265CookieProcessor());
Tomcat.addServlet(ctx, "test", new CookieServlet("Ġ"));
ctx.addServletMappingDecoded("/test", "test");
tomcat.start();
Map<String, List<String>> headers = new HashMap<>();
ByteChunk res = new ByteChunk();
getUrl("http://localhost:" + getPort() + "/test", res, headers);
List<String> cookieHeaders = headers.get("Set-Cookie");
Assert.assertEquals("There should only be one Set-Cookie header in this test", 1, cookieHeaders.size());
// Client is assuming header is ISO-8859-1 encoding which it isn't. Turn
// the header value back into the received bytes (this isn't guaranteed
// to work with all values but it will for this test value)
byte[] headerBytes = cookieHeaders.get(0).getBytes(StandardCharsets.ISO_8859_1);
// Now convert those bytes to a String using UTF-8
String utf8Header = new String(headerBytes, StandardCharsets.UTF_8);
Assert.assertEquals("Test=Ġ", utf8Header);
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class TestCookiesDefaultSysProps method testCookiesInstance.
@Override
@Test
public void testCookiesInstance() throws Exception {
Tomcat tomcat = getTomcatInstance();
addServlets(tomcat);
tomcat.start();
ByteChunk res = getUrl("http://localhost:" + getPort() + "/invalid");
assertEquals("Cookie name fail", res.toString());
res = getUrl("http://localhost:" + getPort() + "/null");
assertEquals("Cookie name fail", res.toString());
res = getUrl("http://localhost:" + getPort() + "/blank");
assertEquals("Cookie name fail", res.toString());
res = getUrl("http://localhost:" + getPort() + "/invalidFwd");
assertEquals("Cookie name fail", res.toString());
res = getUrl("http://localhost:" + getPort() + "/invalidStrict");
assertEquals("Cookie name ok", res.toString());
res = getUrl("http://localhost:" + getPort() + "/valid");
assertEquals("Cookie name ok", res.toString());
// Need to read response headers to test version switching
Map<String, List<String>> headers = new HashMap<>();
getUrl("http://localhost:" + getPort() + "/switch", res, headers);
List<String> cookieHeaders = headers.get("Set-Cookie");
for (String cookieHeader : cookieHeaders) {
assertEquals("name=\"val?ue\"; Version=1", cookieHeader);
}
}
use of org.apache.tomcat.util.buf.ByteChunk in project tomcat by apache.
the class Request method readChunkedPostBody.
/**
* Read chunked post body.
*
* @return the post body as a bytes array
* @throws IOException if an IO exception occurred
*/
protected byte[] readChunkedPostBody() throws IOException {
ByteChunk body = new ByteChunk();
byte[] buffer = new byte[CACHED_POST_LEN];
int len = 0;
while (len > -1) {
len = getStream().read(buffer, 0, CACHED_POST_LEN);
if (connector.getMaxPostSize() >= 0 && (body.getLength() + len) > connector.getMaxPostSize()) {
// Too much data
checkSwallowInput();
throw new IllegalStateException(sm.getString("coyoteRequest.chunkedPostTooLarge"));
}
if (len > 0) {
body.append(buffer, 0, len);
}
}
if (body.getLength() == 0) {
return null;
}
if (body.getLength() < body.getBuffer().length) {
int length = body.getLength();
byte[] result = new byte[length];
System.arraycopy(body.getBuffer(), 0, result, 0, length);
return result;
}
return body.getBuffer();
}
Aggregations