use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchExecutorTest method checksUserPermissionsForSearch.
@Test
public void checksUserPermissionsForSearch() {
final Search search = mockSearch();
final SearchUser searchUser = mock(SearchUser.class);
when(searchUser.canReadView(any())).thenReturn(true);
when(searchUser.canReadStream(any())).thenReturn(false);
doThrow(ForbiddenException.class).when(searchExecutionGuard).check(eq(search), any());
when(searchDomain.getForUser(eq("search1"), eq(searchUser))).thenReturn(Optional.of(search));
assertThatExceptionOfType(ForbiddenException.class).isThrownBy(() -> this.searchExecutor.execute("search1", searchUser, ExecutionState.empty()));
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchDomainTest method returnsEmptyOptionalWhenIdDoesntExist.
@Test
public void returnsEmptyOptionalWhenIdDoesntExist() {
when(dbService.get("some-id")).thenReturn(Optional.empty());
final SearchUser searchUser = mock(SearchUser.class);
final Optional<Search> result = sut.getForUser("some-id", searchUser);
assertThat(result).isEqualTo(Optional.empty());
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchDomainTest method guardExceptionOnPostLeadsTo403.
@Test
public void guardExceptionOnPostLeadsTo403() {
final Search search = mockSearchWithOwner("someone");
final SearchUser searchUser = mock(SearchUser.class);
throwGuardExceptionFor(search);
assertThatExceptionOfType(ForbiddenException.class).isThrownBy(() -> sut.saveForUser(search, searchUser));
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchDomainTest method listIsEmptyIfNoSearchesPermitted.
@Test
public void listIsEmptyIfNoSearchesPermitted() {
mockSearchWithOwner("someone else");
mockSearchWithOwner("someone else");
final SearchUser searchUser = mock(SearchUser.class);
List<Search> result = sut.getAllForUser(searchUser, searchUser::canReadView);
assertThat(result).isEmpty();
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class SearchDomainTest method includesOwnedSearchesInList.
@Test
public void includesOwnedSearchesInList() {
final String userName = "boeser-willi";
final Search ownedSearch = mockSearchWithOwner(userName);
mockSearchWithOwner("someone else");
final SearchUser searchUser = mock(SearchUser.class);
when(searchUser.owns(ownedSearch)).thenReturn(true);
List<Search> result = sut.getAllForUser(searchUser, searchUser::canReadView);
assertThat(result).containsExactly(ownedSearch);
}
Aggregations