Search in sources :

Example 11 with TextField

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

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

the class InputsResourceMaskingPasswordsTest method testMaskingOfNullValueInMap.

@Test
public void testMaskingOfNullValueInMap() {
    final TextField passwordInput = mock(TextField.class);
    when(passwordInput.getName()).thenReturn("nopassword");
    when(passwordInput.getAttributes()).thenReturn(ImmutableList.of());
    final ConfigurationRequest configurationRequest = ConfigurationRequest.createWithFields(passwordInput);
    final Map<String, Object> configuration = Collections.singletonMap("nopassword", null);
    final Map<String, Object> resultingAttributes = this.inputsResource.maskPasswordsInConfiguration(configuration, configurationRequest);
    assertThat(resultingAttributes).hasSize(1);
    assertThat(resultingAttributes).containsEntry("nopassword", null);
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) TextField(org.graylog2.plugin.configuration.fields.TextField) Test(org.junit.Test)

Example 13 with TextField

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

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

the class InputsResourceMaskingPasswordsTest method testMaskingOfNonPasswordFields.

@Test
public void testMaskingOfNonPasswordFields() {
    final TextField passwordInput = mock(TextField.class);
    when(passwordInput.getName()).thenReturn("nopassword");
    when(passwordInput.getAttributes()).thenReturn(ImmutableList.of());
    final ConfigurationRequest configurationRequest = ConfigurationRequest.createWithFields(passwordInput);
    final Map<String, Object> configuration = ImmutableMap.of("nopassword", "lasers in space");
    final Map<String, Object> resultingAttributes = this.inputsResource.maskPasswordsInConfiguration(configuration, configurationRequest);
    assertThat(resultingAttributes).hasSize(1);
    assertThat(resultingAttributes).containsEntry("nopassword", "lasers in space");
}
Also used : ConfigurationRequest(org.graylog2.plugin.configuration.ConfigurationRequest) TextField(org.graylog2.plugin.configuration.fields.TextField) Test(org.junit.Test)

Example 15 with TextField

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

the class InputsResourceMaskingPasswordsTest method getPasswordField.

private TextField getPasswordField(String name) {
    final TextField passwordInput = mock(TextField.class);
    when(passwordInput.getName()).thenReturn(name);
    when(passwordInput.getAttributes()).thenReturn(ImmutableList.of(TextField.Attribute.IS_PASSWORD.toString().toLowerCase(Locale.ENGLISH)));
    return passwordInput;
}
Also used : TextField(org.graylog2.plugin.configuration.fields.TextField)

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