Search in sources :

Example 16 with TextField

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

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