use of spark.ssl.SslStores in project spark by perwendel.
the class ServiceTest method testSecure_thenReturnNewSslStores.
@Test
public void testSecure_thenReturnNewSslStores() {
service.secure("keyfile", "keypassword", "truststorefile", "truststorepassword");
SslStores sslStores = Whitebox.getInternalState(service, "sslStores");
assertNotNull("Should return a SslStores because we configured it to have one", sslStores);
assertEquals("Should return keystoreFile from SslStores", "keyfile", sslStores.keystoreFile());
assertEquals("Should return keystorePassword from SslStores", "keypassword", sslStores.keystorePassword());
assertEquals("Should return trustStoreFile from SslStores", "truststorefile", sslStores.trustStoreFile());
assertEquals("Should return trustStorePassword from SslStores", "truststorepassword", sslStores.trustStorePassword());
}
use of spark.ssl.SslStores in project spark by perwendel.
the class SocketConnectorFactoryTest method testCreateSecureSocketConnector.
@Test
@PrepareForTest({ ServerConnector.class })
public void testCreateSecureSocketConnector() throws Exception {
final String host = "localhost";
final int port = 8888;
final String keystoreFile = "keystoreFile.jks";
final String keystorePassword = "keystorePassword";
final String truststoreFile = "truststoreFile.jks";
final String trustStorePassword = "trustStorePassword";
SslStores sslStores = SslStores.create(keystoreFile, keystorePassword, truststoreFile, trustStorePassword);
Server server = new Server();
ServerConnector serverConnector = SocketConnectorFactory.createSecureSocketConnector(server, host, port, sslStores);
String internalHost = Whitebox.getInternalState(serverConnector, "_host");
int internalPort = Whitebox.getInternalState(serverConnector, "_port");
assertEquals("Server Connector Host should be set to the specified server", host, internalHost);
assertEquals("Server Connector Port should be set to the specified port", port, internalPort);
Map<String, ConnectionFactory> factories = Whitebox.getInternalState(serverConnector, "_factories");
assertTrue("Should return true because factory for SSL should have been set", factories.containsKey("ssl") && factories.get("ssl") != null);
SslConnectionFactory sslConnectionFactory = (SslConnectionFactory) factories.get("ssl");
SslContextFactory sslContextFactory = sslConnectionFactory.getSslContextFactory();
assertEquals("Should return the Keystore file specified", keystoreFile, sslContextFactory.getKeyStoreResource().getFile().getName());
assertEquals("Should return the Truststore file specified", truststoreFile, sslContextFactory.getTrustStoreResource().getFile().getName());
}
Aggregations