Search in sources :

Example 11 with StandardSSLContextService

use of org.apache.nifi.ssl.StandardSSLContextService in project nifi by apache.

the class TestPublishMqttSSL method init.

@Before
public void init() throws IOException, InitializationException {
    startServer();
    testRunner = TestRunners.newTestRunner(PublishMQTT.class);
    testRunner.setProperty(PublishMQTT.PROP_BROKER_URI, "ssl://localhost:8883");
    testRunner.setProperty(PublishMQTT.PROP_CLIENTID, "TestClient");
    testRunner.setProperty(PublishMQTT.PROP_RETAIN, "true");
    testRunner.setProperty(PublishMQTT.PROP_TOPIC, "testTopic");
    final StandardSSLContextService sslService = new StandardSSLContextService();
    Map<String, String> sslProperties = createSslProperties();
    testRunner.addControllerService("ssl-context", sslService, sslProperties);
    testRunner.enableControllerService(sslService);
    testRunner.setProperty(PublishMQTT.PROP_SSL_CONTEXT_SERVICE, "ssl-context");
}
Also used : PublishMQTT(org.apache.nifi.processors.mqtt.PublishMQTT) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Before(org.junit.Before)

Example 12 with StandardSSLContextService

use of org.apache.nifi.ssl.StandardSSLContextService in project nifi by apache.

the class TestInvokeHTTP method testSslSetHttpRequest.

@Test
public void testSslSetHttpRequest() throws Exception {
    final Map<String, String> sslProperties = new HashMap<>();
    sslProperties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
    sslProperties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
    sslProperties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
    sslProperties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
    sslProperties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
    sslProperties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
    runner = TestRunners.newTestRunner(InvokeHTTP.class);
    final StandardSSLContextService sslService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslService, sslProperties);
    runner.enableControllerService(sslService);
    runner.setProperty(InvokeHTTP.PROP_SSL_CONTEXT_SERVICE, "ssl-context");
    addHandler(new GetOrHeadHandler());
    runner.setProperty(InvokeHTTP.PROP_URL, url + "/status/200");
    createFlowFiles(runner);
    runner.run();
    runner.assertTransferCount(InvokeHTTP.REL_SUCCESS_REQ, 1);
    runner.assertTransferCount(InvokeHTTP.REL_RESPONSE, 1);
    runner.assertTransferCount(InvokeHTTP.REL_RETRY, 0);
    runner.assertTransferCount(InvokeHTTP.REL_NO_RETRY, 0);
    runner.assertTransferCount(InvokeHTTP.REL_FAILURE, 0);
    runner.assertPenalizeCount(0);
    // expected in request status.code and status.message
    // original flow file (+attributes)
    final MockFlowFile bundle = runner.getFlowFilesForRelationship(InvokeHTTP.REL_SUCCESS_REQ).get(0);
    bundle.assertContentEquals("Hello".getBytes("UTF-8"));
    bundle.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200");
    bundle.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK");
    bundle.assertAttributeEquals("Foo", "Bar");
    // expected in response
    // status code, status message, all headers from server response --> ff attributes
    // server response message body into payload of ff
    final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(InvokeHTTP.REL_RESPONSE).get(0);
    bundle1.assertContentEquals("/status/200".getBytes("UTF-8"));
    bundle1.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200");
    bundle1.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK");
    bundle1.assertAttributeEquals("Foo", "Bar");
    bundle1.assertAttributeEquals("Content-Type", "text/plain;charset=iso-8859-1");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Test(org.junit.Test)

Example 13 with StandardSSLContextService

use of org.apache.nifi.ssl.StandardSSLContextService in project nifi by apache.

the class TestListenHTTP method configureInvalidProcessorSslContextService.

private SSLContextService configureInvalidProcessorSslContextService() throws InitializationException {
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService(SSL_CONTEXT_SERVICE_IDENTIFIER, sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
    runner.setProperty(ListenHTTP.SSL_CONTEXT_SERVICE, SSL_CONTEXT_SERVICE_IDENTIFIER);
    return sslContextService;
}
Also used : StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService)

Example 14 with StandardSSLContextService

use of org.apache.nifi.ssl.StandardSSLContextService in project nifi by apache.

the class TestListenRELP method testTLS.

@Test
public void testTLS() throws InitializationException, IOException, InterruptedException {
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
    runner.enableControllerService(sslContextService);
    runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
    final List<RELPFrame> frames = new ArrayList<>();
    frames.add(OPEN_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(SYSLOG_FRAME);
    frames.add(CLOSE_FRAME);
    // three syslog frames should be transferred and three responses should be sent
    run(frames, 5, 5, sslContextService);
}
Also used : StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) ArrayList(java.util.ArrayList) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame) Test(org.junit.Test)

Example 15 with StandardSSLContextService

use of org.apache.nifi.ssl.StandardSSLContextService in project nifi by apache.

the class TestGetHTTP method useSSLContextService.

private void useSSLContextService(final Map<String, String> sslProperties) {
    final SSLContextService service = new StandardSSLContextService();
    try {
        controller.addControllerService("ssl-service", service, sslProperties);
        controller.enableControllerService(service);
    } catch (InitializationException ex) {
        ex.printStackTrace();
        Assert.fail("Could not create SSL Context Service");
    }
    controller.setProperty(GetHTTP.SSL_CONTEXT_SERVICE, "ssl-service");
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) InitializationException(org.apache.nifi.reporting.InitializationException)

Aggregations

StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)17 SSLContextService (org.apache.nifi.ssl.SSLContextService)11 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 Before (org.junit.Before)4 InitializationException (org.apache.nifi.reporting.InitializationException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 LivySessionController (org.apache.nifi.controller.livy.LivySessionController)1 ConsumeMQTT (org.apache.nifi.processors.mqtt.ConsumeMQTT)1 PublishMQTT (org.apache.nifi.processors.mqtt.PublishMQTT)1 RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)1 StandardRestrictedSSLContextService (org.apache.nifi.ssl.StandardRestrictedSSLContextService)1 FlowFileUnpackagerV3 (org.apache.nifi.util.FlowFileUnpackagerV3)1 MockFlowFile (org.apache.nifi.util.MockFlowFile)1