use of io.netty.handler.ssl.SslContext in project rest.li by linkedin.
the class TestHttp2AlpnHandler method testChannelCloseBeforeNegotiation.
@Test(timeOut = 10000)
@SuppressWarnings("unchecked")
public void testChannelCloseBeforeNegotiation() throws Exception {
SslContext sslContext = Mockito.mock(SslContext.class);
Http2StreamCodec http2StreamCodec = Mockito.mock(Http2StreamCodec.class);
Http2AlpnHandler handler = new Http2AlpnHandler(sslContext, http2StreamCodec, true, Integer.MAX_VALUE);
EmbeddedChannel channel = new EmbeddedChannel(handler);
RequestWithCallback request = Mockito.mock(RequestWithCallback.class);
TimeoutAsyncPoolHandle handle = Mockito.mock(TimeoutAsyncPoolHandle.class);
TimeoutTransportCallback callback = Mockito.mock(TimeoutTransportCallback.class);
Mockito.when(request.handle()).thenReturn(handle);
Mockito.when(request.callback()).thenReturn(callback);
// Write should not succeed before negotiation completes
Assert.assertFalse(channel.writeOutbound(request));
Assert.assertFalse(channel.finish());
// Synchronously waiting for channel to close
channel.close().sync();
Mockito.verify(request).handle();
Mockito.verify(request).callback();
Mockito.verify(handle).dispose();
Mockito.verify(callback).onResponse(Mockito.any(TransportResponse.class));
}
use of io.netty.handler.ssl.SslContext in project rest.li by linkedin.
the class TestHttp2AlpnHandler method testWriteBeforeNegotiation.
@Test
public void testWriteBeforeNegotiation() throws Exception {
SslContext sslContext = Mockito.mock(SslContext.class);
Http2StreamCodec http2StreamCodec = Mockito.mock(Http2StreamCodec.class);
Http2AlpnHandler handler = new Http2AlpnHandler(sslContext, http2StreamCodec, true, Integer.MAX_VALUE);
EmbeddedChannel channel = new EmbeddedChannel(handler);
// Write should not succeed before negotiation completes
RequestWithCallback request = Mockito.mock(RequestWithCallback.class);
Assert.assertFalse(channel.writeOutbound(request));
Assert.assertFalse(channel.finish());
}
use of io.netty.handler.ssl.SslContext in project pravega by pravega.
the class TLSHelper method newServerSslContext.
/**
* Creates a new instance of {@link SslContext}.
*
* @param certificateFile the PEM-encoded server certificate file
* @param serverKeyFile the PEM-encoded file containing the server's encrypted private key
* @param tlsProtocolVersion version of TLS protocol
* @return a {@link SslContext} built from the specified {@code pathToCertificateFile} and {@code pathToServerKeyFile}
* @throws NullPointerException if either {@code certificateFile} or {@code serverKeyFile} is null
* @throws IllegalStateException if either {@code certificateFile} or {@code serverKeyFile} doesn't exist or is unreadable.
* @throws RuntimeException if there is a failure in building the {@link SslContext}
*/
public static SslContext newServerSslContext(File certificateFile, File serverKeyFile, String[] tlsProtocolVersion) {
Preconditions.checkNotNull(certificateFile);
Preconditions.checkNotNull(serverKeyFile);
Preconditions.checkNotNull(tlsProtocolVersion);
ensureExistAndAreReadable(certificateFile, serverKeyFile);
try {
SslContext result = SslContextBuilder.forServer(certificateFile, serverKeyFile).protocols(tlsProtocolVersion).build();
log.debug("Done creating a new SSL Context for the server.");
return result;
} catch (SSLException e) {
throw new RuntimeException(e);
}
}
use of io.netty.handler.ssl.SslContext in project pravega by pravega.
the class PravegaConnectionListenerTest method testUsesPollingMonitorForSymbolicLinks.
@Test
public void testUsesPollingMonitorForSymbolicLinks() {
String pathToCertificateFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_CERT_FILE_NAME;
String pathToKeyFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_FILE_NAME;
@Cleanup PravegaConnectionListener listener = new PravegaConnectionListener(true, true, "whatever", -1, mock(StreamSegmentStore.class), mock(TableStore.class), SegmentStatsRecorder.noOp(), TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), "dummy-tls-certificate-path", "dummy-tls-key-path", true, NoOpScheduledExecutor.get(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
AtomicReference<SslContext> dummySslCtx = new AtomicReference<>(null);
FileModificationMonitor monitor = listener.prepareCertificateMonitor(true, pathToCertificateFile, pathToKeyFile, dummySslCtx);
assertTrue("Unexpected type of FileModificationMonitor", monitor instanceof FileModificationPollingMonitor);
}
use of io.netty.handler.ssl.SslContext in project pravega by pravega.
the class PravegaConnectionListenerTest method testUsesEventWatcherForNonSymbolicLinks.
@Test
public void testUsesEventWatcherForNonSymbolicLinks() {
String pathToCertificateFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_CERT_FILE_NAME;
String pathToKeyFile = "../../../config/" + SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_FILE_NAME;
@Cleanup PravegaConnectionListener listener = new PravegaConnectionListener(true, true, "whatever", -1, mock(StreamSegmentStore.class), mock(TableStore.class), SegmentStatsRecorder.noOp(), TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), "dummy-tls-certificate-path", "dummy-tls-key-path", true, NoOpScheduledExecutor.get(), SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
AtomicReference<SslContext> dummySslCtx = new AtomicReference<>(null);
FileModificationMonitor monitor = listener.prepareCertificateMonitor(pathToCertificateFile, pathToKeyFile, dummySslCtx);
assertTrue("Unexpected type of FileModificationMonitor", monitor instanceof FileModificationEventWatcher);
}
Aggregations