Fix a test failure in CompositeRolesStoreTests (#37661)

Due to missing stubbing for `NativePrivilegeStore#getPrivileges`
the test `testNegativeLookupsAreCached` failed
when the superuser role name was present in the role names.
This commit adds missing stubbing.

Closes: #37657
This commit is contained in:
Yogesh Gaikwad 2019-01-22 09:34:40 +11:00 committed by GitHub
parent 21838d73b5
commit ca4b5861c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -225,10 +225,17 @@ public class CompositeRolesStoreTests extends ESTestCase {
return null; return null;
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class)); }).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
final ReservedRolesStore reservedRolesStore = spy(new ReservedRolesStore()); final ReservedRolesStore reservedRolesStore = spy(new ReservedRolesStore());
final NativePrivilegeStore nativePrivilegeStore = mock(NativePrivilegeStore.class);
doAnswer((invocationOnMock) -> {
ActionListener<Collection<ApplicationPrivilegeDescriptor>> callback = null;
callback = (ActionListener<Collection<ApplicationPrivilegeDescriptor>>) invocationOnMock.getArguments()[2];
callback.onResponse(Collections.emptyList());
return null;
}).when(nativePrivilegeStore).getPrivileges(isA(Set.class), isA(Set.class), any(ActionListener.class));
final CompositeRolesStore compositeRolesStore = final CompositeRolesStore compositeRolesStore =
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore, new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS), nativePrivilegeStore, Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
new XPackLicenseState(SECURITY_ENABLED_SETTINGS)); new XPackLicenseState(SECURITY_ENABLED_SETTINGS));
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
@ -258,8 +265,9 @@ public class CompositeRolesStoreTests extends ESTestCase {
if (getSuperuserRole && numberOfTimesToCall > 0) { if (getSuperuserRole && numberOfTimesToCall > 0) {
// the superuser role was requested so we get the role descriptors again // the superuser role was requested so we get the role descriptors again
verify(reservedRolesStore, times(2)).accept(anySetOf(String.class), any(ActionListener.class)); verify(reservedRolesStore, times(2)).accept(anySetOf(String.class), any(ActionListener.class));
verify(nativePrivilegeStore).getPrivileges(isA(Set.class),isA(Set.class), any(ActionListener.class));
} }
verifyNoMoreInteractions(fileRolesStore, reservedRolesStore, nativeRolesStore); verifyNoMoreInteractions(fileRolesStore, reservedRolesStore, nativeRolesStore, nativePrivilegeStore);
} }
public void testNegativeLookupsCacheDisabled() { public void testNegativeLookupsCacheDisabled() {