Search in sources :

Example 66 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class JettyServerTest method testConfigureSslContextFactoryWithKeystorePasswordAndKeyPassword.

@Test
public void testConfigureSslContextFactoryWithKeystorePasswordAndKeyPassword() {
    // Expect that if we set both passwords, KeyStore password is used for KeyStore, Key password is used for Key Manager
    String testKeystorePassword = "testKeystorePassword";
    String testKeyPassword = "testKeyPassword";
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD, testKeystorePassword);
    addProps.put(NiFiProperties.SECURITY_KEY_PASSWD, testKeyPassword);
    NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
    SslContextFactory contextFactory = mock(SslContextFactory.class);
    JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
    verify(contextFactory).setKeyStorePassword(testKeystorePassword);
    verify(contextFactory).setKeyManagerPassword(testKeyPassword);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 67 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class JettyServerTest method testConfigureSslContextFactoryWithKeyPassword.

@Test
public void testConfigureSslContextFactoryWithKeyPassword() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
    // Expect that with no KeyStore password, we will only need to set Key Manager Password
    String testKeyPassword = "testKeyPassword";
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.SECURITY_KEY_PASSWD, testKeyPassword);
    NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
    SslContextFactory contextFactory = mock(SslContextFactory.class);
    JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
    verify(contextFactory).setKeyManagerPassword(testKeyPassword);
    verify(contextFactory, never()).setKeyStorePassword(anyString());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 68 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class JettyServerTest method testConfigureSslContextFactoryWithJksKeyStore.

@Test
public void testConfigureSslContextFactoryWithJksKeyStore() {
    // Expect that we will not set provider for jks keystore
    final Map<String, String> addProps = new HashMap<>();
    String keyStoreType = KeystoreType.JKS.toString();
    addProps.put(NiFiProperties.SECURITY_KEYSTORE_TYPE, keyStoreType);
    NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
    SslContextFactory contextFactory = mock(SslContextFactory.class);
    JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
    verify(contextFactory).setKeyStoreType(keyStoreType);
    verify(contextFactory, never()).setKeyStoreProvider(anyString());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 69 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TestVolatileContentRepository method testSimpleReadWrite.

@Test
public void testSimpleReadWrite() throws IOException {
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, TestVolatileContentRepository.class.getResource("/conf/nifi.properties").getFile());
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(VolatileContentRepository.MAX_SIZE_PROPERTY, "11 MB");
    final NiFiProperties nifiProps = NiFiProperties.createBasicNiFiProperties(null, addProps);
    final VolatileContentRepository contentRepo = new VolatileContentRepository(nifiProps);
    contentRepo.initialize(claimManager);
    final ContentClaim claim = contentRepo.create(true);
    final OutputStream out = contentRepo.write(claim);
    final int byteCount = 2398473 * 4;
    final byte[] x = new byte[4];
    x[0] = 48;
    x[1] = 29;
    x[2] = 49;
    x[3] = 51;
    for (int i = 0; i < byteCount / 4; i++) {
        out.write(x);
    }
    out.close();
    final InputStream in = contentRepo.read(claim);
    for (int i = 0; i < byteCount; i++) {
        final int val = in.read();
        final int index = i % 4;
        final byte expectedVal = x[index];
        assertEquals(expectedVal, val);
    }
    assertEquals(-1, in.read());
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) HashMap(java.util.HashMap) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 70 with NiFiProperties

use of org.apache.nifi.util.NiFiProperties in project nifi by apache.

the class TestVolatileContentRepository method testMemoryIsFreed.

@Test
public void testMemoryIsFreed() throws IOException, InterruptedException {
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, TestVolatileContentRepository.class.getResource("/conf/nifi.properties").getFile());
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(VolatileContentRepository.MAX_SIZE_PROPERTY, "11 MB");
    final NiFiProperties nifiProps = NiFiProperties.createBasicNiFiProperties(null, addProps);
    final VolatileContentRepository contentRepo = new VolatileContentRepository(nifiProps);
    contentRepo.initialize(claimManager);
    final byte[] oneK = new byte[1024];
    Arrays.fill(oneK, (byte) 55);
    final ExecutorService exec = Executors.newFixedThreadPool(10);
    for (int t = 0; t < 10; t++) {
        final Runnable r = new Runnable() {

            @Override
            public void run() {
                try {
                    for (int j = 0; j < 10000; j++) {
                        final ContentClaim claim = contentRepo.create(true);
                        final OutputStream out = contentRepo.write(claim);
                        // Write 1 MB to the repo
                        for (int i = 0; i < 1024; i++) {
                            out.write(oneK);
                        }
                        final int count = contentRepo.decrementClaimantCount(claim);
                        if (count <= 0) {
                            contentRepo.remove(claim);
                        }
                    }
                } catch (final Exception e) {
                    e.printStackTrace();
                }
            }
        };
        exec.submit(r);
    }
    exec.shutdown();
    exec.awaitTermination(100000, TimeUnit.MINUTES);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

NiFiProperties (org.apache.nifi.util.NiFiProperties)98 Test (org.junit.Test)63 HashMap (java.util.HashMap)28 Properties (java.util.Properties)24 File (java.io.File)16 Bundle (org.apache.nifi.bundle.Bundle)13 Matchers.anyString (org.mockito.Matchers.anyString)13 IOException (java.io.IOException)10 HashSet (java.util.HashSet)10 Map (java.util.Map)8 X509Certificate (java.security.cert.X509Certificate)7 Mockito.anyString (org.mockito.Mockito.anyString)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 SystemBundle (org.apache.nifi.nar.SystemBundle)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IdentityMapping (org.apache.nifi.authorization.util.IdentityMapping)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4