use of org.apache.catalina.startup.TesterServlet in project tomcat by apache.
the class TestHttp11Processor method testInconsistentHostHeader02.
@Test
public void testInconsistentHostHeader02() throws Exception {
Tomcat tomcat = getTomcatInstance();
// This setting means the connection will be closed at the end of the
// request
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", "1"));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Add servlet
Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
ctx.addServletMappingDecoded("/foo", "TesterServlet");
tomcat.start();
String request = "GET http://a:8080/foo HTTP/1.1" + SimpleHttpClient.CRLF + "Host: b:8080" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
// Expected response is a 400 response.
Assert.assertTrue(client.isResponse400());
}
use of org.apache.catalina.startup.TesterServlet in project tomcat by apache.
the class TestHttp11Processor method testInconsistentHostHeader06.
/*
* Hostname (with port and user) is included in the request line, but Host
* header is empty.
* Added for bug 62739.
*/
@Test
public void testInconsistentHostHeader06() throws Exception {
Tomcat tomcat = getTomcatInstance();
// This setting means the connection will be closed at the end of the
// request
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", "1"));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Add servlet
Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
ctx.addServletMappingDecoded("/foo", "TesterServlet");
tomcat.start();
String request = "GET http://user:pwd@a/foo HTTP/1.1" + SimpleHttpClient.CRLF + "Host: " + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
// Expected response is a 400 response.
Assert.assertTrue(client.isResponse400());
}
use of org.apache.catalina.startup.TesterServlet in project tomcat by apache.
the class TestHttp11Processor method testMissingHostHeader.
@Test
public void testMissingHostHeader() throws Exception {
Tomcat tomcat = getTomcatInstance();
// This setting means the connection will be closed at the end of the
// request
Assert.assertTrue(tomcat.getConnector().setProperty("maxKeepAliveRequests", "1"));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
// Add servlet
Tomcat.addServlet(ctx, "TesterServlet", new TesterServlet());
ctx.addServletMappingDecoded("/foo", "TesterServlet");
tomcat.start();
String request = "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { request });
client.connect();
client.processRequest();
// Expected response is a 400 response.
Assert.assertTrue(client.isResponse400());
}
use of org.apache.catalina.startup.TesterServlet in project tomcat by apache.
the class TestSsl method testRenegotiateWorks.
@Test
public void testRenegotiateWorks() throws Exception {
Tomcat tomcat = getTomcatInstance();
TesterSupport.initSsl(tomcat);
TesterSupport.configureSSLImplementation(tomcat, sslImplementationName);
Assume.assumeTrue("SSL renegotiation has to be supported for this test", TesterSupport.isClientRenegotiationSupported(getTomcatInstance()));
if (needApr) {
AprLifecycleListener listener = new AprLifecycleListener();
Assume.assumeTrue(AprLifecycleListener.isAprAvailable());
StandardServer server = (StandardServer) tomcat.getServer();
server.addLifecycleListener(listener);
}
Context root = tomcat.addContext("", TEMP_DIR);
Wrapper w = Tomcat.addServlet(root, "tester", new TesterServlet());
w.setAsyncSupported(true);
root.addServletMappingDecoded("/", "tester");
tomcat.start();
SSLContext sslCtx;
// Force TLS 1.2 if TLS 1.3 is available as JSSE's TLS 1.3
// implementation doesn't support Post Handshake Authentication
// which is required for this test to pass.
sslCtx = SSLContext.getInstance(Constants.SSL_PROTO_TLSv1_2);
sslCtx.init(null, TesterSupport.getTrustManagers(), null);
SSLSocketFactory socketFactory = sslCtx.getSocketFactory();
SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", getPort());
OutputStream os = socket.getOutputStream();
InputStream is = socket.getInputStream();
Reader r = new InputStreamReader(is);
doRequest(os, r);
Assert.assertTrue("Checking no client issuer has been requested", TesterSupport.getLastClientAuthRequestedIssuerCount() == 0);
TesterHandshakeListener listener = new TesterHandshakeListener();
socket.addHandshakeCompletedListener(listener);
socket.startHandshake();
doRequest(os, r);
// Handshake complete appears to be called asynchronously
int wait = 0;
while (wait < 5000 && !listener.isComplete()) {
wait += 50;
Thread.sleep(50);
}
Assert.assertTrue("Checking no client issuer has been requested", TesterSupport.getLastClientAuthRequestedIssuerCount() == 0);
Assert.assertTrue(listener.isComplete());
System.out.println("Renegotiation completed after " + wait + " ms");
}
use of org.apache.catalina.startup.TesterServlet in project tomcat70 by apache.
the class TestAbstractHttp11Processor method testPipelining.
@Test
public void testPipelining() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctxt = tomcat.addContext("", null);
// Add protected servlet
Tomcat.addServlet(ctxt, "TesterServlet", new TesterServlet());
ctxt.addServletMapping("/foo", "TesterServlet");
tomcat.start();
String requestPart1 = "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF;
String requestPart2 = "Host: any" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
final Client client = new Client(tomcat.getConnector().getLocalPort());
client.setRequest(new String[] { requestPart1, requestPart2 });
client.setRequestPause(1000);
client.setUseContentLength(true);
client.connect();
Runnable send = new Runnable() {
@Override
public void run() {
try {
client.sendRequest();
client.sendRequest();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
Thread t = new Thread(send);
t.start();
// Sleep for 1500 ms which should mean the all of request 1 has been
// sent and half of request 2
Thread.sleep(1500);
// Now read the first response
client.readResponse(true);
Assert.assertFalse(client.isResponse50x());
Assert.assertTrue(client.isResponse200());
Assert.assertEquals("OK", client.getResponseBody());
// Read the second response. No need to sleep, read will block until
// there is data to process
client.readResponse(true);
Assert.assertFalse(client.isResponse50x());
Assert.assertTrue(client.isResponse200());
Assert.assertEquals("OK", client.getResponseBody());
}
Aggregations