HappyEyeballsResolver implements SocketAddressResolver { Optional<String> isLiteralIpAddress(String host) { if (isLiteralV4Address(host)) return Optional.of(host); else if (host.contains(":")) { final Matcher matcher = IPV6_ADDRESS_PATTERN.matcher(host); if (matcher.matches()) return Optional.of(matcher.group(1)); } return Optional.empty(); } HappyEyeballsResolver(HttpClient httpClient); @Override void resolve(String host, int port, Promise<List<InetSocketAddress>> promise); static final long HAPPY_EYEBALLS_TOTAL_TIMEOUT_NANOS; }
@Test public void should_recognise_ipv4_literal() { assertThat(subject.isLiteralIpAddress("10.0.0.10")).hasValue("10.0.0.10"); assertThat(subject.isLiteralIpAddress("127.0.0.1")).hasValue("127.0.0.1"); assertThat(subject.isLiteralIpAddress("567.0.0.1")).hasValue("567.0.0.1"); }
@Test public void should_not_recognise_ipv4_literal() { assertThat(subject.isLiteralIpAddress(".10.0.0.24")).isEmpty(); assertThat(subject.isLiteralIpAddress("a10.0.0.24")).isEmpty(); assertThat(subject.isLiteralIpAddress("10.0.0.24.b")).isEmpty(); assertThat(subject.isLiteralIpAddress("10.0.0/24")).isEmpty(); assertThat(subject.isLiteralIpAddress("127")).isEmpty(); assertThat(subject.isLiteralIpAddress("")).isEmpty(); }
@Test public void should_recognise_ipv6_literal() { assertThat(subject.isLiteralIpAddress("db8::")).hasValue("db8::"); assertThat(subject.isLiteralIpAddress("::1")).hasValue("::1"); assertThat(subject.isLiteralIpAddress("0db8::1")).hasValue("0db8::1"); assertThat(subject.isLiteralIpAddress("Db8:db9:1")).hasValue("Db8:db9:1"); assertThat(subject.isLiteralIpAddress("dB8:db9::1%eth0")).hasValue("dB8:db9::1%eth0"); assertThat(subject.isLiteralIpAddress("fe80::b62e:99ff:fe46:41f2%en0")).hasValue("fe80::b62e:99ff:fe46:41f2%en0"); assertThat(subject.isLiteralIpAddress("::FFFF:192.168.1.250")).hasValue("::FFFF:192.168.1.250"); }
@Test public void should_not_recognise_ipv6_literal() { assertThat(subject.isLiteralIpAddress("dbg::")).isEmpty(); assertThat(subject.isLiteralIpAddress("db8:dead:beef::/26")).isEmpty(); assertThat(subject.isLiteralIpAddress("127")).isEmpty(); assertThat(subject.isLiteralIpAddress("")).isEmpty(); }