From 46376100b14681681a5f8cbe4fedb3b32aecc5c0 Mon Sep 17 00:00:00 2001 From: Ioannis Kakavas Date: Fri, 13 Dec 2019 13:46:44 +0200 Subject: [PATCH] Fix testMalformedToken (#50164) (#50170) This test was fixed as part of #49736 so that it used a TokenService mock instance that was enabled, so that token verification fails because the token is invalid and not because the token service is not enabled. When the randomly generated token we send, decodes to being of version > 7.2 , we need to have mocked a GetResponse for the call that TokenService#getUserTokenFromId will make, otherwise this hangs and times out. --- .../elasticsearch/xpack/security/authc/TokenServiceTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenServiceTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenServiceTests.java index 7fc958cfafb..5af99ffb19d 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenServiceTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/TokenServiceTests.java @@ -601,7 +601,9 @@ public class TokenServiceTests extends ESTestCase { final byte[] randomBytes = new byte[numBytes]; random().nextBytes(randomBytes); TokenService tokenService = createTokenService(tokenServiceEnabledSettings, systemUTC()); - + // mock another random token so that we don't find a token in TokenService#getUserTokenFromId + Authentication authentication = new Authentication(new User("joe", "admin"), new RealmRef("native_realm", "native", "node1"), null); + mockGetTokenFromId(tokenService, UUIDs.randomBase64UUID(), authentication, false); ThreadContext requestContext = new ThreadContext(Settings.EMPTY); storeTokenHeader(requestContext, Base64.getEncoder().encodeToString(randomBytes));