kamilla1201 commented on a change in pull request #6502:
URL: https://github.com/apache/geode/pull/6502#discussion_r636536765



##########
File path: 
geode-common/src/test/java/org/apache/geode/internal/inet/LocalHostUtilTest.java
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+
+package org.apache.geode.internal.inet;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.UnknownHostException;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+
+public class LocalHostUtilTest extends TestCase {
+
+  /**
+   * We cannot verify that {@link LocalHostUtil#convertFromIPv4MappedAddress}
+   * converts an IPv4-mapped address to an IPv4 address because it's not 
possible to create
+   * an IPv4-mapped Inet6Address instance. Methods that allow to create an 
InetAddress instance
+   * (i.e. {@link InetAddress#getByName(String)} or {@link 
InetAddress#getByAddress(byte[])})
+   * internally convert IPv4-mapped IPv6 address to an IPv4 address.
+   *
+   * This test verifies that if {@link NetworkInterface#getInetAddresses} 
returns an IPv4-mapped
+   * address, it will not be returned by {@link LocalHostUtil#getMyAddresses}.
+   */
+  @Test
+  public void testGetMyAddressesDoesNotReturnIPv4MappedAddresses() {
+    assertThat(LocalHostUtil.getMyAddresses())
+        .noneMatch(address -> 
LocalHostUtil.isIPv4MappedAddress(address.getAddress()));
+  }
+
+  @Test
+  public void 
testConvertFromIPv4MappedAddressReturnsOriginalAddressIfNotIPv4Mapped()
+      throws UnknownHostException {
+    InetAddress ipv4 = InetAddress.getByName("127.0.0.1");
+    InetAddress ipv6 = InetAddress.getByName("0:0:0:0:0:0:0:1");
+    InetAddress ipv4Compatible = InetAddress.getByName("::127.0.0.1");
+    assertThat(LocalHostUtil.convertFromIPv4MappedAddress(ipv4))
+        .isEqualTo(ipv4);
+    assertThat(LocalHostUtil.convertFromIPv4MappedAddress(ipv6))
+        .isEqualTo(ipv6);
+    assertThat(LocalHostUtil.convertFromIPv4MappedAddress(ipv4Compatible))

Review comment:
       @agingade you're right, there's no test that provides an IPv4-mapped 
address as an input because I couldn't find a way to create such an instance. 
Methods like InetAddress.getByName() and InetAddress.getByAddress() will 
automatically convert an IPv4-mapped address to an IPv4 address.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to