You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/05/19 23:12:39 UTC

[GitHub] [geode] kamilla1201 opened a new pull request #6502: GEODE-9290: LocalHostUtil.getMyAddresses should not return IPv4-mapped IPv6 addresses

kamilla1201 opened a new pull request #6502:
URL: https://github.com/apache/geode/pull/6502


   
   
   Thank you for submitting a contribution to Apache Geode.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   ### Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   


-- 
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:
users@infra.apache.org



[GitHub] [geode] onichols-pivotal commented on pull request #6502: GEODE-9290: LocalHostUtil.getMyAddresses should not return IPv4-mapped IPv6 addresses

Posted by GitBox <gi...@apache.org>.
onichols-pivotal commented on pull request #6502:
URL: https://github.com/apache/geode/pull/6502#issuecomment-917293066


   This PR has been untouched for several months, can it be closed?


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] agingade commented on a change in pull request #6502: GEODE-9290: LocalHostUtil.getMyAddresses should not return IPv4-mapped IPv6 addresses

Posted by GitBox <gi...@apache.org>.
agingade commented on a change in pull request #6502:
URL: https://github.com/apache/geode/pull/6502#discussion_r636477467



##########
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:
       The test seems to be passing the value and validating against the same value...I was thinking about case  where the input arg is different than the converted result and the result is as expected.
   E.g.: assertThat(LocalHostUtil.convertFromIPv4MappedAddress(ipv4CompatibleIpv6)).isEqualTo(ipv4Compatible);
   
   Please correct me if I am missing anything.




-- 
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:
users@infra.apache.org



[GitHub] [geode] kamilla1201 commented on a change in pull request #6502: GEODE-9290: LocalHostUtil.getMyAddresses should not return IPv4-mapped IPv6 addresses

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



[GitHub] [geode] kamilla1201 closed pull request #6502: GEODE-9290: LocalHostUtil.getMyAddresses should not return IPv4-mapped IPv6 addresses

Posted by GitBox <gi...@apache.org>.
kamilla1201 closed pull request #6502:
URL: https://github.com/apache/geode/pull/6502


   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org