|
@@ -83,6 +83,7 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
private boolean hasAnonymousProfile;
|
|
|
private boolean hasReservedProfile;
|
|
|
private boolean hasNativeProfile;
|
|
|
+ private boolean profileIndexExists;
|
|
|
|
|
|
@Before
|
|
|
public void maybeEnableAnonymous() {
|
|
@@ -96,6 +97,7 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
hasAnonymousProfile = randomBoolean();
|
|
|
hasReservedProfile = randomBoolean();
|
|
|
hasNativeProfile = randomBoolean();
|
|
|
+ profileIndexExists = randomBoolean();
|
|
|
}
|
|
|
|
|
|
@After
|
|
@@ -163,7 +165,7 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
} else {
|
|
|
assertThat("expected an empty array but got: " + Arrays.toString(users), users, emptyArray());
|
|
|
}
|
|
|
- if (withProfileUid) {
|
|
|
+ if (profileIndexExists && withProfileUid) {
|
|
|
assertThat(
|
|
|
responseRef.get().getProfileUidLookup(),
|
|
|
equalTo(
|
|
@@ -248,7 +250,7 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
assertThat(throwableRef.get(), is(nullValue()));
|
|
|
assertThat(responseRef.get(), is(notNullValue()));
|
|
|
assertThat(users, arrayContaining(reservedUsers.toArray(new User[reservedUsers.size()])));
|
|
|
- if (withProfileUid) {
|
|
|
+ if (profileIndexExists && withProfileUid) {
|
|
|
assertThat(responseRef.get().getProfileUidLookup(), equalTo(reservedUsers.stream().filter(user -> {
|
|
|
if (user instanceof AnonymousUser) {
|
|
|
return hasAnonymousProfile;
|
|
@@ -340,7 +342,7 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
assertThat(throwableRef.get(), is(nullValue()));
|
|
|
assertThat(responseRef.get(), is(notNullValue()));
|
|
|
assertThat(responseRef.get().users(), arrayContaining(expectedList.toArray(new User[expectedList.size()])));
|
|
|
- if (withProfileUid) {
|
|
|
+ if (profileIndexExists && withProfileUid) {
|
|
|
assertThat(responseRef.get().getProfileUidLookup(), equalTo(expectedList.stream().filter(user -> {
|
|
|
if (user instanceof AnonymousUser) {
|
|
|
return hasAnonymousProfile;
|
|
@@ -399,6 +401,7 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
null,
|
|
|
Collections.emptySet()
|
|
|
);
|
|
|
+ profileIndexExists = true; // profile index must exist to simulate exception on search
|
|
|
TransportGetUsersAction action = new TransportGetUsersAction(
|
|
|
Settings.EMPTY,
|
|
|
mock(ActionFilters.class),
|
|
@@ -496,7 +499,7 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
assertThat(throwableRef.get(), is(nullValue()));
|
|
|
assertThat(responseRef.get(), is(notNullValue()));
|
|
|
assertThat(responseRef.get().users(), arrayContaining(expectedList.toArray(new User[expectedList.size()])));
|
|
|
- if (withProfileUid) {
|
|
|
+ if (profileIndexExists && withProfileUid) {
|
|
|
assertThat(
|
|
|
responseRef.get().getProfileUidLookup(),
|
|
|
equalTo(
|
|
@@ -611,8 +614,12 @@ public class TransportGetUsersActionTests extends ESTestCase {
|
|
|
private ProfileService mockProfileService(boolean randomException) {
|
|
|
final ProfileService profileService = mock(ProfileService.class);
|
|
|
doAnswer(invocation -> {
|
|
|
- final List<Subject> subjects = (List<Subject>) invocation.getArguments()[0];
|
|
|
final var listener = (ActionListener<SubjectSearchResultsAndErrors<Profile>>) invocation.getArguments()[1];
|
|
|
+ if (false == profileIndexExists) {
|
|
|
+ listener.onResponse(null);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ final List<Subject> subjects = (List<Subject>) invocation.getArguments()[0];
|
|
|
List<Tuple<Subject, Profile>> results = subjects.stream().map(subject -> {
|
|
|
final User user = subject.getUser();
|
|
|
if (user instanceof AnonymousUser) {
|