Fix ReservedRealm test for failed authentication

Original commit: elastic/x-pack-elasticsearch@5759d9268c
This commit is contained in:
Tim Brooks 2017-07-14 09:28:44 -05:00
parent dbbec0d37e
commit 8ab167cccb
1 changed files with 6 additions and 3 deletions

View File

@ -286,16 +286,19 @@ public class ReservedRealmTests extends ESTestCase {
}
}
@AwaitsFix(bugUrl = "https://github.com/elastic/x-pack-elasticsearch/issues/2003")
public void testFailedAuthentication() throws Exception {
when(securityLifecycleService.isSecurityIndexExisting()).thenReturn(true);
SecureString password = new SecureString("password".toCharArray());
char[] hash = Hasher.BCRYPT.hash(password);
ReservedUserInfo userInfo = new ReservedUserInfo(hash, true, false);
mockGetAllReservedUserInfo(usersStore, Collections.singletonMap("elastic", userInfo));
final ReservedRealm reservedRealm = new ReservedRealm(mock(Environment.class), Settings.EMPTY, usersStore,
new AnonymousUser(Settings.EMPTY), securityLifecycleService, new ThreadContext(Settings.EMPTY));
// maybe cache a successful auth
if (randomBoolean()) {
PlainActionFuture<AuthenticationResult> future = new PlainActionFuture<>();
reservedRealm.authenticate(new UsernamePasswordToken(ElasticUser.NAME, EMPTY_PASSWORD), future);
reservedRealm.authenticate(new UsernamePasswordToken(ElasticUser.NAME, password), future);
User user = future.actionGet().getUser();
assertEquals(new ElasticUser(true), user);
}