Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -152,18 +153,20 @@ public void testSslConfClassPathFirst() throws Exception {
assertNotEquals(conf, sslConfLoaded);
}

@Test(expected = IllegalStateException.class)
@Test
public void clientMode() throws Exception {
Configuration conf = createConfiguration(false, true);
SSLFactory sslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
try {
sslFactory.init();
Assert.assertNotNull(sslFactory.createSSLSocketFactory());
Assert.assertNotNull(sslFactory.getHostnameVerifier());
sslFactory.createSSLServerSocketFactory();
} finally {
sslFactory.destroy();
}
assertThrows(IllegalStateException.class, () -> {
try {
sslFactory.init();
Assert.assertNotNull(sslFactory.createSSLSocketFactory());
Assert.assertNotNull(sslFactory.getHostnameVerifier());
sslFactory.createSSLServerSocketFactory();
} finally {
sslFactory.destroy();
}
});
}

private void serverMode(boolean clientCert, boolean socket) throws Exception {
Expand All @@ -184,24 +187,32 @@ private void serverMode(boolean clientCert, boolean socket) throws Exception {
}


@Test(expected = IllegalStateException.class)
@Test
public void serverModeWithoutClientCertsSocket() throws Exception {
serverMode(false, true);
assertThrows(IllegalStateException.class, () -> {
serverMode(false, true);
});
}

@Test(expected = IllegalStateException.class)
@Test
public void serverModeWithClientCertsSocket() throws Exception {
serverMode(true, true);
assertThrows(IllegalStateException.class, () -> {
serverMode(true, true);
});
}

@Test(expected = IllegalStateException.class)
@Test
public void serverModeWithoutClientCertsVerifier() throws Exception {
serverMode(false, false);
assertThrows(IllegalStateException.class, () -> {
serverMode(false, false);
});
}

@Test(expected = IllegalStateException.class)
@Test
public void serverModeWithClientCertsVerifier() throws Exception {
serverMode(true, false);
assertThrows(IllegalStateException.class, () -> {
serverMode(true, false);
});
}

private void runDelegatedTasks(SSLEngineResult result, SSLEngine engine)
Expand Down Expand Up @@ -357,16 +368,18 @@ public void validHostnameVerifier() throws Exception {
sslFactory.destroy();
}

@Test(expected = GeneralSecurityException.class)
@Test
public void invalidHostnameVerifier() throws Exception {
Configuration conf = createConfiguration(false, true);
conf.set(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, "foo");
SSLFactory sslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
try {
sslFactory.init();
} finally {
sslFactory.destroy();
}
assertThrows(GeneralSecurityException.class, () -> {
try {
sslFactory.init();
} finally {
sslFactory.destroy();
}
});
}

@Test
Expand Down