|
76 | 76 | import org.apache.pulsar.broker.PulsarService;
|
77 | 77 | import org.apache.pulsar.broker.ServiceConfiguration;
|
78 | 78 | import org.apache.pulsar.broker.auth.MockAlwaysExpiredAuthenticationProvider;
|
| 79 | +import org.apache.pulsar.broker.auth.MockMutableAuthenticationProvider; |
79 | 80 | import org.apache.pulsar.broker.authentication.AuthenticationDataSubscription;
|
80 | 81 | import org.apache.pulsar.broker.auth.MockAuthenticationProvider;
|
81 | 82 | import org.apache.pulsar.broker.auth.MockMultiStageAuthenticationProvider;
|
@@ -1040,6 +1041,54 @@ public void testVerifyAuthRoleAndAuthDataFromDirectConnectionBroker() throws Exc
|
1040 | 1041 | }));
|
1041 | 1042 | }
|
1042 | 1043 |
|
| 1044 | + @Test |
| 1045 | + public void testRefreshOriginalPrincipalWithAuthDataForwardedFromProxy() throws Exception { |
| 1046 | + AuthenticationService authenticationService = mock(AuthenticationService.class); |
| 1047 | + AuthenticationProvider authenticationProvider = new MockMutableAuthenticationProvider(); |
| 1048 | + String authMethodName = authenticationProvider.getAuthMethodName(); |
| 1049 | + when(brokerService.getAuthenticationService()).thenReturn(authenticationService); |
| 1050 | + when(authenticationService.getAuthenticationProvider(authMethodName)).thenReturn(authenticationProvider); |
| 1051 | + svcConfig.setAuthenticationEnabled(true); |
| 1052 | + svcConfig.setAuthenticateOriginalAuthData(true); |
| 1053 | + svcConfig.setProxyRoles(Collections.singleton("pass.proxy")); |
| 1054 | + |
| 1055 | + resetChannel(); |
| 1056 | + assertTrue(channel.isActive()); |
| 1057 | + assertEquals(serverCnx.getState(), State.Start); |
| 1058 | + |
| 1059 | + String proxyRole = "pass.proxy"; |
| 1060 | + String clientRole = "pass.client"; |
| 1061 | + ByteBuf connect = Commands.newConnect(authMethodName, proxyRole, "test", "localhost", |
| 1062 | + clientRole, clientRole, authMethodName); |
| 1063 | + channel.writeInbound(connect); |
| 1064 | + Object connectResponse = getResponse(); |
| 1065 | + assertTrue(connectResponse instanceof CommandConnected); |
| 1066 | + assertEquals(serverCnx.getOriginalAuthData().getCommandData(), clientRole); |
| 1067 | + assertEquals(serverCnx.getOriginalAuthState().getAuthRole(), clientRole); |
| 1068 | + assertEquals(serverCnx.getOriginalPrincipal(), clientRole); |
| 1069 | + assertEquals(serverCnx.getAuthData().getCommandData(), proxyRole); |
| 1070 | + assertEquals(serverCnx.getAuthRole(), proxyRole); |
| 1071 | + assertEquals(serverCnx.getAuthState().getAuthRole(), proxyRole); |
| 1072 | + |
| 1073 | + // Request refreshing the original auth. |
| 1074 | + // Expected: |
| 1075 | + // 1. Original role and original data equals to "pass.RefreshOriginAuthData". |
| 1076 | + // 2. The broker disconnects the client, because the new role doesn't equal the old role. |
| 1077 | + String newClientRole = "pass.RefreshOriginAuthData"; |
| 1078 | + ByteBuf refreshAuth = Commands.newAuthResponse(authMethodName, |
| 1079 | + AuthData.of(newClientRole.getBytes(StandardCharsets.UTF_8)), 0, "test"); |
| 1080 | + channel.writeInbound(refreshAuth); |
| 1081 | + |
| 1082 | + assertEquals(serverCnx.getOriginalAuthData().getCommandData(), newClientRole); |
| 1083 | + assertEquals(serverCnx.getOriginalAuthState().getAuthRole(), newClientRole); |
| 1084 | + assertEquals(serverCnx.getAuthData().getCommandData(), proxyRole); |
| 1085 | + assertEquals(serverCnx.getAuthRole(), proxyRole); |
| 1086 | + assertEquals(serverCnx.getAuthState().getAuthRole(), proxyRole); |
| 1087 | + |
| 1088 | + assertFalse(channel.isOpen()); |
| 1089 | + assertFalse(channel.isActive()); |
| 1090 | + } |
| 1091 | + |
1043 | 1092 | @Test(timeOut = 30000)
|
1044 | 1093 | public void testProducerCommand() throws Exception {
|
1045 | 1094 | resetChannel();
|
|
0 commit comments