use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class FieldTypesResourceTest method allFieldTypesReturnsResultFromMappedFieldTypesService.
@Test
public void allFieldTypesReturnsResultFromMappedFieldTypesService() {
final SearchUser searchUser = TestSearchUser.builder().allowStream("2323").allowStream("4242").build();
when(permittedStreams.load(any())).thenReturn(ImmutableSet.of("2323", "4242"));
final Set<MappedFieldTypeDTO> fieldTypes = Collections.singleton(MappedFieldTypeDTO.create("foobar", FieldTypes.Type.createType("long", ImmutableSet.of("numeric", "enumerable"))));
when(mappedFieldTypesService.fieldTypesByStreamIds(eq(ImmutableSet.of("2323", "4242")), eq(RelativeRange.allTime()))).thenReturn(fieldTypes);
final Set<MappedFieldTypeDTO> result = this.fieldTypesResource.allFieldTypes(searchUser);
assertThat(result).isEqualTo(fieldTypes);
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class FieldTypesResourceTest method byStreamReturnsTypesFromMappedFieldTypesService.
@Test
public void byStreamReturnsTypesFromMappedFieldTypesService() {
final SearchUser searchUser = TestSearchUser.builder().allowStream("2323").allowStream("4242").build();
final Set<MappedFieldTypeDTO> fieldTypes = Collections.singleton(MappedFieldTypeDTO.create("foobar", FieldTypes.Type.createType("long", ImmutableSet.of("numeric", "enumerable"))));
when(mappedFieldTypesService.fieldTypesByStreamIds(eq(ImmutableSet.of("2323", "4242")), eq(RelativeRange.allTime()))).thenReturn(fieldTypes);
final Set<MappedFieldTypeDTO> result = this.fieldTypesResource.byStreams(FieldTypesForStreamsRequest.Builder.builder().streams(ImmutableSet.of("2323", "4242")).build(), searchUser);
verify(mappedFieldTypesService, times(1)).fieldTypesByStreamIds(streamIdCaptor.capture(), timeRangeArgumentCaptor.capture());
assertThat(streamIdCaptor.getValue()).containsExactlyInAnyOrder("2323", "4242");
assertThat(timeRangeArgumentCaptor.getValue()).isEqualTo(RelativeRange.allTime());
assertThat(result).isEqualTo(fieldTypes);
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class FieldTypesResourceTest method allFieldTypesChecksPermissionsForStream.
@Test
public void allFieldTypesChecksPermissionsForStream() {
final SearchUser searchUser = TestSearchUser.builder().allowStream("4242").denyStream("2323").build();
final MappedFieldTypesService dependency = Mockito.mock(MappedFieldTypesService.class);
Mockito.when(dependency.fieldTypesByStreamIds(Mockito.any(), Mockito.any())).thenAnswer(invocation -> {
final Collection<String> streamIDs = invocation.getArgument(0);
// for each streamID return a field that's called exactly like the streamID
return streamIDs.stream().map(streamID -> MappedFieldTypeDTO.create(streamID, FieldTypes.Type.builder().type("text").build())).collect(Collectors.toSet());
});
final FieldTypesResource resource = new FieldTypesResource(dependency);
final Set<MappedFieldTypeDTO> fields = resource.allFieldTypes(searchUser);
// field for allowed stream has to be present
assertThat(fields.stream().anyMatch(f -> f.name().equals("4242"))).isTrue();
// field for denied stream must not be present
assertThat(fields.stream().anyMatch(f -> f.name().equals("2323"))).isFalse();
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class FieldTypesResourceTest method byStreamChecksPermissionsForStream.
@Test
public void byStreamChecksPermissionsForStream() {
final SearchUser searchUser = TestSearchUser.builder().allowStream("2323").allowStream("4242").build();
final MappedFieldTypesService dependency = Mockito.mock(MappedFieldTypesService.class);
Mockito.when(dependency.fieldTypesByStreamIds(Mockito.any(), Mockito.any())).thenAnswer(invocation -> {
final Collection<String> streamIDs = invocation.getArgument(0);
// for each streamID return a field that's called exactly like the streamID
return streamIDs.stream().map(streamID -> MappedFieldTypeDTO.create(streamID, FieldTypes.Type.builder().type("text").build())).collect(Collectors.toSet());
});
final FieldTypesResource resource = new FieldTypesResource(dependency);
final Set<MappedFieldTypeDTO> fields = resource.byStreams(FieldTypesForStreamsRequest.Builder.builder().streams(ImmutableSet.of("2323", "4242")).build(), searchUser);
// field for allowed stream has to be present
assertThat(fields.stream().anyMatch(f -> f.name().equals("2323"))).isTrue();
assertThat(fields.stream().anyMatch(f -> f.name().equals("4242"))).isTrue();
}
use of org.graylog.plugins.views.search.permissions.SearchUser in project graylog2-server by Graylog2.
the class FieldTypesResourceTest method shouldNotAllowAccessWithoutPermission.
@Test
public void shouldNotAllowAccessWithoutPermission() {
final SearchUser searchUser = TestSearchUser.builder().denyStream("2323").allowStream("4242").build();
assertThatExceptionOfType(MissingStreamPermissionException.class).isThrownBy(() -> fieldTypesResource.byStreams(FieldTypesForStreamsRequest.Builder.builder().streams(ImmutableSet.of("2323", "4242")).build(), searchUser)).satisfies(ex -> assertThat(ex.streamsWithMissingPermissions()).contains("2323"));
}
Aggregations