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);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
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()) {
|
||||
threadContext.putHeader("Authorization", "Bearer " + Base64.getEncoder().encodeToString(randomBytes));
|
||||
service.authenticate("_action", message, null, ActionListener.wrap(result -> {
|
||||
|
@ -839,18 +840,22 @@ public class AuthenticationServiceTests extends ESTestCase {
|
|||
assertThat(result.getAuthenticatedBy(), is(notNullValue()));
|
||||
assertThreadContextContainsAuthentication(result);
|
||||
assertEquals(expected, result);
|
||||
success.set(true);
|
||||
latch.countDown();
|
||||
}, this::logAndFail));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
assertThat(ex.getMessage(), containsString("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: "));
|
||||
latch.countDown();
|
||||
} catch (NegativeArraySizeException ex) {
|
||||
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!
|
||||
latch.await();
|
||||
verify(auditTrail).authenticationSuccess(firstRealm.name(), user, "_action", message);
|
||||
if (success.get()) {
|
||||
verify(auditTrail).authenticationSuccess(firstRealm.name(), user, "_action", message);
|
||||
}
|
||||
verifyNoMoreInteractions(auditTrail);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue