Skip to content

Commit

Permalink
Fix a test failure in CompositeRolesStoreTests (elastic#37661)
Browse files Browse the repository at this point in the history
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: elastic#37657
  • Loading branch information
bizybot authored Jan 21, 2019
1 parent 21838d7 commit ca4b586
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,17 @@ public void testNegativeLookupsAreCached() {
return null;
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
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 =
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));
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor

Expand Down Expand Up @@ -258,8 +265,9 @@ public void testNegativeLookupsAreCached() {
if (getSuperuserRole && numberOfTimesToCall > 0) {
// the superuser role was requested so we get the role descriptors again
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() {
Expand Down

0 comments on commit ca4b586

Please sign in to comment.