|
22 | 22 | import org.junit.After;
|
23 | 23 | import org.junit.Test;
|
24 | 24 |
|
| 25 | +import java.util.List; |
| 26 | +import javax.net.ssl.SNIHostName; |
| 27 | +import javax.net.ssl.SNIServerName; |
| 28 | +import javax.net.ssl.SSLEngine; |
| 29 | +import javax.net.ssl.SSLParameters; |
| 30 | + |
| 31 | +import org.neo4j.driver.internal.BoltServerAddress; |
25 | 32 | import org.neo4j.driver.internal.security.SecurityPlan;
|
26 | 33 | import org.neo4j.driver.internal.util.Clock;
|
27 | 34 | import org.neo4j.driver.internal.util.FakeClock;
|
28 | 35 |
|
| 36 | +import static org.hamcrest.Matchers.equalTo; |
| 37 | +import static org.hamcrest.Matchers.hasSize; |
| 38 | +import static org.hamcrest.Matchers.instanceOf; |
29 | 39 | import static org.junit.Assert.assertEquals;
|
30 | 40 | import static org.junit.Assert.assertNotNull;
|
31 | 41 | import static org.junit.Assert.assertNull;
|
| 42 | +import static org.junit.Assert.assertThat; |
32 | 43 | import static org.mockito.Mockito.mock;
|
33 | 44 | import static org.mockito.Mockito.when;
|
34 | 45 | import static org.neo4j.driver.internal.BoltServerAddress.LOCAL_DEFAULT;
|
@@ -98,6 +109,23 @@ public void shouldUpdateChannelAttributes()
|
98 | 109 | assertNotNull( messageDispatcher( channel ) );
|
99 | 110 | }
|
100 | 111 |
|
| 112 | + @Test |
| 113 | + public void shouldIncludeSniHostName() throws Exception |
| 114 | + { |
| 115 | + BoltServerAddress address = new BoltServerAddress( "database.neo4j.com", 8989 ); |
| 116 | + NettyChannelInitializer initializer = new NettyChannelInitializer( address, SecurityPlan.forAllCertificates(), 10000, Clock.SYSTEM, DEV_NULL_LOGGING ); |
| 117 | + |
| 118 | + initializer.initChannel( channel ); |
| 119 | + |
| 120 | + SslHandler sslHandler = channel.pipeline().get( SslHandler.class ); |
| 121 | + SSLEngine sslEngine = sslHandler.engine(); |
| 122 | + SSLParameters sslParameters = sslEngine.getSSLParameters(); |
| 123 | + List<SNIServerName> sniServerNames = sslParameters.getServerNames(); |
| 124 | + assertThat( sniServerNames, hasSize( 1 ) ); |
| 125 | + assertThat( sniServerNames.get( 0 ), instanceOf( SNIHostName.class ) ); |
| 126 | + assertThat( ((SNIHostName) sniServerNames.get( 0 )).getAsciiName(), equalTo( address.host() ) ); |
| 127 | + } |
| 128 | + |
101 | 129 | private static NettyChannelInitializer newInitializer( SecurityPlan securityPlan )
|
102 | 130 | {
|
103 | 131 | return newInitializer( securityPlan, Integer.MAX_VALUE );
|
|
0 commit comments