use of org.graylog2.indexer.fieldtypes.MappedFieldTypesService 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.graylog2.indexer.fieldtypes.MappedFieldTypesService 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();
}
Aggregations