Search in sources :

Example 6 with TextField

use of org.graylog2.rest.models.configuration.responses.TextField in project graylog2-server by Graylog2.

the class ConfigurationRequestTest method putAllRetainsOrder.

@Test
public void putAllRetainsOrder() throws Exception {
    final ImmutableMap<String, ConfigurationField> fields = ImmutableMap.<String, ConfigurationField>of("field1", new TextField("field1", "humanName", "defaultValue", "description"), "field2", new TextField("field2", "humanName", "defaultValue", "description"), "field3", new TextField("field3", "humanName", "defaultValue", "description"));
    configurationRequest.putAll(fields);
    assertThat(configurationRequest.getFields().keySet()).containsSequence("field1", "field2", "field3");
}
Also used : ConfigurationField(org.graylog2.plugin.configuration.fields.ConfigurationField) TextField(org.graylog2.plugin.configuration.fields.TextField) Test(org.junit.Test)

Example 7 with TextField

use of org.graylog2.rest.models.configuration.responses.TextField 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 8 with TextField

use of org.graylog2.rest.models.configuration.responses.TextField 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 9 with TextField

use of org.graylog2.rest.models.configuration.responses.TextField in project graylog2-server by Graylog2.

the class ConfigurationMapConverterTest method testConvertValues.

@Test
public void testConvertValues() throws Exception {
    final ImmutableMap<String, String> dropdownChoices = ImmutableMap.of("a", "1", "b", "2");
    final ConfigurationRequest cr = new ConfigurationRequest();
    cr.addField(new TextField("string", "string", "default", ""));
    cr.addField(new TextField("empty-string", "empty", "", ""));
    cr.addField(new TextField("null-string", "null", null, ""));
    cr.addField(new TextField("non-string", "non-string", null, ""));
    cr.addField(new NumberField("number", "number", 42, ""));
    cr.addField(new BooleanField("boolean-true", "true", false, ""));
    cr.addField(new BooleanField("boolean-false", "false", false, ""));
    cr.addField(new DropdownField("dropdown", "dropdown", "a", dropdownChoices, "", ConfigurationField.Optional.NOT_OPTIONAL));
    cr.addField(new DropdownField("dropdown-empty", "dropdown-empty", "", dropdownChoices, "", ConfigurationField.Optional.NOT_OPTIONAL));
    cr.addField(new DropdownField("dropdown-null", "dropdown-null", "", dropdownChoices, "", ConfigurationField.Optional.NOT_OPTIONAL));
    final UUID uuid = UUID.randomUUID();
    final Map<String, Object> data = new HashMap<>();
    data.put("string", "foo");
    data.put("empty-string", "");
    data.put("null-string", null);
    data.put("non-string", uuid);
    data.put("number", "5");
    data.put("boolean-true", "true");
    data.put("boolean-false", "false");
    data.put("dropdown", "a");
    data.put("dropdown-empty", "");
    data.put("dropdown-null", null);
    final Map<String, Object> config = ConfigurationMapConverter.convertValues(data, cr);
    assertThat(config).contains(entry("string", "foo"), entry("empty-string", ""), entry("null-string", ""), entry("non-string", uuid.toString()), entry("number", 5), entry("boolean-true", true), entry("boolean-false", false), entry("dropdown", "a"), entry("dropdown-empty", ""), entry("dropdown-null", ""));
}
Also used : DropdownField(org.graylog2.plugin.configuration.fields.DropdownField) BooleanField(org.graylog2.plugin.configuration.fields.BooleanField) HashMap(java.util.HashMap) ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) TextField(org.graylog2.plugin.configuration.fields.TextField) UUID(java.util.UUID) NumberField(org.graylog2.plugin.configuration.fields.NumberField) Test(org.junit.Test)

Example 10 with TextField

use of org.graylog2.rest.models.configuration.responses.TextField in project graylog2-server by Graylog2.

the class ConfigurationRequestTest method asListRetainsOrder.

@Test
public void asListRetainsOrder() throws Exception {
    int numberOfFields = 5;
    for (int i = 0; i < numberOfFields; i++) {
        configurationRequest.addField(new TextField("field" + i, "humanName", "defaultValue", "description"));
    }
    assertThat(configurationRequest.asList().keySet()).containsSequence("field0", "field1", "field2", "field3", "field4");
}
Also used : TextField(org.graylog2.plugin.configuration.fields.TextField) Test(org.junit.Test)

Aggregations

TextField (org.graylog2.plugin.configuration.fields.TextField)15 Test (org.junit.Test)11 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)10 ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)7 Input (org.graylog2.inputs.Input)4 InputDescription (org.graylog2.shared.inputs.InputDescription)4 HashMap (java.util.HashMap)2 InputSummary (org.graylog2.rest.models.system.inputs.responses.InputSummary)2 InputsList (org.graylog2.rest.models.system.inputs.responses.InputsList)2 Map (java.util.Map)1 UUID (java.util.UUID)1 BooleanField (org.graylog2.plugin.configuration.fields.BooleanField)1 DropdownField (org.graylog2.plugin.configuration.fields.DropdownField)1 ListField (org.graylog2.plugin.configuration.fields.ListField)1 NumberField (org.graylog2.plugin.configuration.fields.NumberField)1 BooleanField (org.graylog2.rest.models.configuration.responses.BooleanField)1 DropdownField (org.graylog2.rest.models.configuration.responses.DropdownField)1 NumberField (org.graylog2.rest.models.configuration.responses.NumberField)1 RequestedConfigurationField (org.graylog2.rest.models.configuration.responses.RequestedConfigurationField)1 TextField (org.graylog2.rest.models.configuration.responses.TextField)1