zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anmolnar <...@git.apache.org>
Subject [GitHub] zookeeper pull request #652: ZOOKEEPER-3156: Add in option to canonicalize h...
Date Tue, 02 Oct 2018 14:05:03 GMT
Github user anmolnar commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/652#discussion_r221963829
  
    --- Diff: src/java/main/org/apache/zookeeper/ClientCnxn.java ---
    @@ -793,7 +794,87 @@ public RWServerFoundException(String msg) {
                 super(msg);
             }
         }
    -    
    +
    +    static class MockableInetSocketAddress {
    +        private final InetSocketAddress addr;
    +
    +        MockableInetSocketAddress(InetSocketAddress addr) {
    +            this.addr = addr;
    +        }
    +
    +        public String getHostName() {
    +            return addr.getHostName();
    +        }
    +
    +        public MockableInetAddress getAddress() {
    +            InetAddress ia = addr.getAddress();
    +            return ia == null ? null : new MockableInetAddress(ia);
    +        }
    +
    +        @Override
    +        public String toString() {
    +            return addr.toString();
    +        }
    +    }
    +
    +    static class MockableInetAddress {
    +        private final InetAddress ia;
    +
    +        MockableInetAddress(InetAddress ia) {
    +            this.ia = ia;
    +        }
    +
    +        public String getCanonicalHostName() {
    +            return ia.getCanonicalHostName();
    +        }
    +
    +        public String getHostAddress() {
    +            return ia.getHostAddress();
    +        }
    +
    +        @Override
    +        public String toString() {
    +            return ia.toString();
    +        }
    +    }
    +    /**
    +     * Get the name of the server principal for a SASL client.  This is visible for testing
purposes.
    +     * @param addr the address of the host.
    +     * @param clientConfig the configuration for the client.
    +     * @return the name of the principal.
    +     */
    +    static String getServerPrincipal(MockableInetSocketAddress addr, ZKClientConfig clientConfig)
{
    +        String principalUserName = clientConfig.getProperty(ZKClientConfig.ZK_SASL_CLIENT_USERNAME,
    +            ZKClientConfig.ZK_SASL_CLIENT_USERNAME_DEFAULT);
    +        String hostName = addr.getHostName();
    +
    +        boolean canonicalize = true;
    +        try {
    +            canonicalize = Boolean.parseBoolean(clientConfig.getProperty(ZKClientConfig.ZK_SASL_CLIENT_CANONICALIZE_HOSTNAME,
    +                ZKClientConfig.ZK_SASL_CLIENT_CANONICALIZE_HOSTNAME_DEFAULT));
    +        } catch (IllegalArgumentException ea) {
    --- End diff --
    
    I don't see any of these methods (parseBoolean() and getProperty()) throw IllegalArgumentException,
so you don't need to catch here.
    
    In your original PR, you used System.getProperty() which throws it:
    https://github.com/apache/zookeeper/pull/648/files#diff-ae38c175a23a47be52ae31ed1f1518a3R781
    
    But this is master and we use ZKConfig here.


---

Mime
View raw message