Skip to content

Commit e53aa57

Browse files
authored
Merge pull request #229 from zhenlineo/1.5-ipv6
Added tests for ipv6 address parsing for routing procedure responses
2 parents aec6f57 + a7c3e32 commit e53aa57

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

Neo4j.Driver/Neo4j.Driver.Tests/Routing/ClusterDiscoveryManagerTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System;
1919
using System.Collections.Generic;
2020
using System.Linq;
21+
using System.Net;
2122
using FluentAssertions;
2223
using Moq;
2324
using Neo4j.Driver.Internal;
@@ -271,6 +272,37 @@ public void ShouldThrowExceptionIfReaderIsEmpty()
271272
}
272273
}
273274

275+
public class BoltRoutingUriMethod
276+
{
277+
[Theory]
278+
[InlineData("localhost", "localhost", GraphDatabase.DefaultBoltPort)]
279+
[InlineData("localhost:9193", "localhost", 9193)]
280+
[InlineData("neo4j.com", "neo4j.com", GraphDatabase.DefaultBoltPort)]
281+
[InlineData("royal-server.com.uk", "royal-server.com.uk", GraphDatabase.DefaultBoltPort)]
282+
[InlineData("royal-server.com.uk:4546", "royal-server.com.uk", 4546)]
283+
// IPv4
284+
[InlineData("127.0.0.1", "127.0.0.1", GraphDatabase.DefaultBoltPort)]
285+
[InlineData("8.8.8.8:8080", "8.8.8.8", 8080)]
286+
[InlineData("0.0.0.0", "0.0.0.0", GraphDatabase.DefaultBoltPort)]
287+
[InlineData("192.0.2.235:4329", "192.0.2.235", 4329)]
288+
[InlineData("172.31.255.255:255", "172.31.255.255", 255)]
289+
// IPv6
290+
[InlineData("[1afc:0:a33:85a3::ff2f]", "[1afc:0:a33:85a3::ff2f]", GraphDatabase.DefaultBoltPort)]
291+
[InlineData("[::1]:1515", "[::1]", 1515)]
292+
[InlineData("[ff0a::101]:8989", "[ff0a::101]", 8989)]
293+
// IPv6 with zone id
294+
[InlineData("[1afc:0:a33:85a3::ff2f%eth1]", "[1afc:0:a33:85a3::ff2f]", GraphDatabase.DefaultBoltPort)]
295+
[InlineData("[::1%eth0]:3030", "[::1]", 3030)]
296+
[InlineData("[ff0a::101%8]:4040", "[ff0a::101]", 4040)]
297+
public void ShouldHaveLocalhost(string input, string host, int port)
298+
{
299+
var uri = ClusterDiscoveryManager.BoltRoutingUri(input);
300+
uri.Scheme.Should().Be("bolt+routing");
301+
uri.Host.Should().Be(host);
302+
uri.Port.Should().Be(port);
303+
}
304+
}
305+
274306
internal static InitMessage InitMessage(IAuthToken auth = null)
275307
{
276308
auth = auth ?? AuthTokens.None;

Neo4j.Driver/Neo4j.Driver/Internal/Routing/ClusterDiscoveryManager.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,17 @@ private void ParseDiscoveryResult(IRecord record)
151151
ExpireAfterSeconds = record["ttl"].As<long>();
152152
}
153153

154-
private Uri BoltRoutingUri(string address)
154+
public static Uri BoltRoutingUri(string address)
155155
{
156-
return new Uri("bolt+routing://" + address);
156+
UriBuilder builder = new UriBuilder("bolt+routing://" + address);
157+
158+
// If scheme is not registered and no port is specified, then the port is assigned as -1
159+
if (builder.Port == -1)
160+
{
161+
builder.Port = GraphDatabase.DefaultBoltPort;
162+
}
163+
164+
return builder.Uri;
157165
}
158166

159167
private class SingleConnectionBasedConnectionProvider : IConnectionProvider
@@ -192,4 +200,4 @@ public Task CloseAsync()
192200
}
193201
}
194202
}
195-
}
203+
}

0 commit comments

Comments
 (0)