mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Test: fix AuthenticationService tests timeouts due to incorrect stream sizes
The AuthenticationService#testInvalidToken would cause a suite timeout in the case of an exception due to a incorrect stream size as the latch was never counted down. This fixes the missing latch countdown. relates elastic/x-pack-elasticsearch#2615 Original commit: elastic/x-pack-elasticsearch@e838e6e912
This commit is contained in:
parent
6099660643
commit
7b8d92a2a7
@ -830,6 +830,7 @@ public class AuthenticationServiceTests extends ESTestCase {
|
|||||||
random().nextBytes(randomBytes);
|
random().nextBytes(randomBytes);
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
final Authentication expected = new Authentication(user, new RealmRef(firstRealm.name(), firstRealm.type(), "authc_test"), null);
|
final Authentication expected = new Authentication(user, new RealmRef(firstRealm.name(), firstRealm.type(), "authc_test"), null);
|
||||||
|
AtomicBoolean success = new AtomicBoolean(false);
|
||||||
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
|
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
|
||||||
threadContext.putHeader("Authorization", "Bearer " + Base64.getEncoder().encodeToString(randomBytes));
|
threadContext.putHeader("Authorization", "Bearer " + Base64.getEncoder().encodeToString(randomBytes));
|
||||||
service.authenticate("_action", message, null, ActionListener.wrap(result -> {
|
service.authenticate("_action", message, null, ActionListener.wrap(result -> {
|
||||||
@ -839,18 +840,22 @@ public class AuthenticationServiceTests extends ESTestCase {
|
|||||||
assertThat(result.getAuthenticatedBy(), is(notNullValue()));
|
assertThat(result.getAuthenticatedBy(), is(notNullValue()));
|
||||||
assertThreadContextContainsAuthentication(result);
|
assertThreadContextContainsAuthentication(result);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
success.set(true);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}, this::logAndFail));
|
}, this::logAndFail));
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
assertThat(ex.getMessage(), containsString("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: "));
|
assertThat(ex.getMessage(), containsString("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: "));
|
||||||
|
latch.countDown();
|
||||||
} catch (NegativeArraySizeException ex) {
|
} catch (NegativeArraySizeException ex) {
|
||||||
assertThat(ex.getMessage(), containsString("array size must be positive but was: "));
|
assertThat(ex.getMessage(), containsString("array size must be positive but was: "));
|
||||||
|
latch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to use a latch here because the key computation goes async on another thread!
|
// we need to use a latch here because the key computation goes async on another thread!
|
||||||
latch.await();
|
latch.await();
|
||||||
verify(auditTrail).authenticationSuccess(firstRealm.name(), user, "_action", message);
|
if (success.get()) {
|
||||||
|
verify(auditTrail).authenticationSuccess(firstRealm.name(), user, "_action", message);
|
||||||
|
}
|
||||||
verifyNoMoreInteractions(auditTrail);
|
verifyNoMoreInteractions(auditTrail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user