Github user revans2 commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/652#discussion_r221956355
--- 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 --
The IllegalArgumentException is coming from the `Boolean.parseBoolean`. If
it cannot understand the value as either true or false it will throw the
exception and we end up with it being true, the default. If you want a log I
am happy to add it, because "no" will be interpreted as true, which might be
confusing.
---