gaoran10 commented on code in PR #20713:
URL: https://github.com/apache/pulsar/pull/20713#discussion_r1268297039


##########
pulsar-broker-auth-sasl/src/test/java/org/apache/pulsar/broker/authentication/SaslAuthenticateTest.java:
##########
@@ -295,4 +301,52 @@ public void testSaslServerAndClientAuth() throws Exception 
{
         log.info("-- {} -- end", methodName);
     }
 
+    @Test
+    public void testSaslOnlyAuthFirstStage() throws Exception {
+        AuthenticationProviderSasl saslServer = (AuthenticationProviderSasl) 
pulsar.getBrokerService()
+                
.getAuthenticationService().getAuthenticationProvider(SaslConstants.AUTH_METHOD_NAME);
+
+        HttpServletRequest servletRequest = mock(HttpServletRequest.class);
+        doReturn("Init").when(servletRequest).getHeader("State");
+        // 10 clients only do one-stage verification, resulting in 10 auth 
info remaining in memory
+        for (int i = 0; i < 10; i++) {
+            AuthenticationDataProvider dataProvider =  
authSasl.getAuthData("localhost");
+            AuthData initData1 = 
dataProvider.authenticate(AuthData.INIT_AUTH_DATA);
+            
doReturn(Base64.getEncoder().encodeToString(initData1.getBytes())).when(
+                    servletRequest).getHeader("SASL-Token");
+            
doReturn(String.valueOf(i)).when(servletRequest).getHeader("SASL-Server-ID");
+            saslServer.authenticateHttpRequest(servletRequest, 
mock(HttpServletResponse.class));
+        }
+        Field field = 
AuthenticationProviderSasl.class.getDeclaredField("authStates");
+        field.setAccessible(true);
+        Cache<Long, AuthenticationState> cache = (Cache<Long, 
AuthenticationState>) field.get(saslServer);
+        assertEquals(cache.asMap().size(), 10);
+        // The cache expiration time is set to 1ms. Residual auth info should 
be cleaned up
+        Properties properties = new Properties();
+        properties.setProperty("authentication_sasl_prefix", "1");

Review Comment:
   Sorry, I'm not clear about this configuration, maybe 
`inflightSaslContextExpiryMs`?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to