Protect Inet test against "helpful" DNS resolvers
Update `InetAddressFormatterTests` to ensure that DNS resolvers that return a "help" page for missing domains don't cause the build to fail. Closes gh-11897
This commit is contained in:
parent
70c0d6a005
commit
abe92eba2e
|
|
@ -52,7 +52,7 @@ public class InetAddressFormatterTests {
|
||||||
@Test
|
@Test
|
||||||
public void convertFromInetAddressToStringShouldConvert()
|
public void convertFromInetAddressToStringShouldConvert()
|
||||||
throws UnknownHostException {
|
throws UnknownHostException {
|
||||||
assumeResolves("example.com");
|
assumeResolves("example.com", true);
|
||||||
InetAddress address = InetAddress.getByName("example.com");
|
InetAddress address = InetAddress.getByName("example.com");
|
||||||
String converted = this.conversionService.convert(address, String.class);
|
String converted = this.conversionService.convert(address, String.class);
|
||||||
assertThat(converted).isEqualTo(address.getHostAddress());
|
assertThat(converted).isEqualTo(address.getHostAddress());
|
||||||
|
|
@ -60,7 +60,7 @@ public class InetAddressFormatterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertFromStringToInetAddressShouldConvert() {
|
public void convertFromStringToInetAddressShouldConvert() {
|
||||||
assumeResolves("example.com");
|
assumeResolves("example.com", true);
|
||||||
InetAddress converted = this.conversionService.convert("example.com",
|
InetAddress converted = this.conversionService.convert("example.com",
|
||||||
InetAddress.class);
|
InetAddress.class);
|
||||||
assertThat(converted.toString()).startsWith("example.com");
|
assertThat(converted.toString()).startsWith("example.com");
|
||||||
|
|
@ -68,16 +68,27 @@ public class InetAddressFormatterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertFromStringToInetAddressWhenHostDoesNotExistShouldThrowException() {
|
public void convertFromStringToInetAddressWhenHostDoesNotExistShouldThrowException() {
|
||||||
|
String missingDomain = "ireallydontexist.example.com";
|
||||||
|
assumeResolves(missingDomain, false);
|
||||||
this.thrown.expect(ConversionFailedException.class);
|
this.thrown.expect(ConversionFailedException.class);
|
||||||
this.conversionService.convert("ireallydontexist.example.com", InetAddress.class);
|
this.conversionService.convert(missingDomain, InetAddress.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assumeResolves(String host) {
|
private void assumeResolves(String host, boolean expectedToResolve) {
|
||||||
|
boolean resolved = isResolvable(host);
|
||||||
|
if (resolved != expectedToResolve) {
|
||||||
|
throw new AssumptionViolatedException(
|
||||||
|
"Host " + host + " resolved " + resolved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isResolvable(String host) {
|
||||||
try {
|
try {
|
||||||
InetAddress.getByName(host);
|
InetAddress.getByName(host);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (UnknownHostException ex) {
|
catch (UnknownHostException ex) {
|
||||||
throw new AssumptionViolatedException("Host " + host + " not resolvable", ex);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue