Fix handling of IOException when computing key for tokens (elastic/x-pack-elasticsearch#3639)
The invalid token test has been failing due to the way the test expects an exception to be returned. Recent changes allowed the exception to be returned via a listener but the test was not adapted and the code in the token service was not properly handling these exceptions when they were returned via a listener. relates elastic/x-pack-elasticsearch#3630 Original commit: elastic/x-pack-elasticsearch@1cf2cc0427
This commit is contained in:
parent
2453da82e0
commit
e577d2b776
|
@ -265,7 +265,15 @@ public final class TokenService extends AbstractComponent {
|
||||||
listener.onResponse(null);
|
listener.onResponse(null);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
decodeAndValidateToken(token, listener);
|
decodeAndValidateToken(token, ActionListener.wrap(listener::onResponse, e -> {
|
||||||
|
if (e instanceof IOException) {
|
||||||
|
// could happen with a token that is not ours
|
||||||
|
logger.debug("invalid token", e);
|
||||||
|
listener.onResponse(null);
|
||||||
|
} else {
|
||||||
|
listener.onFailure(e);
|
||||||
|
}
|
||||||
|
}));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// could happen with a token that is not ours
|
// could happen with a token that is not ours
|
||||||
logger.debug("invalid token", e);
|
logger.debug("invalid token", e);
|
||||||
|
|
|
@ -886,7 +886,19 @@ public class AuthenticationServiceTests extends ESTestCase {
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
success.set(true);
|
success.set(true);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}, this::logAndFail));
|
}, e -> {
|
||||||
|
if (e instanceof IllegalStateException) {
|
||||||
|
assertThat(e.getMessage(), containsString("array length must be <= to " + ArrayUtil.MAX_ARRAY_LENGTH + " but was: "));
|
||||||
|
latch.countDown();
|
||||||
|
} else if (e instanceof NegativeArraySizeException) {
|
||||||
|
assertThat(e.getMessage(), containsString("array size must be positive but was: "));
|
||||||
|
latch.countDown();
|
||||||
|
} else {
|
||||||
|
logger.error("unexpected exception", e);
|
||||||
|
latch.countDown();
|
||||||
|
fail("unexpected exception: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}));
|
||||||
} catch (IllegalStateException ex) {
|
} catch (IllegalStateException 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();
|
latch.countDown();
|
||||||
|
|
Loading…
Reference in New Issue