|
92 | 92 |
|
93 | 93 | import static org.assertj.core.api.Assertions.assertThat; |
94 | 94 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 95 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
95 | 96 | import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
96 | 97 | import static org.junit.jupiter.api.Assertions.assertNotEquals; |
97 | 98 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
@@ -1908,6 +1909,77 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { |
1908 | 1909 | } |
1909 | 1910 | } |
1910 | 1911 |
|
| 1912 | + @ParameterizedTest |
| 1913 | + @MethodSource("newSslTaskExecutors") |
| 1914 | + public void testConnectFailsIfKeyManagerThrowsError(Executor executor) throws Throwable { |
| 1915 | + AtomicBoolean keyManagerCalled = new AtomicBoolean(); |
| 1916 | + X509ExtendedKeyManager keyManager = new X509ExtendedKeyManager() { |
| 1917 | + @Override |
| 1918 | + public String[] getClientAliases(String keyType, Principal[] issuers) { |
| 1919 | + return null; |
| 1920 | + } |
| 1921 | + |
| 1922 | + @Override |
| 1923 | + public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) { |
| 1924 | + return null; |
| 1925 | + } |
| 1926 | + |
| 1927 | + @Override |
| 1928 | + public String[] getServerAliases(String keyType, Principal[] issuers) { |
| 1929 | + return null; |
| 1930 | + } |
| 1931 | + |
| 1932 | + @Override |
| 1933 | + public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) { |
| 1934 | + return null; |
| 1935 | + } |
| 1936 | + |
| 1937 | + @Override |
| 1938 | + public String chooseEngineServerAlias(String keyType, Principal[] issuers, SSLEngine engine) { |
| 1939 | + keyManagerCalled.set(true); |
| 1940 | + // An Error (and not an Exception) must also fail the handshake and not stall it. |
| 1941 | + throw new NoClassDefFoundError("expected"); |
| 1942 | + } |
| 1943 | + |
| 1944 | + @Override |
| 1945 | + public X509Certificate[] getCertificateChain(String alias) { |
| 1946 | + throw new UnsupportedOperationException(); |
| 1947 | + } |
| 1948 | + |
| 1949 | + @Override |
| 1950 | + public PrivateKey getPrivateKey(String alias) { |
| 1951 | + throw new UnsupportedOperationException(); |
| 1952 | + } |
| 1953 | + }; |
| 1954 | + |
| 1955 | + Channel server = QuicTestUtils.newServer(QuicTestUtils.newQuicServerBuilder(executor, |
| 1956 | + QuicSslContextBuilder.forServer(keyManager, null) |
| 1957 | + .applicationProtocols(QuicTestUtils.PROTOS).clientAuth(ClientAuth.NONE).build()), |
| 1958 | + TestQuicTokenHandler.INSTANCE, new TestHandler(), |
| 1959 | + new TestHandler()); |
| 1960 | + InetSocketAddress address = (InetSocketAddress) server.localAddress(); |
| 1961 | + |
| 1962 | + Channel channel = QuicTestUtils.newClient(QuicTestUtils.newQuicClientBuilder(executor, |
| 1963 | + QuicSslContextBuilder.forClient() |
| 1964 | + .trustManager(InsecureTrustManagerFactory.INSTANCE) |
| 1965 | + .applicationProtocols(QuicTestUtils.PROTOS).build())); |
| 1966 | + try { |
| 1967 | + Future<QuicChannel> connectFuture = QuicTestUtils.newQuicChannelBootstrap(channel) |
| 1968 | + .handler(new TestHandler()) |
| 1969 | + .streamHandler(new TestHandler()) |
| 1970 | + .remoteAddress(address) |
| 1971 | + .connect().await(); |
| 1972 | + assertFalse(connectFuture.isSuccess()); |
| 1973 | + assertTrue(keyManagerCalled.get()); |
| 1974 | + } finally { |
| 1975 | + server.close().sync(); |
| 1976 | + // Close the parent Datagram channel as well. |
| 1977 | + channel.close().sync(); |
| 1978 | + |
| 1979 | + shutdown(executor); |
| 1980 | + } |
| 1981 | + } |
| 1982 | + |
1911 | 1983 | @ParameterizedTest |
1912 | 1984 | @MethodSource("newSslTaskExecutors") |
1913 | 1985 | public void testSessionTickets(Executor executor) throws Throwable { |
|