Skip to content

Commit 874a787

Browse files
committed
fix tests
1 parent 514eca0 commit 874a787

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/oidc/TransportOpenIdConnectLogoutActionTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.client.internal.Client;
2626
import org.elasticsearch.cluster.service.ClusterService;
2727
import org.elasticsearch.common.settings.Settings;
28+
import org.elasticsearch.common.util.concurrent.EsExecutors;
2829
import org.elasticsearch.common.util.concurrent.ThreadContext;
2930
import org.elasticsearch.core.Tuple;
3031
import org.elasticsearch.env.Environment;
@@ -105,6 +106,7 @@ public void setup() throws Exception {
105106
final var defaultContext = threadContext.newStoredContext();
106107
final ThreadPool threadPool = mock(ThreadPool.class);
107108
when(threadPool.getThreadContext()).thenReturn(threadContext);
109+
when(threadPool.generic()).thenReturn(EsExecutors.DIRECT_EXECUTOR_SERVICE);
108110
AuthenticationTestHelper.builder()
109111
.user(new User("kibana"))
110112
.realmRef(new Authentication.RealmRef("realm", "type", "node"))

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/AuthenticationServiceTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import java.util.Map;
123123
import java.util.Set;
124124
import java.util.concurrent.CountDownLatch;
125+
import java.util.concurrent.TimeUnit;
125126
import java.util.concurrent.atomic.AtomicBoolean;
126127
import java.util.function.Consumer;
127128

@@ -1940,6 +1941,7 @@ public void testAuthenticateWithToken() throws Exception {
19401941
when(projectIndex.isAvailable(SecurityIndexManager.Availability.PRIMARY_SHARDS)).thenReturn(true);
19411942
when(projectIndex.isAvailable(SecurityIndexManager.Availability.SEARCH_SHARDS)).thenReturn(true);
19421943
when(projectIndex.indexExists()).thenReturn(true);
1944+
CountDownLatch latch = new CountDownLatch(1);
19431945
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
19441946
threadContext.putHeader("Authorization", "Bearer " + token);
19451947
boolean requestIdAlreadyPresent = randomBoolean();
@@ -1962,8 +1964,10 @@ public void testAuthenticateWithToken() throws Exception {
19621964
verify(operatorPrivilegesService).maybeMarkOperatorUser(eq(result), eq(threadContext));
19631965
setCompletedToTrue(completed);
19641966
verify(auditTrail).authenticationSuccess(eq(reqId.get()), eq(result), eq("_action"), same(transportRequest));
1967+
latch.countDown();
19651968
}, this::logAndFail));
19661969
}
1970+
latch.await(1, TimeUnit.SECONDS);
19671971
assertTrue(completed.get());
19681972
verifyNoMoreInteractions(auditTrail);
19691973
}

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/support/SecondaryAuthenticatorTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
import java.util.List;
6969
import java.util.Map;
7070
import java.util.Set;
71+
import java.util.concurrent.CountDownLatch;
7172
import java.util.concurrent.ExecutionException;
73+
import java.util.concurrent.TimeUnit;
7274
import java.util.concurrent.atomic.AtomicReference;
7375
import java.util.function.Consumer;
7476

@@ -334,9 +336,12 @@ public void testAuthenticateUsingBearerToken() throws Exception {
334336
SecurityMocks.mockGetRequest(client, SecuritySystemIndices.SECURITY_TOKENS_ALIAS, tokenDocId.get(), tokenSource.get());
335337

336338
final TransportRequest request = AuthenticateRequest.INSTANCE;
339+
CountDownLatch latch = new CountDownLatch(1);
337340
final PlainActionFuture<SecondaryAuthentication> future = new PlainActionFuture<>();
341+
ActionListener.runAfter(future, latch::countDown);
338342
authenticator.authenticate(AuthenticateAction.NAME, request, future);
339343

344+
latch.await(1, TimeUnit.SECONDS);
340345
final SecondaryAuthentication secondaryAuthentication = future.result();
341346
assertThat(secondaryAuthentication, Matchers.notNullValue());
342347
assertThat(secondaryAuthentication.getAuthentication(), Matchers.notNullValue());

0 commit comments

Comments
 (0)