Skip to content

Commit 85315b6

Browse files
authored
Merge pull request #498 from lutovich/1.6-sni-test
Added unit test for SNI in encrypted connections
2 parents 1cf40b7 + 72b0b6a commit 85315b6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

driver/src/test/java/org/neo4j/driver/internal/async/NettyChannelInitializerTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,24 @@
2222
import org.junit.After;
2323
import org.junit.Test;
2424

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;
2532
import org.neo4j.driver.internal.security.SecurityPlan;
2633
import org.neo4j.driver.internal.util.Clock;
2734
import org.neo4j.driver.internal.util.FakeClock;
2835

36+
import static org.hamcrest.Matchers.equalTo;
37+
import static org.hamcrest.Matchers.hasSize;
38+
import static org.hamcrest.Matchers.instanceOf;
2939
import static org.junit.Assert.assertEquals;
3040
import static org.junit.Assert.assertNotNull;
3141
import static org.junit.Assert.assertNull;
42+
import static org.junit.Assert.assertThat;
3243
import static org.mockito.Mockito.mock;
3344
import static org.mockito.Mockito.when;
3445
import static org.neo4j.driver.internal.BoltServerAddress.LOCAL_DEFAULT;
@@ -98,6 +109,23 @@ public void shouldUpdateChannelAttributes()
98109
assertNotNull( messageDispatcher( channel ) );
99110
}
100111

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+
101129
private static NettyChannelInitializer newInitializer( SecurityPlan securityPlan )
102130
{
103131
return newInitializer( securityPlan, Integer.MAX_VALUE );

0 commit comments

Comments
 (0)