You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ma...@apache.org on 2022/08/25 09:42:17 UTC
[pulsar] branch branch-2.9 updated: [fix][broker] Avoid IllegalStateException while client_version is not set (#16788)
This is an automated email from the ASF dual-hosted git repository.
mattisonchao pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.9 by this push:
new b292591fba5 [fix][broker] Avoid IllegalStateException while client_version is not set (#16788)
b292591fba5 is described below
commit b292591fba5a60f0ce5f28f5517f36c908af0c5d
Author: Penghui Li <pe...@apache.org>
AuthorDate: Thu Jul 28 10:19:36 2022 +0800
[fix][broker] Avoid IllegalStateException while client_version is not set (#16788)
---
.../apache/pulsar/broker/service/ServerCnx.java | 4 +++-
.../pulsar/broker/service/ServerCnxTest.java | 23 ++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
index 02aa9e93c57..24cedf27277 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
@@ -19,6 +19,7 @@
package org.apache.pulsar.broker.service;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.pulsar.broker.admin.impl.PersistentTopicsBase.unsafeGetPartitionedTopicMetadataAsync;
import static org.apache.pulsar.broker.lookup.TopicLookupBase.lookupTopicAsync;
@@ -902,7 +903,8 @@ public class ServerCnx extends PulsarHandler implements TransportCnx {
try {
AuthData clientData = AuthData.of(authResponse.getResponse().getAuthData());
- doAuthentication(clientData, authResponse.getProtocolVersion(), authResponse.getClientVersion());
+ doAuthentication(clientData, authResponse.getProtocolVersion(),
+ authResponse.hasClientVersion() ? authResponse.getClientVersion() : EMPTY);
} catch (AuthenticationException e) {
service.getPulsarStats().recordConnectionCreateFail();
log.warn("[{}] Authentication failed: {} ", remoteAddress, e.getMessage());
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java
index be9ed72cd14..8edda7761c7 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java
@@ -23,11 +23,15 @@ import static org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMo
import static org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.matches;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
@@ -89,6 +93,7 @@ import org.apache.pulsar.common.api.proto.AuthMethod;
import org.apache.pulsar.common.api.proto.BaseCommand;
import org.apache.pulsar.common.api.proto.BaseCommand.Type;
import org.apache.pulsar.common.api.proto.CommandAck.AckType;
+import org.apache.pulsar.common.api.proto.CommandAuthResponse;
import org.apache.pulsar.common.api.proto.CommandConnected;
import org.apache.pulsar.common.api.proto.CommandError;
import org.apache.pulsar.common.api.proto.CommandLookupTopicResponse;
@@ -1956,4 +1961,22 @@ public class ServerCnxTest {
channel.finish();
}
}
+
+ @Test
+ public void testHandleAuthResponseWithoutClientVersion() {
+ ServerCnx cnx = mock(ServerCnx.class, CALLS_REAL_METHODS);
+ CommandAuthResponse authResponse = mock(CommandAuthResponse.class);
+ org.apache.pulsar.common.api.proto.AuthData authData = mock(org.apache.pulsar.common.api.proto.AuthData.class);
+ when(authResponse.getResponse()).thenReturn(authData);
+ when(authResponse.hasResponse()).thenReturn(true);
+ when(authResponse.getResponse().hasAuthMethodName()).thenReturn(true);
+ when(authResponse.getResponse().hasAuthData()).thenReturn(true);
+ when(authResponse.hasClientVersion()).thenReturn(false);
+ try {
+ cnx.handleAuthResponse(authResponse);
+ } catch (Exception ignore) {
+ }
+ verify(authResponse, times(1)).hasClientVersion();
+ verify(authResponse, times(0)).getClientVersion();
+ }
}