joseluisll commented on code in PR #8807:
URL: https://github.com/apache/hadoop/pull/8807#discussion_r4234113131


##########
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestDNS.java:
##########
@@ -185,6 +186,29 @@ public void testRDNS() throws Exception {
     }
   }
 
+  /**
+   * Test the reverse lookup names built for IPv4 and IPv6 addresses.
+   */
+  @Test
+  public void testReverseDnsName() throws Exception {
+    assertThat(DNS.getReverseDnsName(InetAddress.getByName("192.0.2.129")))
+        .isEqualTo("129.2.0.192.in-addr.arpa");
+    // The example from RFC 3596 section 2.5
+    
assertThat(DNS.getReverseDnsName(InetAddress.getByName("4321:0:1:2:3:4:567:89ab")))
+        
.isEqualTo("b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.arpa");
+    assertThat(DNS.getReverseDnsName(InetAddress.getByName("2001:db8::1")))
+        
.isEqualTo("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa");
+    assertThat(DNS.getReverseDnsName(InetAddress.getByName("::1")))
+        
.isEqualTo("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa");
+    // The JDK resolves an IPv4-mapped address to an Inet4Address
+    
assertThat(DNS.getReverseDnsName(InetAddress.getByName("::ffff:192.0.2.129")))
+        .isEqualTo("129.2.0.192.in-addr.arpa");
+    // The scope id is not part of the name
+    byte[] linkLocal = InetAddress.getByName("fe80::1").getAddress();
+    assertThat(DNS.getReverseDnsName(Inet6Address.getByAddress(null, 
linkLocal, 5)))
+        
.isEqualTo("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa");
+  }

Review Comment:
   Optional suggestion: `testReverseDnsName` covers how the name is built, but 
nothing tests the bug the PR fixes: `reverseDns` throwing a `RuntimeException` 
that `getHosts` doesn't catch (it only catches `NamingException`). A test 
through the public method would guard that, and it reuses `INVALID_DNS_SERVER`, 
so it doesn't need a real DNS server:
   
   ```java
     /**
      * Test that the reverse lookup of an IPv6 address fails with a
      * NamingException, which DNS#getHosts handles, when no DNS server answers.
      */
     @Test
     public void testReverseDnsIPv6WithInvalidServer() throws Exception {
       assertThrows(NamingException.class,
           () -> DNS.reverseDns(InetAddress.getByName("2001:db8::1"), 
INVALID_DNS_SERVER));
     }
   ```
   
   It needs `import javax.naming.NamingException;` and `import static 
org.junit.jupiter.api.Assertions.assertThrows;`.
   
   I ran it locally: it passes on this branch (all 14 `TestDNS` tests green) 
and fails on trunk with `expected NamingException but was 
ArrayIndexOutOfBoundsException`.



-- 
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: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to