Skip to content

Add support of IPv6 addresses #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public static BoltServerAddress from( URI uri )
{
port = DEFAULT_PORT;
}

if( uri.getHost() == null )
{
throw new IllegalArgumentException( "Invalid URI format `" + uri.toString() + "`");
}

return new BoltServerAddress( uri.getHost(), port );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.neo4j.driver.internal.net.BoltServerAddress.LOCAL_DEFAULT;
import static org.neo4j.driver.internal.util.Matchers.directDriverWithAddress;
import static org.neo4j.driver.v1.Values.parameters;
Expand All @@ -52,6 +53,38 @@ public void shouldUseDefaultPortIfMissing()
assertThat( driver, is( directDriverWithAddress( LOCAL_DEFAULT ) ) );
}

@Test
public void shouldAllowIPv6Address()
{
// Given
URI uri = URI.create( "bolt://[::1]" );
BoltServerAddress address = BoltServerAddress.from( uri );

// When
Driver driver = GraphDatabase.driver( uri );

// Then
assertThat( driver, is( directDriverWithAddress( address ) ) );
}

@Test
public void shouldRejectInvalidAddress()
{
// Given
URI uri = URI.create( "*" );

// When & Then
try
{
Driver driver = GraphDatabase.driver( uri );
fail("Expecting error for wrong uri");
}
catch( IllegalArgumentException e )
{
assertThat( e.getMessage(), equalTo( "Invalid URI format `*`" ) );
}
}

@Test
public void shouldRegisterSingleServer()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@

import org.neo4j.driver.v1.AccessMode;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.Transaction;
import org.neo4j.driver.v1.exceptions.ClientException;
import org.neo4j.driver.v1.exceptions.TransientException;
import org.neo4j.driver.v1.util.ServerVersion;
import org.neo4j.driver.v1.util.TestNeo4jSession;

import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -65,6 +68,21 @@ public void assumeBookmarkSupport()
assumeTrue( serverVersion.greaterThanOrEqual( v3_1_0 ) );
}

@Test
public void shouldConnectIPv6Uri()
{
// Given
try( Driver driver = GraphDatabase.driver( "bolt://[::1]:7687" );
Session session = driver.session() )
{
// When
StatementResult result = session.run( "RETURN 1" );

// Then
assertThat( result.single().get( 0 ).asInt(), equalTo( 1 ) );
}
}

@Test
public void shouldReceiveBookmarkOnSuccessfulCommit() throws Throwable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ private void createFakeServerCertPairInKnownCerts( BoltServerAddress address, Fi
public void shouldFailTLSHandshakeDueToServerCertNotSignedByKnownCA() throws Throwable
{
// Given
neo4j.restart(
Neo4jSettings.TEST_SETTINGS.updateWith(
neo4j.restart( Neo4jSettings.TEST_SETTINGS.updateWith(
Neo4jSettings.CERT_DIR,
folder.getRoot().getAbsolutePath().replace( "\\", "/" ) ) );
SocketChannel channel = SocketChannel.open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class Neo4jSettings
public static final String DATA_DIR = "dbms.directories.data";
public static final String CERT_DIR = "dbms.directories.certificates";
public static final String IMPORT_DIR = "dbms.directories.import";
public static final String LISTEN_ADDR = "dbms.connectors.default_listen_address"; // only valid for 3.1+
public static final String IPV6_ENABLED_ADDR = "::";

private static final String DEFAULT_IMPORT_DIR = "import";
private static final String DEFAULT_CERT_DIR = "certificates";
Expand All @@ -52,7 +54,8 @@ public class Neo4jSettings
CERT_DIR, DEFAULT_CERT_DIR,
DATA_DIR, DEFAULT_DATA_DIR,
IMPORT_DIR, DEFAULT_IMPORT_DIR,
AUTH_ENABLED, "false" ), Collections.<String>emptySet() );
AUTH_ENABLED, "false",
LISTEN_ADDR, IPV6_ENABLED_ADDR ), Collections.<String>emptySet() );

private Neo4jSettings( Map<String, String> settings, Set<String> excludes )
{
Expand Down