private void prepareAuthoritativeResourceData( final String name, final List<String> autNums, final List<String> ipv4Resources, final List<String> ipv6Resources) { final AuthoritativeResource authoritativeResource = mock(AuthoritativeResource.class); when(authoritativeResource.getAutNums()).thenReturn(ciSet(autNums)); final IntervalMap<Ipv4Resource, Ipv4Resource> ipv4Map = new NestedIntervalMap<>(); for (final String ipv4Resource : ipv4Resources) { final Ipv4Resource resource = Ipv4Resource.parse(ipv4Resource); ipv4Map.put(resource, resource); } when(authoritativeResource.getInetRanges()).thenReturn(ipv4Map); final IntervalMap<Ipv6Resource, Ipv6Resource> ipv6Map = new NestedIntervalMap<>(); for (final String ipv6Resource : ipv6Resources) { final Ipv6Resource resource = Ipv6Resource.parse(ipv6Resource); ipv6Map.put(resource, resource); } when(authoritativeResource.getInet6Ranges()).thenReturn(ipv6Map); when(authoritativeResourceData.getAuthoritativeResource(ciString(name))) .thenReturn(authoritativeResource); }
@Test public void valid_ipv6_trailing_dot() { final Domain domain = Domain.parse("0.0.0.0.8.f.7.0.1.0.0.2.ip6.arpa."); assertThat(domain.getValue(), is(ciString("0.0.0.0.8.f.7.0.1.0.0.2.ip6.arpa"))); assertThat((Ipv6Resource) domain.getReverseIp(), is(Ipv6Resource.parse("2001:7f8::/48"))); assertThat(domain.getType(), is(Domain.Type.IP6)); }
/** * Validate an IPv6 address * * @param yytext */ public static void validateIpv6(final String yytext) { try { Ipv6Resource.parse(yytext); } catch (IllegalArgumentException e) { syntaxError("IP address " + yytext + " contains an invalid quad"); } }
/** * check each quad of 1A:3:7:8:AAAA:BBBB:DEAD:BEEF/55 in prefix is valid * * @param yytext */ public static void validateIpv6Prefix(final String yytext) { final int slash = yytext.indexOf('/'); try { Ipv6Resource.parse(yytext.substring(0, slash)); } catch (IllegalArgumentException e) { syntaxError("IPv6 prefix " + yytext + " contains an invalid quad"); } final int length = Integer.valueOf(yytext.substring(slash + 1)); if (length > MAX_BIT_LENGTH_IPV6) { syntaxError("IPv6 prefix " + yytext + " contains an invalid prefix length"); } }
/** * check IPv6 address and prefix range is valid * * @param yytext */ public static void validateIpv6PrefixRange(final String yytext) { Matcher m = ADDRESS_PREFIX_RANGE_PATTERN.matcher(yytext); if (m.matches()) { try { Ipv6Resource.parse(m.group(1)); } catch (IllegalArgumentException e) { syntaxError("IP prefix " + yytext + " contains an invalid quad"); } int prefix = Integer.valueOf(m.group(2)); if (prefix > MAX_BIT_LENGTH_IPV6) { syntaxError("IP prefix range " + yytext + " contains an invalid prefix length"); } String fromString = m.group(3); int from = 0; if (fromString != null) { from = Integer.valueOf(fromString); if (from > MAX_BIT_LENGTH_IPV6) { syntaxError("IP prefix range " + yytext + " contains an invalid range"); } } String toString = m.group(4); if (toString != null) { int to = Integer.valueOf(toString); if (to > MAX_BIT_LENGTH_IPV6) { syntaxError("IP prefix range " + yytext + " contains an invalid range"); } if (to < from) { syntaxError("IP prefix " + yytext + " range end is less than range start"); } } } }