Search in sources :

Example 26 with PluginSetting

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));
}
Also used : DataPrepperCoreAuthenticationProvider(com.amazon.dataprepper.pipeline.server.DataPrepperCoreAuthenticationProvider) PluginFactory(com.amazon.dataprepper.model.plugin.PluginFactory) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 27 with PluginSetting

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));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 28 with PluginSetting

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"));
}
Also used : InvalidPluginConfigurationException(com.amazon.dataprepper.model.plugin.InvalidPluginConfigurationException) HashMap(java.util.HashMap) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 29 with PluginSetting

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);
    });
}
Also used : HashMap(java.util.HashMap) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.Test)

Example 30 with 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);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) File(java.io.File) Certificate(com.amazon.dataprepper.plugins.prepper.peerforwarder.certificate.model.Certificate) Test(org.junit.Test)

Aggregations

PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)150 Test (org.junit.jupiter.api.Test)58 HashMap (java.util.HashMap)55 Test (org.junit.Test)43 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Record (com.amazon.dataprepper.model.record.Record)22 AsciiString (io.netty.util.AsciiString)16 Measurement (io.micrometer.core.instrument.Measurement)12 StringJoiner (java.util.StringJoiner)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 Map (java.util.Map)11 Path (java.nio.file.Path)9 Server (com.linecorp.armeria.server.Server)8 Before (org.junit.Before)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 BlockingBuffer (com.amazon.dataprepper.plugins.buffer.blockingbuffer.BlockingBuffer)7 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)7 PluginMetrics (com.amazon.dataprepper.metrics.PluginMetrics)6 CertificateProvider (com.amazon.dataprepper.plugins.certificate.CertificateProvider)6 ACMCertificateProvider (com.amazon.dataprepper.plugins.certificate.acm.ACMCertificateProvider)6