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 12:55:41 GMT
Github user anmolnar commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/652#discussion_r221937931
  
    --- Diff: src/java/test/org/apache/zookeeper/ClientCanonicalizeTest.java ---
    @@ -0,0 +1,59 @@
    +/**
    + * 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.zookeeper;
    +
    +import java.io.IOException;
    +import org.apache.zookeeper.client.ZKClientConfig;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.mockito.Mockito.*;
    +
    +public class ClientCanonicalizeTest extends ZKTestCase {
    +    @Test
    +    public void testClientCanonicalization() throws IOException, InterruptedException
{
    +        ClientCnxn.MockableInetSocketAddress addr = mock(ClientCnxn.MockableInetSocketAddress.class);
    +        ClientCnxn.MockableInetAddress ia = mock(ClientCnxn.MockableInetAddress.class);
    +
    +        when(addr.getHostName()).thenReturn("zookeeper.apache.org");
    +        when(addr.getAddress()).thenReturn(ia);
    +        when(ia.getCanonicalHostName()).thenReturn("zk1.apache.org");
    +        when(ia.getHostAddress()).thenReturn("127.0.0.1");
    +
    +        ZKClientConfig conf = new ZKClientConfig();
    +        String principal = ClientCnxn.getServerPrincipal(addr, conf);
    +        Assert.assertEquals("zookeeper/zk1.apache.org", principal);
    +    }
    +
    +    @Test
    +    public void testClientNoCanonicalization() throws IOException, InterruptedException
{
    +        ClientCnxn.MockableInetSocketAddress addr = mock(ClientCnxn.MockableInetSocketAddress.class);
    +        ClientCnxn.MockableInetAddress ia = mock(ClientCnxn.MockableInetAddress.class);
    +
    +        when(addr.getHostName()).thenReturn("zookeeper.apache.org");
    +        when(addr.getAddress()).thenReturn(ia);
    +        when(ia.getCanonicalHostName()).thenReturn("zk1.apache.org");
    +        when(ia.getHostAddress()).thenReturn("127.0.0.1");
    +
    +        //when(addr.get)
    +        ZKClientConfig conf = new ZKClientConfig();
    +        conf.setProperty(ZKClientConfig.ZK_SASL_CLIENT_CANONICALIZE_HOSTNAME, "false");
    +        String principal = ClientCnxn.getServerPrincipal(addr, conf);
    +        Assert.assertEquals("zookeeper/zookeeper.apache.org", principal);
    --- End diff --
    
    Same here.


---

Mime
View raw message