Search in sources :

Example 91 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class UdpTransportTest method launchTransportForBootStrapTest.

private UdpTransport launchTransportForBootStrapTest(final ChannelInboundHandler channelHandler) throws MisfireException {
    final UdpTransport transport = new UdpTransport(CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, new LocalMetricRegistry()) {

        @Override
        protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChannelHandlers(MessageInput input) {
            final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
            handlers.put("logging", () -> new LoggingHandler(LogLevel.INFO));
            handlers.put("counter", () -> channelHandler);
            handlers.putAll(super.getChannelHandlers(input));
            return handlers;
        }
    };
    final MessageInput messageInput = mock(MessageInput.class);
    when(messageInput.getId()).thenReturn("TEST");
    when(messageInput.getName()).thenReturn("TEST");
    transport.launch(messageInput);
    return transport;
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(io.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) LinkedHashMap(java.util.LinkedHashMap)

Example 92 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class UdpTransportTest method receiveBufferSizeIsNotLimited.

@Test
public void receiveBufferSizeIsNotLimited() {
    final int recvBufferSize = Ints.saturatedCast(Size.megabytes(1L).toBytes());
    ImmutableMap<String, Object> source = ImmutableMap.of(NettyTransport.CK_BIND_ADDRESS, BIND_ADDRESS, NettyTransport.CK_PORT, PORT, NettyTransport.CK_RECV_BUFFER_SIZE, recvBufferSize);
    Configuration config = new Configuration(source);
    UdpTransport udpTransport = new UdpTransport(config, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, new LocalMetricRegistry());
    assertThat(udpTransport.getBootstrap(mock(MessageInput.class)).config().options().get(ChannelOption.SO_RCVBUF)).isEqualTo(recvBufferSize);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) Test(org.junit.Test)

Example 93 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class InputsResourceMaskingPasswordsTest method testMaskingOfPasswordFields.

@Test
public void testMaskingOfPasswordFields() {
    final ConfigurationField fooInput = mock(ConfigurationField.class);
    final TextField passwordInput = mock(TextField.class);
    when(fooInput.getName()).thenReturn("foo");
    when(passwordInput.getName()).thenReturn("password");
    when(passwordInput.getAttributes()).thenReturn(ImmutableList.of(TextField.Attribute.IS_PASSWORD.toString().toLowerCase(Locale.ENGLISH)));
    final ConfigurationRequest configurationRequest = ConfigurationRequest.createWithFields(fooInput, passwordInput);
    final Map<String, Object> configuration = ImmutableMap.of("foo", 42, "password", "verysecret");
    final Map<String, Object> resultingAttributes = this.inputsResource.maskPasswordsInConfiguration(configuration, configurationRequest);
    assertThat(resultingAttributes).hasSize(2);
    assertThat(resultingAttributes).containsEntry("password", "<password set>");
    assertThat(resultingAttributes).containsEntry("foo", 42);
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField) Test(org.junit.Test)

Example 94 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class InputsResourceMaskingPasswordsTest method testRetrievalOfInputWithPasswordFieldIfUserIsNotAllowedToEditInput.

@Test
public void testRetrievalOfInputWithPasswordFieldIfUserIsNotAllowedToEditInput() throws NotFoundException {
    final String inputId = "myinput";
    final String inputType = "dummyinput";
    final Input input = getInput(inputId, inputType);
    when(inputService.find(inputId)).thenReturn(input);
    final ConfigurationField fooInput = mock(ConfigurationField.class);
    when(fooInput.getName()).thenReturn("foo");
    final TextField passwordInput = getPasswordField("password");
    final ConfigurationRequest configurationRequest = ConfigurationRequest.createWithFields(fooInput, passwordInput);
    final InputDescription inputDescription = getInputDescription(configurationRequest);
    this.availableInputs.put(inputType, inputDescription);
    when(currentSubject.isPermitted(RestPermissions.INPUTS_READ + ":" + inputId)).thenReturn(true);
    when(currentSubject.isPermitted(RestPermissions.INPUTS_EDIT + ":" + inputId)).thenReturn(false);
    final Map<String, Object> configuration = ImmutableMap.of("foo", 42, "password", "verysecret");
    when(input.getConfiguration()).thenReturn(configuration);
    final InputSummary summary = this.inputsResource.get(inputId);
    assertThat(summary.attributes()).hasSize(2);
    assertThat(summary.attributes()).containsEntry("password", "<password set>");
    assertThat(summary.attributes()).containsEntry("foo", 42);
}
Also used : InputSummary(org.graylog2.rest.models.system.inputs.responses.InputSummary) Input(org.graylog2.inputs.Input) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField) InputDescription(org.graylog2.shared.inputs.InputDescription) Test(org.junit.Test)

Example 95 with Configuration

use of org.graylog2.Configuration in project graylog2-server by Graylog2.

the class InputsResourceMaskingPasswordsTest method testMaskingOfEmptyMap.

@Test
public void testMaskingOfEmptyMap() {
    final ConfigurationRequest configurationRequest = ConfigurationRequest.createWithFields();
    final Map<String, Object> configuration = Collections.emptyMap();
    final Map<String, Object> resultingAttributes = this.inputsResource.maskPasswordsInConfiguration(configuration, configurationRequest);
    assertThat(resultingAttributes).isEmpty();
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)67 Configuration (org.graylog2.plugin.configuration.Configuration)46 Configuration (org.apache.commons.configuration2.Configuration)35 ApiOperation (io.swagger.annotations.ApiOperation)31 Timed (com.codahale.metrics.annotation.Timed)23 AuditEvent (org.graylog2.audit.jersey.AuditEvent)23 Path (javax.ws.rs.Path)22 BadRequestException (javax.ws.rs.BadRequestException)21 MessageInput (org.graylog2.plugin.inputs.MessageInput)18 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)17 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)15 Stream (org.graylog2.plugin.streams.Stream)15 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)14 File (java.io.File)14 Consumes (javax.ws.rs.Consumes)14 DateTime (org.joda.time.DateTime)14 POST (javax.ws.rs.POST)13 Produces (javax.ws.rs.Produces)13 Configuration (org.graylog2.Configuration)13 ApiResponses (io.swagger.annotations.ApiResponses)12