Refactored test so that's clear that host name verification happens on the client.

This commit is contained in:
Simone Bordet 2013-06-18 10:54:15 +02:00
parent 0162b616b5
commit 9240039366
1 changed files with 14 additions and 16 deletions

View File

@ -48,25 +48,18 @@ import static org.junit.Assert.assertThat;
*/ */
public class HostnameVerificationTest public class HostnameVerificationTest
{ {
private SslContextFactory sslContextFactory = new SslContextFactory(); private SslContextFactory clientSslContextFactory = new SslContextFactory();
private Server server; private Server server = new Server();
private HttpClient client; private HttpClient client;
private NetworkConnector connector; private NetworkConnector connector;
@Before @Before
public void setUp() throws Exception public void setUp() throws Exception
{ {
if (sslContextFactory != null) SslContextFactory serverSslContextFactory = new SslContextFactory();
{ serverSslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
// keystore contains a hostname which doesn't match localhost serverSslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks"); connector = new ServerConnector(server, serverSslContextFactory);
sslContextFactory.setKeyStorePassword("storepwd");
}
sslContextFactory.setEndpointIdentificationAlgorithm("HTTPS");
if (server == null)
server = new Server();
connector = new ServerConnector(server, sslContextFactory);
server.addConnector(connector); server.addConnector(connector);
server.setHandler(new DefaultHandler() server.setHandler(new DefaultHandler()
{ {
@ -79,9 +72,13 @@ public class HostnameVerificationTest
}); });
server.start(); server.start();
// keystore contains a hostname which doesn't match localhost
clientSslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
clientSslContextFactory.setKeyStorePassword("storepwd");
QueuedThreadPool executor = new QueuedThreadPool(); QueuedThreadPool executor = new QueuedThreadPool();
executor.setName(executor.getName() + "-client"); executor.setName(executor.getName() + "-client");
client = new HttpClient(sslContextFactory); client = new HttpClient(clientSslContextFactory);
client.setExecutor(executor); client.setExecutor(executor);
client.start(); client.start();
} }
@ -104,6 +101,7 @@ public class HostnameVerificationTest
@Test @Test
public void simpleGetWithHostnameVerificationEnabledTest() throws Exception public void simpleGetWithHostnameVerificationEnabledTest() throws Exception
{ {
clientSslContextFactory.setEndpointIdentificationAlgorithm("HTTPS");
String uri = "https://localhost:" + connector.getLocalPort() + "/"; String uri = "https://localhost:" + connector.getLocalPort() + "/";
try try
{ {
@ -136,7 +134,7 @@ public class HostnameVerificationTest
@Test @Test
public void simpleGetWithHostnameVerificationDisabledTest() throws Exception public void simpleGetWithHostnameVerificationDisabledTest() throws Exception
{ {
sslContextFactory.setEndpointIdentificationAlgorithm(null); clientSslContextFactory.setEndpointIdentificationAlgorithm(null);
String uri = "https://localhost:" + connector.getLocalPort() + "/"; String uri = "https://localhost:" + connector.getLocalPort() + "/";
try try
{ {
@ -157,7 +155,7 @@ public class HostnameVerificationTest
@Test @Test
public void trustAllDisablesHostnameVerificationTest() throws Exception public void trustAllDisablesHostnameVerificationTest() throws Exception
{ {
sslContextFactory.setTrustAll(true); clientSslContextFactory.setTrustAll(true);
String uri = "https://localhost:" + connector.getLocalPort() + "/"; String uri = "https://localhost:" + connector.getLocalPort() + "/";
try try
{ {