use of org.graylog2.plugin.configuration.fields.ConfigurationField 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.plugin.configuration.fields.ConfigurationField 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.plugin.configuration.fields.ConfigurationField 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;
});
}
use of org.graylog2.plugin.configuration.fields.ConfigurationField in project graylog2-server by Graylog2.
the class HTTPAlarmCallbackTest method getRequestedConfigurationContainsURLField.
@Test
public void getRequestedConfigurationContainsURLField() throws Exception {
final ConfigurationRequest requestedConfiguration = alarmCallback.getRequestedConfiguration();
final ConfigurationField field = requestedConfiguration.getField("url");
assertThat(field).isNotNull();
assertThat(field.getHumanName()).isEqualTo("URL");
assertThat(field.isOptional()).isEqualTo(ConfigurationField.Optional.NOT_OPTIONAL);
}
use of org.graylog2.plugin.configuration.fields.ConfigurationField in project graylog2-server by Graylog2.
the class V20161125142400_EmailAlarmCallbackMigrationTest method extractDefaultValuesFromEmailAlarmCallbackConfiguration.
@Test
public void extractDefaultValuesFromEmailAlarmCallbackConfiguration() throws Exception {
final ConfigurationRequest configurationRequest = mock(ConfigurationRequest.class);
when(emailAlarmCallback.getRequestedConfiguration()).thenReturn(configurationRequest);
final ConfigurationField configurationField1 = mock(ConfigurationField.class);
when(configurationField1.getDefaultValue()).thenReturn(42);
final ConfigurationField configurationField2 = mock(ConfigurationField.class);
when(configurationField2.getDefaultValue()).thenReturn("foobar");
final ConfigurationField configurationField3 = mock(ConfigurationField.class);
when(configurationField3.getDefaultValue()).thenReturn(true);
final Map<String, ConfigurationField> configurationFields = ImmutableMap.of("field1", configurationField1, "field2", configurationField2, "field3", configurationField3);
when(configurationRequest.getFields()).thenReturn(configurationFields);
final Map<String, Object> defaultConfig = this.emailAlarmCallbackMigrationPeriodical.getDefaultEmailAlarmCallbackConfig();
assertThat(defaultConfig).isNotNull().isNotEmpty().hasSize(3).isEqualTo(ImmutableMap.of("field1", 42, "field2", "foobar", "field3", true));
}
Aggregations