You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2023/03/18 15:07:28 UTC
[pulsar] branch branch-2.8 updated: [test] Fix ServerCnxTest failing after merge of #19830
This is an automated email from the ASF dual-hosted git repository.
mmarshall pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.8 by this push:
new d526211c1f1 [test] Fix ServerCnxTest failing after merge of #19830
d526211c1f1 is described below
commit d526211c1f1c34dcb301a30f1bf5b2e39cf1b839
Author: Michael Marshall <mm...@apache.org>
AuthorDate: Sat Mar 18 09:44:54 2023 -0500
[test] Fix ServerCnxTest failing after merge of #19830
The ServerCnxTest class is run as part of the flaky tests,
so https://github.com/apache/pulsar/pull/19830 was merged
without noticing that the changes didn't actually pass
tests. This commit fixes the test by changing the assertions
to ensure that "correct" combinations of roles and original
principals are verified.
(cherry picked from commit 13f4a0dc0a8df4a65d2f1006e5fb65ed1e671e0d)
---
.../pulsar/broker/service/ServerCnxTest.java | 37 ++++++++++++++--------
1 file changed, 23 insertions(+), 14 deletions(-)
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 8379ae5f67b..0179de5dc1e 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
@@ -607,8 +607,10 @@ public class ServerCnxTest {
channel.finish();
}
+ // This test is different in branch-2.11 and older because the behavior changes after branch-2.11.
+ // See https://github.com/apache/pulsar/pull/19830 for additional information.
@Test(timeOut = 30000)
- public void testConnectCommandWithInvalidRoleCombinations() throws Exception {
+ public void testConnectCommandWithDifferentRoleCombinations() throws Exception {
AuthenticationService authenticationService = mock(AuthenticationService.class);
AuthenticationProvider authenticationProvider = new MockAuthenticationProvider();
String authMethodName = authenticationProvider.getAuthMethodName();
@@ -621,19 +623,20 @@ public class ServerCnxTest {
svcConfig.setProxyRoles(Collections.singleton("pass.proxy"));
// Invalid combinations where authData is proxy role
- verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.proxy", "pass.proxy");
- verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.proxy", "");
- verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.proxy", null);
- // Invalid combinations where original principal is set to a pass.proxy role
- verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client", "pass.proxy");
- // Invalid combinations where the original principal is set to a non-proxy role
- verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client1", "pass.client");
- verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client", "pass.client");
- verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client", "pass.client1");
+ verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.proxy", "pass.proxy", false);
+ verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.proxy", "", false);
+ verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.proxy", null, false);
+ // Only considered valid because there is no requirement for that only a proxy role can pass
+ // an original principal
+ verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client", "pass.proxy", true);
+ verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client1", "pass.client", true);
+ verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client", "pass.client", true);
+ verifyAuthRoleAndOriginalPrincipalBehavior(authMethodName, "pass.client", "pass.client1", true);
}
private void verifyAuthRoleAndOriginalPrincipalBehavior(String authMethodName, String authData,
- String originalPrincipal) throws Exception {
+ String originalPrincipal,
+ boolean shouldPass) throws Exception {
resetChannel();
assertTrue(channel.isActive());
assertEquals(serverCnx.getState(), State.Start);
@@ -643,9 +646,15 @@ public class ServerCnxTest {
channel.writeInbound(clientCommand);
Object response = getResponse();
- assertTrue(response instanceof CommandError);
- assertEquals(((CommandError) response).getError(), ServerError.AuthorizationError);
- assertEquals(serverCnx.getState(), State.Failed);
+ if (shouldPass) {
+ assertTrue(response instanceof CommandConnected);
+ assertEquals(serverCnx.getState(), State.Connected);
+ assertTrue(serverCnx.isActive());
+ } else {
+ assertTrue(response instanceof CommandError);
+ assertEquals(((CommandError) response).getError(), ServerError.AuthorizationError);
+ assertEquals(serverCnx.getState(), State.Failed);
+ }
channel.finish();
}