Skip to content

Commit

Permalink
UriBuilder IPv6 additional check
Browse files Browse the repository at this point in the history
  • Loading branch information
rsvoboda committed Oct 12, 2017
1 parent 7b3f9ce commit dbdd56b
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,51 @@ public void uriBuilderTest() throws Exception {

}

@Test
public void additionalCheckForIPv6() throws Exception {

Assert.assertEquals("http://0:0:0:0:0:0:0:1", UriBuilder.fromUri("http://0:0:0:0:0:0:0:1").build().toString());
Assert.assertEquals("http://::1", UriBuilder.fromUri("http://::1").build().toString());
Assert.assertEquals("http://0:0:0:0:0:0:0:1", UriBuilder.fromUri("http://{host}").build("0:0:0:0:0:0:0:1").toString());
//Assert.assertEquals("http://[0:0:0:0:0:0:0:1]:8080", UriBuilder.fromUri("http://{host}:8080").build("[0:0:0:0:0:0:0:1]").toString());

// inspiration from https://stackoverflow.com/a/17871737

Assert.assertEquals("http://1:2:3:4:5:6:7:8", UriBuilder.fromUri("http://1:2:3:4:5:6:7:8").build().toString());
Assert.assertEquals("http://1::", UriBuilder.fromUri("http://1::").build().toString());
Assert.assertEquals("http://1:2:3:4:5:6:7::", UriBuilder.fromUri("http://1:2:3:4:5:6:7::").build().toString());
Assert.assertEquals("http://1::8", UriBuilder.fromUri("http://1::8").build().toString());
Assert.assertEquals("http://1:2:3:4:5:6::8", UriBuilder.fromUri("http://1:2:3:4:5:6::8").build().toString());
Assert.assertEquals("http://1::7:8", UriBuilder.fromUri("http://1::7:8").build().toString());
Assert.assertEquals("http://1:2:3:4:5::7:8", UriBuilder.fromUri("http://1:2:3:4:5::7:8").build().toString());
Assert.assertEquals("http://1:2:3:4:5::8", UriBuilder.fromUri("http://1:2:3:4:5::8").build().toString());
Assert.assertEquals("http://1::6:7:8", UriBuilder.fromUri("http://1::6:7:8").build().toString());
Assert.assertEquals("http://1:2:3:4::6:7:8", UriBuilder.fromUri("http://1:2:3:4::6:7:8").build().toString());
Assert.assertEquals("http://1:2:3:4::8", UriBuilder.fromUri("http://1:2:3:4::8").build().toString());
Assert.assertEquals("http://1::5:6:7:8", UriBuilder.fromUri("http://1::5:6:7:8").build().toString());
Assert.assertEquals("http://1:2:3::5:6:7:8", UriBuilder.fromUri("http://1:2:3::5:6:7:8").build().toString());
Assert.assertEquals("http://1:2:3::8", UriBuilder.fromUri("http://1:2:3::8").build().toString());
Assert.assertEquals("http://1::4:5:6:7:8", UriBuilder.fromUri("http://1::4:5:6:7:8").build().toString());
Assert.assertEquals("http://1:2::4:5:6:7:8", UriBuilder.fromUri("http://1:2::4:5:6:7:8").build().toString());
Assert.assertEquals("http://1:2::8", UriBuilder.fromUri("http://1:2::8").build().toString());
Assert.assertEquals("http://1::3:4:5:6:7:8", UriBuilder.fromUri("http://1::3:4:5:6:7:8").build().toString());
Assert.assertEquals("http://1::8", UriBuilder.fromUri("http://1::8").build().toString());
Assert.assertEquals("http://::2:3:4:5:6:7:8", UriBuilder.fromUri("http://::2:3:4:5:6:7:8").build().toString());
Assert.assertEquals("http://::3:4:5:6:7:8", UriBuilder.fromUri("http://::3:4:5:6:7:8").build().toString());
Assert.assertEquals("http://::8", UriBuilder.fromUri("http://::8").build().toString());
Assert.assertEquals("http://::", UriBuilder.fromUri("http://::").build().toString());

//Assert.assertEquals("http://fe80::7:8%eth0", UriBuilder.fromUri("http://fe80::7:8%eth0").build().toString());
//Assert.assertEquals("http://fe80::7:8%1", UriBuilder.fromUri("http://fe80::7:8%1").build().toString());

Assert.assertEquals("http://::255.255.255.255", UriBuilder.fromUri("http://::255.255.255.255").build().toString());
Assert.assertEquals("http://::ffff:255.255.255.255", UriBuilder.fromUri("http://::ffff:255.255.255.255").build().toString());
Assert.assertEquals("http://::ffff:0:255.255.255.255", UriBuilder.fromUri("http://::ffff:0:255.255.255.255").build().toString());

Assert.assertEquals("http://2001:db8:3:4::192.0.2.33", UriBuilder.fromUri("http://2001:db8:3:4::192.0.2.33").build().toString());
Assert.assertEquals("http://64:ff9b::192.0.2.33", UriBuilder.fromUri("http://64:ff9b::192.0.2.33").build().toString());
}

public void printParse(String uri) {
logger.info("--- " + uri);
Matcher match = uriPattern.matcher(uri);
Expand Down

0 comments on commit dbdd56b

Please sign in to comment.