Search in sources :

Example 1 with SslStores

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());
}
Also used : SslStores(spark.ssl.SslStores) Test(org.junit.Test)

Example 2 with SslStores

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());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) SslStores(spark.ssl.SslStores) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)2 SslStores (spark.ssl.SslStores)2 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1