This is an automated email from the ASF dual-hosted git repository. bschuchardt pushed a commit to branch support/1.13 in repository https://gitbox.apache.org/repos/asf/geode.git
commit 214fb5d6d19d7624e55811dcd16b16923a0027bd Author: Bruce Schuchardt <[email protected]> AuthorDate: Wed May 27 11:12:43 2020 -0700 Feature/geode 8144 (#5164) * modified SocketCreator to look for a hostname if one is not present and endpoint verification is enabled This fixes some problems when running in docker containers * removed test shell script * modified a test to use LocalHostUtil to get localhost * remove use of InetAddress.getLocalHost & add a sanIpAddress if there is no name for the localhost address (cherry picked from commit a185267dca016954f857f6848863bc4f74e6de81) --- .../apache/geode/admin/internal/InetAddressUtils.java | 9 +++++++++ .../GfshHostNameVerificationDistributedTest.java | 17 ++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/geode-core/src/main/java/org/apache/geode/admin/internal/InetAddressUtils.java b/geode-core/src/main/java/org/apache/geode/admin/internal/InetAddressUtils.java index ef24055..4609c1f 100644 --- a/geode-core/src/main/java/org/apache/geode/admin/internal/InetAddressUtils.java +++ b/geode-core/src/main/java/org/apache/geode/admin/internal/InetAddressUtils.java @@ -17,6 +17,8 @@ package org.apache.geode.admin.internal; import java.net.InetAddress; import java.net.UnknownHostException; +import org.apache.commons.validator.routines.InetAddressValidator; + import org.apache.geode.internal.inet.LocalHostUtil; /** @@ -31,6 +33,13 @@ public class InetAddressUtils { } /** + * Returns true if the given hostname is an IPv4 or IPv6 numeric address + */ + public static boolean isIPLiteral(String hostName) { + return InetAddressValidator.getInstance().isValid(hostName); + } + + /** * Returns a string version of {@code InetAddress} which can be converted back later. Essentially * any leading slash is trimmed. * diff --git a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/GfshHostNameVerificationDistributedTest.java b/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/GfshHostNameVerificationDistributedTest.java index f232748..4d5f40d 100644 --- a/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/GfshHostNameVerificationDistributedTest.java +++ b/geode-gfsh/src/distributedTest/java/org/apache/geode/management/internal/cli/commands/GfshHostNameVerificationDistributedTest.java @@ -29,9 +29,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.apache.geode.admin.internal.InetAddressUtils; import org.apache.geode.cache.ssl.CertStores; import org.apache.geode.cache.ssl.CertificateBuilder; import org.apache.geode.cache.ssl.CertificateMaterial; +import org.apache.geode.internal.inet.LocalHostUtil; import org.apache.geode.test.dunit.IgnoredException; import org.apache.geode.test.dunit.VM; import org.apache.geode.test.dunit.rules.ClusterStartupRule; @@ -60,14 +62,19 @@ public class GfshHostNameVerificationDistributedTest { .isCA() .generate(); - CertificateMaterial locatorCertificate = new CertificateBuilder() + String hostname = LocalHostUtil.getCanonicalLocalHostName(); + final CertificateBuilder builder = new CertificateBuilder() .commonName("locator") .issuedBy(ca) .sanDnsName(InetAddress.getLoopbackAddress().getHostName()) - .sanDnsName(InetAddress.getLocalHost().getHostName()) - .sanIpAddress(InetAddress.getLocalHost()) - .sanIpAddress(InetAddress.getByName("0.0.0.0")) // to pass on windows - .generate(); + .sanDnsName(hostname) + .sanIpAddress(InetAddress.getByName("0.0.0.0")); + if (InetAddressUtils.isIPLiteral(hostname)) { + // no valid hostname for this machine's IP address, so sanDnsName won't work + // and we need to use a sanIpAddress + builder.sanIpAddress(LocalHostUtil.getLocalHost()); + } + CertificateMaterial locatorCertificate = builder.generate(); CertificateMaterial gfshCertificate = new CertificateBuilder() .commonName("gfsh")
