@@ -315,6 +315,45 @@ public void testDataEncryptionIsActuallyEnabled() throws Exception {
315315 }
316316 }
317317
318+ @ Test
319+ public void testClientIdBoundAfter () throws Exception {
320+ TransportConf conf = new TransportConf ("shuffle" , MapConfigProvider .EMPTY );
321+ SecretKeyHolder keyHolder = mock (SecretKeyHolder .class );
322+ when (keyHolder .getSaslUser (anyString ())).thenReturn ("user" );
323+ when (keyHolder .getSecretKey (anyString ())).thenReturn ("secret" );
324+ TransportClient client = mock (TransportClient .class );
325+ SaslRpcHandler handler = new SaslRpcHandler (conf , null , null , keyHolder );
326+ SparkSaslClient saslClient = new SparkSaslClient ("app-1" , keyHolder , false );
327+ try {
328+ byte [] clientToken = saslClient .firstToken ();
329+ boolean authenticated = false ;
330+ for (int i = 0 ; i < 10 && !authenticated ; i ++) {
331+ SaslMessage msg = new SaslMessage ("app-1" , clientToken );
332+ ByteBuf buf = Unpooled .buffer (msg .encodedLength () + clientToken .length );
333+ msg .encode (buf );
334+ buf .writeBytes (msg .body ().nioByteBuffer ());
335+
336+ AtomicReference <ByteBuffer > response = new AtomicReference <>();
337+ RpcResponseCallback callback = mock (RpcResponseCallback .class );
338+ doAnswer (invocation -> {
339+ response .set ((ByteBuffer ) invocation .getArguments ()[0 ]);
340+ return null ;
341+ }).when (callback ).onSuccess (any (ByteBuffer .class ));
342+
343+ authenticated = handler .doAuthChallenge (client , buf .nioBuffer (), callback );
344+ if (!authenticated ) {
345+ // No client ID set since we did not finish the challenge.
346+ verify (client , never ()).setClientId (anyString ());
347+ clientToken = saslClient .response (JavaUtils .bufferToArray (response .get ()));
348+ }
349+ }
350+ assertTrue (authenticated );
351+ verify (client ).setClientId ("app-1" );
352+ } finally {
353+ saslClient .dispose ();
354+ }
355+ }
356+
318357 @ Test
319358 public void testRpcHandlerDelegate () throws Exception {
320359 // Tests all delegates exception for receive(), which is more complicated and already handled
0 commit comments