Search in sources :

Example 1 with InputsList

use of org.graylog2.rest.models.system.inputs.responses.InputsList 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 2 with InputsList

use of org.graylog2.rest.models.system.inputs.responses.InputsList 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

Input (org.graylog2.inputs.Input)2 ConfigurationRequest (org.graylog2.plugin.configuration.ConfigurationRequest)2 ConfigurationField (org.graylog2.plugin.configuration.fields.ConfigurationField)2 TextField (org.graylog2.plugin.configuration.fields.TextField)2 InputsList (org.graylog2.rest.models.system.inputs.responses.InputsList)2 InputDescription (org.graylog2.shared.inputs.InputDescription)2 Test (org.junit.Test)2