Skip to content

Commit

Permalink
fixing TransportOpenIdConnectLogoutActionTests
Browse files Browse the repository at this point in the history
  • Loading branch information
masseyke committed Dec 4, 2023
1 parent 2847f7e commit d1c6e19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public void setup() throws Exception {
}).when(client).bulk(any(BulkRequest.class), anyActionListener());

final SecurityIndexManager securityIndex = mock(SecurityIndexManager.class);
doAnswer(inv -> {
((Runnable) inv.getArguments()[1]).run();
((Runnable) inv.getArguments()[2]).run();
return null;
}).when(securityIndex).prepareIndexIfNeededThenExecute(anyConsumer(), any(Runnable.class), any(Runnable.class));
doAnswer(inv -> {
((Runnable) inv.getArguments()[1]).run();
return null;
Expand Down Expand Up @@ -223,16 +228,15 @@ public void testLogoutInvalidatesTokens() throws Exception {
tokenMetadata.put("id_token_hint", signedIdToken.serialize());
tokenMetadata.put("oidc_realm", REALM_NAME);
final Authentication authentication = Authentication.newRealmAuthentication(user, realmRef);

final PlainActionFuture<TokenService.CreateTokenResult> future = new PlainActionFuture<>();
Tuple<byte[], byte[]> newTokenBytes = tokenService.getRandomTokenBytes(randomBoolean());
tokenService.createOAuth2Tokens(newTokenBytes.v1(), newTokenBytes.v2(), authentication, authentication, tokenMetadata, future);
final String accessToken = future.actionGet().getAccessToken();

mockGetTokenFromAccessTokenBytes(tokenService, newTokenBytes.v1(), authentication, tokenMetadata, false, null, client);

final OpenIdConnectLogoutRequest request = new OpenIdConnectLogoutRequest();
request.setToken(accessToken);

final PlainActionFuture<OpenIdConnectLogoutResponse> listener = new PlainActionFuture<>();
action.doExecute(mock(Task.class), request, listener);
final OpenIdConnectLogoutResponse response = listener.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public static SecurityIndexManager mockSecurityIndexManager(String alias, boolea
onCompletion.run();
return null;
}).when(securityIndexManager).prepareIndexIfNeededThenExecute(anyConsumer(), any(Runnable.class), any(Runnable.class));
doAnswer(invocationOnMock -> {
Runnable runnable = (Runnable) invocationOnMock.getArguments()[1];
runnable.run();
Runnable onCompletion = (Runnable) invocationOnMock.getArguments()[2];
onCompletion.run();
return null;
}).when(securityIndexManager).prepareIndexIfNeededThenExecute(anyConsumer(), any(Runnable.class), any(Runnable.class));
doAnswer(invocationOnMock -> {
Runnable runnable = (Runnable) invocationOnMock.getArguments()[1];
runnable.run();
Expand Down

0 comments on commit d1c6e19

Please sign in to comment.