Search in sources :

Example 21 with SearchUser

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()));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) Search(org.graylog.plugins.views.search.Search) SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) RestResourceBaseTest(org.graylog2.rest.resources.RestResourceBaseTest) Test(org.junit.Test)

Example 22 with SearchUser

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());
}
Also used : SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) Test(org.junit.Test)

Example 23 with SearchUser

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));
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) Test(org.junit.Test)

Example 24 with 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();
}
Also used : SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) Test(org.junit.Test)

Example 25 with SearchUser

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);
}
Also used : SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

SearchUser (org.graylog.plugins.views.search.permissions.SearchUser)26 Test (org.junit.Test)19 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 ForbiddenException (javax.ws.rs.ForbiddenException)4 Search (org.graylog.plugins.views.search.Search)4 RestResourceBaseTest (org.graylog2.rest.resources.RestResourceBaseTest)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Collection (java.util.Collection)3 POST (javax.ws.rs.POST)3 ViewDTO (org.graylog.plugins.views.search.views.ViewDTO)3 RelativeRange (org.graylog2.plugin.indexer.searches.timeranges.RelativeRange)3 Test (org.junit.jupiter.api.Test)3 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2 Collections (java.util.Collections)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2