ivankelly commented on a change in pull request #3677: PIP-30: interface and mutual change authentication URL: https://github.com/apache/pulsar/pull/3677#discussion_r264300225
########## File path: pulsar-broker/src/test/java/org/apache/pulsar/client/api/MutualAuthenticationTest.java ########## @@ -0,0 +1,232 @@ +/** + * 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.pulsar.client.api; + +import com.google.common.collect.Sets; +import java.io.IOException; +import java.net.SocketAddress; +import java.net.URI; +import java.nio.charset.Charset; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import javax.naming.AuthenticationException; +import javax.net.ssl.SSLSession; +import lombok.Getter; +import org.apache.pulsar.broker.ServiceConfiguration; +import org.apache.pulsar.broker.authentication.AuthenticationDataSource; +import org.apache.pulsar.broker.authentication.AuthenticationProvider; +import org.apache.pulsar.broker.authentication.AuthenticationState; +import org.apache.pulsar.common.api.AuthData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * Test Mutual Authentication. + * Test connect set success, and producer consumer works well. + */ +public class MutualAuthenticationTest extends ProducerConsumerBase { + private static final Logger log = LoggerFactory.getLogger(MutualAuthenticationTest.class); + + private MutualAuthentication mutualAuth; + + private static String[] clientAuthStrings = { + "MutualClientAuthInit", // step 0 + "MutualClientStep1" // step 1 + }; + + private static String[] serverAuthStrings = { + "ResponseMutualClientAuthInit", // step 0 + "ResponseMutualClientStep1" // step 1 + }; + + public static class MutualAuthenticationDataProvider implements AuthenticationDataProvider { + private int authStep = 0; + + @Override + public boolean hasDataFromCommand() { + return true; + } + + @Override + public AuthData authenticate(AuthData data) throws AuthenticationException { + String dataString = new String(data.getBytes(), Charset.forName("UTF-8")); Review comment: instead of depending on authStep here this would be easier to understand with something like. ``` if (Arrays.equals(data.getBytes(), INIT_CONSTANT)) { return AuthData.of(clientAuthStrings[0].getBytes(UTF_8)) } else if (Arrays.equals(data.getBytes(), serverAuthStrings[0].getBytes(UTF_8)) { return AuthData.of(clientAuthStrings[1].getBytes(UTF_8)); } else { throw AuthException; } ``` and similar for the server side. There are not enough roundtrips here to justify adding arithmetic into it. It's more important that it be clear what exactly is happening. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
