@Test void testValid1() throws UnknownHostException, URISyntaxException { URI actual = UriValidator.getSafeUri("ftp: URI expected = new URI("ftp: assertEquals(expected, actual); }
public static URI getSafeUri(String fileLocation) throws UnknownHostException, URISyntaxException { URI uri = new URI(fileLocation); InetAddress inetAddress = InetAddress.getByName(uri.getHost()); if (!uri.isAbsolute()) { throw new RelativePathNotAllowedException(); } if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress()) { throw new LocalhostNotAllowedException(); } return uri; }
UriValidator { public static URI getSafeUri(String fileLocation) throws UnknownHostException, URISyntaxException { URI uri = new URI(fileLocation); InetAddress inetAddress = InetAddress.getByName(uri.getHost()); if (!uri.isAbsolute()) { throw new RelativePathNotAllowedException(); } if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress()) { throw new LocalhostNotAllowedException(); } return uri; } }
UriValidator { public static URI getSafeUri(String fileLocation) throws UnknownHostException, URISyntaxException { URI uri = new URI(fileLocation); InetAddress inetAddress = InetAddress.getByName(uri.getHost()); if (!uri.isAbsolute()) { throw new RelativePathNotAllowedException(); } if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress()) { throw new LocalhostNotAllowedException(); } return uri; } private  UriValidator(); }
UriValidator { public static URI getSafeUri(String fileLocation) throws UnknownHostException, URISyntaxException { URI uri = new URI(fileLocation); InetAddress inetAddress = InetAddress.getByName(uri.getHost()); if (!uri.isAbsolute()) { throw new RelativePathNotAllowedException(); } if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress()) { throw new LocalhostNotAllowedException(); } return uri; } private  UriValidator(); static URI getSafeUri(String fileLocation); }
UriValidator { public static URI getSafeUri(String fileLocation) throws UnknownHostException, URISyntaxException { URI uri = new URI(fileLocation); InetAddress inetAddress = InetAddress.getByName(uri.getHost()); if (!uri.isAbsolute()) { throw new RelativePathNotAllowedException(); } if (inetAddress.isAnyLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isLinkLocalAddress()) { throw new LocalhostNotAllowedException(); } return uri; } private  UriValidator(); static URI getSafeUri(String fileLocation);  }