Skip to content

Commit ca4b586

Browse files
authored
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
1 parent 21838d7 commit ca4b586

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/CompositeRolesStoreTests.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,17 @@ public void testNegativeLookupsAreCached() {
225225
return null;
226226
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
227227
final ReservedRolesStore reservedRolesStore = spy(new ReservedRolesStore());
228+
final NativePrivilegeStore nativePrivilegeStore = mock(NativePrivilegeStore.class);
229+
doAnswer((invocationOnMock) -> {
230+
ActionListener<Collection<ApplicationPrivilegeDescriptor>> callback = null;
231+
callback = (ActionListener<Collection<ApplicationPrivilegeDescriptor>>) invocationOnMock.getArguments()[2];
232+
callback.onResponse(Collections.emptyList());
233+
return null;
234+
}).when(nativePrivilegeStore).getPrivileges(isA(Set.class), isA(Set.class), any(ActionListener.class));
228235

229236
final CompositeRolesStore compositeRolesStore =
230237
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
231-
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
238+
nativePrivilegeStore, Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
232239
new XPackLicenseState(SECURITY_ENABLED_SETTINGS));
233240
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
234241

@@ -258,8 +265,9 @@ public void testNegativeLookupsAreCached() {
258265
if (getSuperuserRole && numberOfTimesToCall > 0) {
259266
// the superuser role was requested so we get the role descriptors again
260267
verify(reservedRolesStore, times(2)).accept(anySetOf(String.class), any(ActionListener.class));
268+
verify(nativePrivilegeStore).getPrivileges(isA(Set.class),isA(Set.class), any(ActionListener.class));
261269
}
262-
verifyNoMoreInteractions(fileRolesStore, reservedRolesStore, nativeRolesStore);
270+
verifyNoMoreInteractions(fileRolesStore, reservedRolesStore, nativeRolesStore, nativePrivilegeStore);
263271
}
264272

265273
public void testNegativeLookupsCacheDisabled() {

0 commit comments

Comments
 (0)