Skip to content

Commit a78ba25

Browse files
committed
Fix testMalformedToken
This test was fixed as part of elastic#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.
1 parent b6d8a7e commit a78ba25

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ public void testMalformedToken() throws Exception {
599599
final byte[] randomBytes = new byte[numBytes];
600600
random().nextBytes(randomBytes);
601601
TokenService tokenService = createTokenService(tokenServiceEnabledSettings, systemUTC());
602-
602+
// mock another random token so that we don't find a token in TokenService#getUserTokenFromId
603+
Authentication authentication = new Authentication(new User("joe", "admin"), new RealmRef("native_realm", "native", "node1"), null);
604+
mockGetTokenFromId(tokenService, UUIDs.randomBase64UUID(), authentication, false);
603605
ThreadContext requestContext = new ThreadContext(Settings.EMPTY);
604606
storeTokenHeader(requestContext, Base64.getEncoder().encodeToString(randomBytes));
605607

0 commit comments

Comments
 (0)