use of org.hamcrest.Matchers.containsString in project jetty.project by eclipse.
the class HttpServerTestBase method testFullHeader.
/*
* Feed a full header method
*/
@Test
public void testFullHeader() throws Exception {
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
StacklessLogging stackless = new StacklessLogging(HttpConnection.class)) {
Log.getLogger(HttpConnection.class).info("expect header is too large, then ISE extra data ...");
OutputStream os = client.getOutputStream();
byte[] buffer = new byte[64 * 1024];
buffer[0] = 'G';
buffer[1] = 'E';
buffer[2] = 'T';
buffer[3] = ' ';
buffer[4] = '/';
buffer[5] = ' ';
buffer[6] = 'H';
buffer[7] = 'T';
buffer[8] = 'T';
buffer[9] = 'P';
buffer[10] = '/';
buffer[11] = '1';
buffer[12] = '.';
buffer[13] = '0';
buffer[14] = '\n';
buffer[15] = 'H';
buffer[16] = ':';
Arrays.fill(buffer, 17, buffer.length - 1, (byte) 'A');
os.write(buffer);
os.flush();
// Read the response.
String response = readResponse(client);
Assert.assertThat(response, Matchers.containsString("HTTP/1.1 431 "));
}
}
use of org.hamcrest.Matchers.containsString in project jetty.project by eclipse.
the class SniSslConnectionFactoryTest method testSocketCustomization.
@Test
public void testSocketCustomization() throws Exception {
final Queue<String> history = new LinkedBlockingQueue<>();
_connector.addBean(new SocketCustomizationListener() {
@Override
protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
history.add("customize connector " + connection + "," + ssl);
}
});
_connector.getBean(SslConnectionFactory.class).addBean(new SocketCustomizationListener() {
@Override
protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
history.add("customize ssl " + connection + "," + ssl);
}
});
_connector.getBean(HttpConnectionFactory.class).addBean(new SocketCustomizationListener() {
@Override
protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
history.add("customize http " + connection + "," + ssl);
}
});
String response = getResponse("127.0.0.1", null);
Assert.assertThat(response, Matchers.containsString("X-HOST: 127.0.0.1"));
Assert.assertEquals("customize connector class org.eclipse.jetty.io.ssl.SslConnection,false", history.poll());
Assert.assertEquals("customize ssl class org.eclipse.jetty.io.ssl.SslConnection,false", history.poll());
Assert.assertEquals("customize connector class org.eclipse.jetty.server.HttpConnection,true", history.poll());
Assert.assertEquals("customize http class org.eclipse.jetty.server.HttpConnection,true", history.poll());
Assert.assertEquals(0, history.size());
}
use of org.hamcrest.Matchers.containsString in project jetty.project by eclipse.
the class SniSslConnectionFactoryTest method testConnect.
@Test
public void testConnect() throws Exception {
String response = getResponse("127.0.0.1", null);
Assert.assertThat(response, Matchers.containsString("X-HOST: 127.0.0.1"));
}
use of org.hamcrest.Matchers.containsString in project jetty.project by eclipse.
the class SniSslConnectionFactoryTest method testSameConnectionRequestsForManyWildDomains.
@Test
public void testSameConnectionRequestsForManyWildDomains() throws Exception {
SslContextFactory clientContextFactory = new SslContextFactory(true);
clientContextFactory.start();
SSLSocketFactory factory = clientContextFactory.getSslContext().getSocketFactory();
try (SSLSocket sslSocket = (SSLSocket) factory.createSocket("127.0.0.1", _port)) {
SNIHostName serverName = new SNIHostName("www.domain.com");
SSLParameters params = sslSocket.getSSLParameters();
params.setServerNames(Collections.singletonList(serverName));
sslSocket.setSSLParameters(params);
sslSocket.startHandshake();
String request = "" + "GET /ctx/path HTTP/1.1\r\n" + "Host: www.domain.com\r\n" + "\r\n";
OutputStream output = sslSocket.getOutputStream();
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = sslSocket.getInputStream();
String response = response(input);
Assert.assertTrue(response.startsWith("HTTP/1.1 200 "));
// Now, on the same socket, send a request for a different valid domain.
request = "" + "GET /ctx/path HTTP/1.1\r\n" + "Host: assets.domain.com\r\n" + "\r\n";
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = response(input);
Assert.assertTrue(response.startsWith("HTTP/1.1 200 "));
// Now make a request for an invalid domain for this connection.
request = "" + "GET /ctx/path HTTP/1.1\r\n" + "Host: www.example.com\r\n" + "\r\n";
output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = response(input);
Assert.assertTrue(response.startsWith("HTTP/1.1 400 "));
Assert.assertThat(response, Matchers.containsString("Host does not match SNI"));
} finally {
clientContextFactory.stop();
}
}
use of org.hamcrest.Matchers.containsString in project jetty.project by eclipse.
the class SniSslConnectionFactoryTest method testSNIConnect.
@Test
public void testSNIConnect() throws Exception {
String response = getResponse("jetty.eclipse.org", "jetty.eclipse.org");
Assert.assertThat(response, Matchers.containsString("X-HOST: jetty.eclipse.org"));
response = getResponse("www.example.com", "www.example.com");
Assert.assertThat(response, Matchers.containsString("X-HOST: www.example.com"));
response = getResponse("foo.domain.com", "*.domain.com");
Assert.assertThat(response, Matchers.containsString("X-HOST: foo.domain.com"));
response = getResponse("m.san.com", "san example");
Assert.assertThat(response, Matchers.containsString("X-HOST: m.san.com"));
response = getResponse("www.san.com", "san example");
Assert.assertThat(response, Matchers.containsString("X-HOST: www.san.com"));
}
Aggregations