|
@@ -716,7 +716,7 @@ public class AuthenticationServiceTests extends ESTestCase {
|
|
|
when(secondRealm.supports(token)).thenReturn(true);
|
|
when(secondRealm.supports(token)).thenReturn(true);
|
|
|
mockAuthenticate(secondRealm, token, new User("lookup user", new String[]{"user"}));
|
|
mockAuthenticate(secondRealm, token, new User("lookup user", new String[]{"user"}));
|
|
|
mockRealmLookupReturnsNull(firstRealm, "run_as");
|
|
mockRealmLookupReturnsNull(firstRealm, "run_as");
|
|
|
- doThrow(authenticationError("realm doesn't want to " + "lookup"))
|
|
|
|
|
|
|
+ doThrow(authenticationError("realm doesn't want to lookup"))
|
|
|
.when(secondRealm).lookupUser(eq("run_as"), any(ActionListener.class));
|
|
.when(secondRealm).lookupUser(eq("run_as"), any(ActionListener.class));
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -1029,12 +1029,22 @@ public class AuthenticationServiceTests extends ESTestCase {
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
private void mockAuthenticate(Realm realm, AuthenticationToken token, User user) {
|
|
private void mockAuthenticate(Realm realm, AuthenticationToken token, User user) {
|
|
|
- doAnswer((i) -> {
|
|
|
|
|
|
|
+ final boolean separateThread = randomBoolean();
|
|
|
|
|
+ doAnswer(i -> {
|
|
|
ActionListener<AuthenticationResult> listener = (ActionListener<AuthenticationResult>) i.getArguments()[1];
|
|
ActionListener<AuthenticationResult> listener = (ActionListener<AuthenticationResult>) i.getArguments()[1];
|
|
|
- if (user == null) {
|
|
|
|
|
- listener.onResponse(AuthenticationResult.notHandled());
|
|
|
|
|
|
|
+ Runnable run = () -> {
|
|
|
|
|
+ if (user == null) {
|
|
|
|
|
+ listener.onResponse(AuthenticationResult.notHandled());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ listener.onResponse(AuthenticationResult.success(user));
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ if (separateThread) {
|
|
|
|
|
+ final Thread thread = new Thread(run);
|
|
|
|
|
+ thread.start();
|
|
|
|
|
+ thread.join();
|
|
|
} else {
|
|
} else {
|
|
|
- listener.onResponse(AuthenticationResult.success(user));
|
|
|
|
|
|
|
+ run.run();
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}).when(realm).authenticate(eq(token), any(ActionListener.class));
|
|
}).when(realm).authenticate(eq(token), any(ActionListener.class));
|