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);
}
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);
}
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;
});
}
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");
}
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;
}
Aggregations