use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.
the class DataPrepperServerConfigurationTest method testGivenPluginFactoryAndPluginSettingsThenCreateAuthenticationProvider.
@Test
public void testGivenPluginFactoryAndPluginSettingsThenCreateAuthenticationProvider() {
final PluginFactory pluginFactory = mock(PluginFactory.class);
final PluginSetting pluginSetting = mock(PluginSetting.class);
final DataPrepperCoreAuthenticationProvider expected = mock(DataPrepperCoreAuthenticationProvider.class);
when(pluginFactory.loadPlugin(eq(DataPrepperCoreAuthenticationProvider.class), eq(pluginSetting))).thenReturn(expected);
final DataPrepperCoreAuthenticationProvider authenticationProvider = serverConfiguration.authenticationProvider(pluginFactory, pluginSetting);
assertThat(authenticationProvider, is(expected));
}
use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.
the class DataPrepperServerConfigurationTest method testGivingInsecureConfigThenCreateInsecureSettings.
@Test
public void testGivingInsecureConfigThenCreateInsecureSettings() {
final PluginModel pluginModel = mock(PluginModel.class);
when(pluginModel.getPluginName()).thenReturn("unauthenticated");
final PluginSetting pluginSetting = serverConfiguration.pluginSetting(pluginModel);
assertThat(pluginSetting.getName(), is("unauthenticated"));
assertThat(pluginSetting.getSettings().isEmpty(), is(true));
}
use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.
the class DefaultPluginFactoryIT method loadPlugin_should_throw_when_a_plugin_configuration_is_invalid.
@Test
void loadPlugin_should_throw_when_a_plugin_configuration_is_invalid() {
final String optionalStringValue = UUID.randomUUID().toString();
final Map<String, Object> pluginSettingMap = new HashMap<>();
pluginSettingMap.put("optional_string", optionalStringValue);
final PluginSetting pluginSetting = createPluginSettings(pluginSettingMap);
final DefaultPluginFactory objectUnderTest = createObjectUnderTest();
final InvalidPluginConfigurationException actualException = assertThrows(InvalidPluginConfigurationException.class, () -> objectUnderTest.loadPlugin(TestPluggableInterface.class, pluginSetting));
assertThat(actualException.getMessage(), notNullValue());
assertThat(actualException.getMessage(), equalTo("Plugin test_plugin in pipeline " + pipelineName + " is configured incorrectly: requiredString must not be null"));
}
use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.
the class PeerForwarderConfigTest method testBuildConfigInvalidSSL.
@Test
public void testBuildConfigInvalidSSL() {
final HashMap<String, Object> settings = new HashMap<>();
settings.put(PeerForwarderConfig.DISCOVERY_MODE, DiscoveryMode.STATIC.toString());
settings.put(PeerForwarderConfig.STATIC_ENDPOINTS, TEST_ENDPOINTS);
settings.put(PeerForwarderConfig.SSL, true);
settings.put(PeerForwarderConfig.SSL_KEY_CERT_FILE, EMPTY_SSL_KEY_CERT_FILE);
Assert.assertThrows(IllegalArgumentException.class, () -> {
final PluginSetting pluginSetting = new PluginSetting("peer_forwarder", settings);
pluginSetting.setPipelineName(PIPELINE_NAME);
PeerForwarderConfig.buildConfig(pluginSetting);
});
settings.put(PeerForwarderConfig.SSL_KEY_CERT_FILE, null);
Assert.assertThrows(IllegalArgumentException.class, () -> {
final PluginSetting pluginSetting = new PluginSetting("peer_forwarder", settings);
pluginSetting.setPipelineName(PIPELINE_NAME);
PeerForwarderConfig.buildConfig(pluginSetting);
});
settings.put(PeerForwarderConfig.SSL_KEY_CERT_FILE, INVALID_SSL_KEY_CERT_FILE);
Assert.assertThrows(RuntimeException.class, () -> {
final PluginSetting pluginSetting = new PluginSetting("peer_forwarder", settings);
pluginSetting.setPipelineName(PIPELINE_NAME);
PeerForwarderConfig.buildConfig(pluginSetting);
});
}
use of com.amazon.dataprepper.model.configuration.PluginSetting in project data-prepper by opensearch-project.
the class PeerForwarderConfigTest method testBuildConfigValidSSL.
@Test
public void testBuildConfigValidSSL() throws IOException {
final HashMap<String, Object> settings = new HashMap<>();
settings.put(PeerForwarderConfig.DISCOVERY_MODE, DiscoveryMode.STATIC.toString());
settings.put(PeerForwarderConfig.STATIC_ENDPOINTS, TEST_ENDPOINTS);
settings.put(PeerForwarderConfig.SSL, true);
settings.put(PeerForwarderConfig.SSL_KEY_CERT_FILE, VALID_SSL_KEY_CERT_FILE);
final PluginSetting pluginSetting = new PluginSetting("peer_forwarder", settings);
pluginSetting.setPipelineName(PIPELINE_NAME);
PeerForwarderConfig.buildConfig(pluginSetting);
verify(peerClientPool, times(1)).setSsl(true);
final ArgumentCaptor<Certificate> certificateArgumentCaptor = ArgumentCaptor.forClass(Certificate.class);
verify(peerClientPool, times(1)).setCertificate(certificateArgumentCaptor.capture());
final Certificate certificate = certificateArgumentCaptor.getValue();
final Path certFilePath = new File(VALID_SSL_KEY_CERT_FILE).toPath();
final String certAsString = Files.readString(certFilePath);
Assert.assertEquals(certificate.getCertificate(), certAsString);
}
Aggregations