use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class MessagesResourceTest method appliesDefaultStreamsToRequestIfOmitted.
@Test
void appliesDefaultStreamsToRequestIfOmitted() {
MessagesRequest request = validRequest();
final SearchUser searchUser = TestSearchUser.builder().allowStream("stream-1").allowStream("stream-2").build();
ArgumentCaptor<MessagesRequest> captor = ArgumentCaptor.forClass(MessagesRequest.class);
when(commandFactory.buildFromRequest(captor.capture())).thenReturn(ExportMessagesCommand.withDefaults());
sut.retrieve(request, searchUser);
MessagesRequest value = captor.getValue();
assertThat(value.streams()).containsExactly("stream-1", "stream-2");
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class MessagesResourceTest method passesOnlyUserNameToAuditingExporterIfExportBasedOnRequest.
@Test
void passesOnlyUserNameToAuditingExporterIfExportBasedOnRequest() {
final SearchUser searchUser = TestSearchUser.builder().withUser(currentUser).build();
AtomicReference<AuditContext> context = captureAuditContext();
sut.retrieve(validRequest(), searchUser);
assertAll(() -> assertThat(context.get().userName()).isEqualTo(currentUser.getName()), () -> assertThat(context.get().searchId()).isEmpty(), () -> assertThat(context.get().searchTypeId()).isEmpty());
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchDomainTest method throwsPermissionExceptionIfNeitherOwnedNorPermittedFromViews.
@Test
public void throwsPermissionExceptionIfNeitherOwnedNorPermittedFromViews() {
final Search search = mockSearchWithOwner("someone else");
final SearchUser searchUser = mock(SearchUser.class);
when(viewService.forSearch(anyString())).thenReturn(ImmutableList.of());
assertThatExceptionOfType(PermissionException.class).isThrownBy(() -> sut.getForUser(search.id(), searchUser));
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchDomainTest method includesSearchesPermittedViaViewsInList.
@Test
public void includesSearchesPermittedViaViewsInList() {
final Search permittedSearch = mockSearchWithOwner("someone else");
mockSearchWithOwner("someone else");
final SearchUser searchUser = mock(SearchUser.class);
final ViewDTO viewDTO = mock(ViewDTO.class);
when(viewService.forSearch(permittedSearch.id())).thenReturn(ImmutableList.of(viewDTO));
when(searchUser.canReadView(viewDTO)).thenReturn(true);
List<Search> result = sut.getAllForUser(searchUser, searchUser::canReadView);
assertThat(result).containsExactly(permittedSearch);
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchDomainTest method loadsSearchIfUserIsOwner.
@Test
public void loadsSearchIfUserIsOwner() {
final String userName = "boeser-willi";
final Search search = mockSearchWithOwner(userName);
final SearchUser searchUser = mock(SearchUser.class);
when(searchUser.owns(search)).thenReturn(true);
final Optional<Search> result = sut.getForUser(search.id(), searchUser);
assertThat(result).isEqualTo(Optional.of(search));
}
Aggregations