|
Expand Up
|
@@ -23,6 +23,9 @@ |
|
|
import io.netty.channel.embedded.EmbeddedChannel; |
|
|
import io.netty.channel.socket.ChannelInputShutdownEvent; |
|
|
import io.netty.handler.codec.DecoderException; |
|
|
import io.netty.util.AsyncMapping; |
|
|
import io.netty.util.concurrent.Future; |
|
|
import io.netty.util.concurrent.Promise; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.function.Executable; |
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
Expand All
|
@@ -35,10 +38,11 @@ |
|
|
import javax.net.ssl.SSLHandshakeException; |
|
|
import java.nio.channels.ClosedChannelException; |
|
|
import java.security.NoSuchAlgorithmException; |
|
|
import java.util.Arrays; |
|
|
import java.util.List; |
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
import java.util.stream.Stream; |
|
|
|
|
|
import static io.netty.handler.ssl.CloseNotifyTest.assertCloseNotify; |
|
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
|
Expand Down
Expand Up
|
@@ -82,11 +86,11 @@ |
|
|
|
|
|
@ParameterizedTest |
|
|
@ValueSource(booleans = {false, true}) |
|
|
public void testHandshakeFailure(boolean exceptionDuringEvent) { |
|
|
AtomicInteger failureCount = new AtomicInteger(); |
|
|
AtomicInteger failureCountOnExceptionReturn = new AtomicInteger(); |
|
|
AtomicInteger downstreamExceptionCount = new AtomicInteger(); |
|
|
AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
public void testHandshakeFailure(final boolean exceptionDuringEvent) { |
|
|
final AtomicInteger failureCount = new AtomicInteger(); |
|
|
final AtomicInteger failureCountOnExceptionReturn = new AtomicInteger(); |
|
|
final AtomicInteger downstreamExceptionCount = new AtomicInteger(); |
|
|
final AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
ChannelHandler alpnHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) { |
|
|
@Override |
|
|
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) { |
|
Expand All
|
@@ -106,8 +110,8 @@ |
|
|
} |
|
|
}; |
|
|
|
|
|
SSLHandshakeException exception = new SSLHandshakeException("error"); |
|
|
SslHandshakeCompletionEvent completionEvent = new SslHandshakeCompletionEvent(exception); |
|
|
final SSLHandshakeException exception = new SSLHandshakeException("error"); |
|
|
final SslHandshakeCompletionEvent completionEvent = new SslHandshakeCompletionEvent(exception); |
|
|
EmbeddedChannel channel = new EmbeddedChannel(alpnHandler, new ChannelInboundHandlerAdapter() { |
|
|
@Override |
|
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { |
|
Expand Down
Expand Up
|
@@ -140,10 +144,10 @@ |
|
|
|
|
|
@ParameterizedTest |
|
|
@MethodSource("handshakeFailureCauses") |
|
|
public void testHandshakeFailureEvent(Throwable cause) { |
|
|
AtomicReference<SslHandshakeCompletionEvent> eventRef = |
|
|
public void testHandshakeFailureEvent(final Throwable cause) { |
|
|
final AtomicReference<SslHandshakeCompletionEvent> eventRef = |
|
|
new AtomicReference<SslHandshakeCompletionEvent>(); |
|
|
AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
final AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
ChannelHandler alpnHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) { |
|
|
@Override |
|
|
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) { |
|
Expand All
|
@@ -164,7 +168,7 @@ |
|
|
} |
|
|
} |
|
|
}); |
|
|
SslHandshakeCompletionEvent completionEvent = new SslHandshakeCompletionEvent(cause); |
|
|
final SslHandshakeCompletionEvent completionEvent = new SslHandshakeCompletionEvent(cause); |
|
|
|
|
|
channel.pipeline().fireUserEventTriggered(completionEvent); |
|
|
|
|
Expand All
|
@@ -174,16 +178,16 @@ |
|
|
assertFalse(channel.finishAndReleaseAll()); |
|
|
} |
|
|
|
|
|
private static Stream<Arguments> handshakeFailureCauses() { |
|
|
return Stream.of( |
|
|
private static List<Arguments> handshakeFailureCauses() { |
|
|
return Arrays.asList( |
|
|
Arguments.of(new SslHandshakeTimeoutException("timed out")), |
Check failure
on line 183
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / Analyze (cpp)
error: static interface method invocations are not supported in -source 6
Check failure
on line 183
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / Analyze (cpp)
error: static interface method invocations are not supported in -source 6
Check failure
on line 183
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / verify-pr
error: static interface method invocations are not supported in -source 1.6
Check failure
on line 183
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / verify-pr
error: static interface method invocations are not supported in -source 1.6
Check failure
on line 183
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / Analyze (java)
error: static interface method invocations are not supported in -source 6
Check failure
on line 183
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / Analyze (java)
error: static interface method invocations are not supported in -source 6
|
|
|
Arguments.of(new ClosedChannelException())); |
Check failure
on line 184
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / verify-pr
error: static interface method invocations are not supported in -source 1.6
Check failure
on line 184
in handler/src/test/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandlerTest.java
View workflow job for this annotation
GitHub Actions / verify-pr
error: static interface method invocations are not supported in -source 1.6
|
|
|
} |
|
|
|
|
|
@Test |
|
|
public void testHandshakeFailureExceptionWithoutEvent() { |
|
|
AtomicInteger failureCount = new AtomicInteger(); |
|
|
AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
final AtomicInteger failureCount = new AtomicInteger(); |
|
|
final AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
ChannelHandler alpnHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) { |
|
|
@Override |
|
|
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) { |
|
Expand All
|
@@ -197,7 +201,7 @@ |
|
|
} |
|
|
}; |
|
|
EmbeddedChannel channel = new EmbeddedChannel(alpnHandler); |
|
|
SSLHandshakeException exception = new SSLHandshakeException("error"); |
|
|
final SSLHandshakeException exception = new SSLHandshakeException("error"); |
|
|
|
|
|
channel.pipeline().fireExceptionCaught(new DecoderException(exception)); |
|
|
|
|
Expand All
|
@@ -209,12 +213,12 @@ |
|
|
|
|
|
@Test |
|
|
public void testSniLookupFailure() { |
|
|
SSLHandshakeException exception = new SSLHandshakeException("SNI lookup failed"); |
|
|
AtomicInteger failureCount = new AtomicInteger(); |
|
|
AtomicInteger handshakeEventCount = new AtomicInteger(); |
|
|
AtomicInteger downstreamExceptionCount = new AtomicInteger(); |
|
|
AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
AtomicReference<SniCompletionEvent> sniEvent = new AtomicReference<SniCompletionEvent>(); |
|
|
final SSLHandshakeException exception = new SSLHandshakeException("SNI lookup failed"); |
|
|
final AtomicInteger failureCount = new AtomicInteger(); |
|
|
final AtomicInteger handshakeEventCount = new AtomicInteger(); |
|
|
final AtomicInteger downstreamExceptionCount = new AtomicInteger(); |
|
|
final AtomicReference<Throwable> failureCause = new AtomicReference<Throwable>(); |
|
|
final AtomicReference<SniCompletionEvent> sniEvent = new AtomicReference<SniCompletionEvent>(); |
|
|
ChannelHandler alpnHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) { |
|
|
@Override |
|
|
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) { |
|
Expand All
|
@@ -227,7 +231,12 @@ |
|
|
failureCause.set(cause); |
|
|
} |
|
|
}; |
|
|
SniHandler sniHandler = new SniHandler((hostname, promise) -> promise.setFailure(exception)); |
|
|
final SniHandler sniHandler = new SniHandler(new AsyncMapping<String, SslContext>() { |
|
|
@Override |
|
|
public Future<SslContext> map(String input, Promise<SslContext> promise) { |
|
|
return promise.setFailure(exception); |
|
|
} |
|
|
}); |
|
|
EmbeddedChannel channel = new EmbeddedChannel(sniHandler, alpnHandler, new ChannelInboundHandlerAdapter() { |
|
|
@Override |
|
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { |
|
Expand Down
|
|