@@ -67,7 +67,7 @@ public class AuthenticatorChainTests extends ESTestCase {
6767 private ServiceAccountAuthenticator serviceAccountAuthenticator ;
6868 private OAuth2TokenAuthenticator oAuth2TokenAuthenticator ;
6969 private ApiKeyAuthenticator apiKeyAuthenticator ;
70- private PluggableApiKeyAuthenticator customApiKeyAuthenticatorWrapper ;
70+ private PluggableApiKeyAuthenticator pluggableApiKeyAuthenticator ;
7171 private RealmsAuthenticator realmsAuthenticator ;
7272 private Authentication authentication ;
7373 private User fallbackUser ;
@@ -92,7 +92,7 @@ public void init() {
9292 oAuth2TokenAuthenticator = mock (OAuth2TokenAuthenticator .class );
9393 apiKeyAuthenticator = mock (ApiKeyAuthenticator .class );
9494 realmsAuthenticator = mock (RealmsAuthenticator .class );
95- customApiKeyAuthenticatorWrapper = mock (PluggableApiKeyAuthenticator .class );
95+ pluggableApiKeyAuthenticator = mock (PluggableApiKeyAuthenticator .class );
9696 when (realms .getActiveRealms ()).thenReturn (List .of (mock (Realm .class )));
9797 when (realms .getUnlicensedRealms ()).thenReturn (List .of ());
9898 final User user = new User (randomAlphaOfLength (8 ));
@@ -105,7 +105,7 @@ public void init() {
105105 authenticationContextSerializer ,
106106 serviceAccountAuthenticator ,
107107 oAuth2TokenAuthenticator ,
108- customApiKeyAuthenticatorWrapper ,
108+ pluggableApiKeyAuthenticator ,
109109 apiKeyAuthenticator ,
110110 realmsAuthenticator
111111 );
@@ -220,7 +220,13 @@ public void testAuthenticateWithApiKey() throws IOException {
220220 new ApiKeyCredentials (randomAlphaOfLength (20 ), apiKeySecret , randomFrom (ApiKey .Type .values ()))
221221 );
222222 doCallRealMethod ().when (serviceAccountAuthenticator ).authenticate (eq (context ), anyActionListener ());
223- doCallRealMethod ().when (customApiKeyAuthenticatorWrapper ).authenticate (eq (context ), anyActionListener ());
223+ doAnswer (invocationOnMock -> {
224+ @ SuppressWarnings ("unchecked" )
225+ final ActionListener <AuthenticationResult <Authentication >> listener = (ActionListener <
226+ AuthenticationResult <Authentication >>) invocationOnMock .getArguments ()[1 ];
227+ listener .onResponse (AuthenticationResult .notHandled ());
228+ return null ;
229+ }).when (pluggableApiKeyAuthenticator ).authenticate (eq (context ), any ());
224230 doCallRealMethod ().when (oAuth2TokenAuthenticator ).authenticate (eq (context ), anyActionListener ());
225231 }
226232 doAnswer (invocationOnMock -> {
@@ -263,7 +269,13 @@ public void testAuthenticateWithRealms() throws IOException {
263269 doCallRealMethod ().when (serviceAccountAuthenticator ).authenticate (eq (context ), anyActionListener ());
264270 doCallRealMethod ().when (oAuth2TokenAuthenticator ).authenticate (eq (context ), anyActionListener ());
265271 doCallRealMethod ().when (apiKeyAuthenticator ).authenticate (eq (context ), anyActionListener ());
266- doCallRealMethod ().when (customApiKeyAuthenticatorWrapper ).authenticate (eq (context ), anyActionListener ());
272+ doAnswer (invocationOnMock -> {
273+ @ SuppressWarnings ("unchecked" )
274+ final ActionListener <AuthenticationResult <Authentication >> listener = (ActionListener <
275+ AuthenticationResult <Authentication >>) invocationOnMock .getArguments ()[1 ];
276+ listener .onResponse (AuthenticationResult .notHandled ());
277+ return null ;
278+ }).when (pluggableApiKeyAuthenticator ).authenticate (eq (context ), any ());
267279 }
268280 doAnswer (invocationOnMock -> {
269281 @ SuppressWarnings ("unchecked" )
@@ -326,7 +338,14 @@ public void testContextWithDirectWrongTokenFailsAuthn() {
326338 doCallRealMethod ().when (serviceAccountAuthenticator ).authenticate (eq (context ), anyActionListener ());
327339 doCallRealMethod ().when (oAuth2TokenAuthenticator ).authenticate (eq (context ), anyActionListener ());
328340 doCallRealMethod ().when (apiKeyAuthenticator ).authenticate (eq (context ), anyActionListener ());
329- doCallRealMethod ().when (customApiKeyAuthenticatorWrapper ).authenticate (eq (context ), anyActionListener ());
341+ doAnswer (invocationOnMock -> {
342+ @ SuppressWarnings ("unchecked" )
343+ final ActionListener <AuthenticationResult <Authentication >> listener = (ActionListener <
344+ AuthenticationResult <Authentication >>) invocationOnMock .getArguments ()[1 ];
345+ listener .onResponse (AuthenticationResult .notHandled ());
346+ return null ;
347+ }).when (pluggableApiKeyAuthenticator ).authenticate (eq (context ), any ());
348+
330349 // 1. realms do not consume the token
331350 doAnswer (invocationOnMock -> {
332351 @ SuppressWarnings ("unchecked" )
0 commit comments