Search in sources :

Example 6 with ConfigurationField

use of org.graylog2.plugin.configuration.fields.ConfigurationField in project graylog2-server by Graylog2.

the class InputsResourceMaskingPasswordsTest method testRetrievalOfInputWithPasswordFieldIfUserIsAllowedToEditInput.

@Test
public void testRetrievalOfInputWithPasswordFieldIfUserIsAllowedToEditInput() 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(true);
    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", "verysecret");
    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 7 with ConfigurationField

use of org.graylog2.plugin.configuration.fields.ConfigurationField in project graylog2-server by Graylog2.

the class InputsResourceMaskingPasswordsTest method testRetrievalOfAllInputsWithPasswordFieldForUserAllowedToEditInput.

@Test
public void testRetrievalOfAllInputsWithPasswordFieldForUserAllowedToEditInput() throws NotFoundException {
    final String inputId = "myinput";
    final String inputType = "dummyinput";
    final Input input = getInput(inputId, inputType);
    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(true);
    final Map<String, Object> configuration = ImmutableMap.of("foo", 42, "password", "verysecret");
    when(input.getConfiguration()).thenReturn(configuration);
    when(inputService.all()).thenReturn(Collections.singletonList(input));
    final InputsList inputsList = this.inputsResource.list();
    assertThat(inputsList.inputs()).isNotEmpty();
    assertThat(inputsList.inputs()).allMatch(summary -> {
        assertThat(summary.attributes()).hasSize(2);
        assertThat(summary.attributes()).containsEntry("password", "verysecret");
        assertThat(summary.attributes()).containsEntry("foo", 42);
        return true;
    });
}
Also used : Input(org.graylog2.inputs.Input) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) InputsList(org.graylog2.rest.models.system.inputs.responses.InputsList) 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 8 with ConfigurationField

use of org.graylog2.plugin.configuration.fields.ConfigurationField in project graylog2-server by Graylog2.

the class InputsResourceMaskingPasswordsTest method testRetrievalOfAllInputsWithPasswordFieldForUserNotAllowedToEditInput.

@Test
public void testRetrievalOfAllInputsWithPasswordFieldForUserNotAllowedToEditInput() throws NotFoundException {
    final String inputId = "myinput";
    final String inputType = "dummyinput";
    final Input input = getInput(inputId, inputType);
    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);
    when(inputService.all()).thenReturn(Collections.singletonList(input));
    final InputsList inputsList = this.inputsResource.list();
    assertThat(inputsList.inputs()).isNotEmpty();
    assertThat(inputsList.inputs()).allMatch(summary -> {
        assertThat(summary.attributes()).hasSize(2);
        assertThat(summary.attributes()).containsEntry("password", "<password set>");
        assertThat(summary.attributes()).containsEntry("foo", 42);
        return true;
    });
}
Also used : Input(org.graylog2.inputs.Input) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) InputsList(org.graylog2.rest.models.system.inputs.responses.InputsList) 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 9 with ConfigurationField

use of org.graylog2.plugin.configuration.fields.ConfigurationField in project graylog2-server by Graylog2.

the class HTTPAlarmCallbackTest method getRequestedConfigurationContainsURLField.

@Test
public void getRequestedConfigurationContainsURLField() throws Exception {
    final ConfigurationRequest requestedConfiguration = alarmCallback.getRequestedConfiguration();
    final ConfigurationField field = requestedConfiguration.getField("url");
    assertThat(field).isNotNull();
    assertThat(field.getHumanName()).isEqualTo("URL");
    assertThat(field.isOptional()).isEqualTo(ConfigurationField.Optional.NOT_OPTIONAL);
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) Test(org.junit.Test)

Example 10 with ConfigurationField

use of org.graylog2.plugin.configuration.fields.ConfigurationField in project graylog2-server by Graylog2.

the class V20161125142400_EmailAlarmCallbackMigrationTest method extractDefaultValuesFromEmailAlarmCallbackConfiguration.

@Test
public void extractDefaultValuesFromEmailAlarmCallbackConfiguration() throws Exception {
    final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
    when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
    final ConfigurationField configurationField1 = mock(ConfigurationField.class);
    when(configurationField1.getDefaultValue()).thenReturn(42);
    final ConfigurationField configurationField2 = mock(ConfigurationField.class);
    when(configurationField2.getDefaultValue()).thenReturn("foobar");
    final ConfigurationField configurationField3 = mock(ConfigurationField.class);
    when(configurationField3.getDefaultValue()).thenReturn(true);
    final Map<String, ConfigurationField> configurationFields = ImmutableMap.of("field1", configurationField1, "field2", configurationField2, "field3", configurationField3);
    when(configurationRequest.getFields()).thenReturn(configurationFields);
    final Map<String, Object> defaultConfig = this.emailAlarmCallbackMigrationPeriodical.getDefaultEmailAlarmCallbackConfig();
    assertThat(defaultConfig).isNotNull().isNotEmpty().hasSize(3).isEqualTo(ImmutableMap.of("field1", 42, "field2", "foobar", "field3", true));
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) Test(org.junit.Test)

Aggregations

ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)12 Test (org.junit.Test)8 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)7 TextField (org.graylog2.plugin.configuration.fields.TextField)7 Input (org.graylog2.inputs.Input)4 InputDescription (org.graylog2.shared.inputs.InputDescription)4 InputSummary (org.graylog2.rest.models.system.inputs.responses.InputSummary)2 InputsList (org.graylog2.rest.models.system.inputs.responses.InputsList)2 JsonValue (com.fasterxml.jackson.annotation.JsonValue)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1