Search in sources :

Example 6 with TlsClientConfig

use of org.apache.nifi.toolkit.tls.configuration.TlsClientConfig in project nifi by apache.

the class NifiPropertiesTlsClientConfigWriterTest method setup.

@Before
public void setup() throws IOException {
    testHostname = "testHostname";
    hostNum = 22;
    keyStore = "testKeyStore.jks";
    keyStoreType = TlsConfig.DEFAULT_KEY_STORE_TYPE;
    keyStorePassword = "badKeyStorePassword";
    keyPassword = "badKeyPassword";
    trustStore = "testTrustStore.jks";
    trustStoreType = TlsConfig.DEFAULT_KEY_STORE_TYPE;
    trustStorePassword = "badTrustStorePassword";
    outputFile = File.createTempFile("temp", "nifi");
    outputStream = new ByteArrayOutputStream();
    when(outputStreamFactory.create(outputFile)).thenReturn(outputStream);
    tlsClientConfig = new TlsClientConfig();
    tlsClientConfig.setKeyStore(keyStore);
    tlsClientConfig.setKeyStoreType(keyStoreType);
    tlsClientConfig.setKeyStorePassword(keyStorePassword);
    tlsClientConfig.setKeyPassword(keyPassword);
    tlsClientConfig.setTrustStore(trustStore);
    tlsClientConfig.setTrustStoreType(trustStoreType);
    tlsClientConfig.setTrustStorePassword(trustStorePassword);
    niFiPropertiesWriter = new NiFiPropertiesWriter(new ArrayList<>());
    when(niFiPropertiesWriterFactory.create()).thenReturn(niFiPropertiesWriter);
    nifiPropertiesTlsClientConfigWriter = new NifiPropertiesTlsClientConfigWriter(niFiPropertiesWriterFactory, outputFile, testHostname, hostNum);
    overlayProperties = nifiPropertiesTlsClientConfigWriter.getOverlayProperties();
}
Also used : NiFiPropertiesWriter(org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter) TlsClientConfig(org.apache.nifi.toolkit.tls.configuration.TlsClientConfig) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 7 with TlsClientConfig

use of org.apache.nifi.toolkit.tls.configuration.TlsClientConfig in project nifi by apache.

the class TlsCertificateAuthorityClientCommandLineTest method testKeyStoreType.

@Test
public void testKeyStoreType() throws CommandLineParseException, IOException {
    String testType = "testType";
    tlsCertificateAuthorityClientCommandLine.parse("-t", testToken, "-T", testType);
    TlsClientConfig clientConfig = tlsCertificateAuthorityClientCommandLine.createClientConfig();
    assertEquals(testType, clientConfig.getKeyStoreType());
    String trustStoreType = KeystoreType.JKS.toString().toLowerCase();
    assertEquals(trustStoreType, clientConfig.getTrustStoreType());
    assertEquals(TlsCertificateAuthorityClientCommandLine.KEYSTORE + testType.toLowerCase(), clientConfig.getKeyStore());
    assertEquals(TlsCertificateAuthorityClientCommandLine.TRUSTSTORE + trustStoreType, clientConfig.getTrustStore());
}
Also used : TlsClientConfig(org.apache.nifi.toolkit.tls.configuration.TlsClientConfig) Test(org.junit.Test)

Example 8 with TlsClientConfig

use of org.apache.nifi.toolkit.tls.configuration.TlsClientConfig in project nifi by apache.

the class TlsCertificateAuthorityClientCommandLineTest method testDefaults.

@Test
public void testDefaults() throws CommandLineParseException, IOException {
    tlsCertificateAuthorityClientCommandLine.parse("-t", testToken);
    TlsClientConfig clientConfig = tlsCertificateAuthorityClientCommandLine.createClientConfig();
    assertEquals(TlsConfig.DEFAULT_HOSTNAME, clientConfig.getCaHostname());
    Assert.assertEquals(new TlsConfig().calcDefaultDn(InetAddress.getLocalHost().getHostName()), clientConfig.getDn());
    assertEquals(TlsCertificateAuthorityClientCommandLine.KEYSTORE + TlsConfig.DEFAULT_KEY_STORE_TYPE.toLowerCase(), clientConfig.getKeyStore());
    assertEquals(TlsConfig.DEFAULT_KEY_STORE_TYPE, clientConfig.getKeyStoreType());
    assertNull(clientConfig.getKeyStorePassword());
    assertNull(clientConfig.getKeyPassword());
    assertEquals(TlsCertificateAuthorityClientCommandLine.TRUSTSTORE + TlsConfig.DEFAULT_KEY_STORE_TYPE.toLowerCase(), clientConfig.getTrustStore());
    assertEquals(TlsConfig.DEFAULT_KEY_STORE_TYPE, clientConfig.getTrustStoreType());
    assertNull(clientConfig.getTrustStorePassword());
    assertEquals(TlsConfig.DEFAULT_KEY_SIZE, clientConfig.getKeySize());
    assertEquals(TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM, clientConfig.getKeyPairAlgorithm());
    assertEquals(testToken, clientConfig.getToken());
    assertEquals(TlsConfig.DEFAULT_PORT, clientConfig.getPort());
    assertEquals(TlsCertificateAuthorityClientCommandLine.DEFAULT_CONFIG_JSON, tlsCertificateAuthorityClientCommandLine.getConfigJsonOut());
    assertNull(tlsCertificateAuthorityClientCommandLine.getConfigJsonIn());
    assertEquals(TlsCertificateAuthorityClientCommandLine.DEFAULT_CERTIFICATE_DIRECTORY, tlsCertificateAuthorityClientCommandLine.getCertificateDirectory());
}
Also used : TlsClientConfig(org.apache.nifi.toolkit.tls.configuration.TlsClientConfig) TlsConfig(org.apache.nifi.toolkit.tls.configuration.TlsConfig) Test(org.junit.Test)

Aggregations

TlsClientConfig (org.apache.nifi.toolkit.tls.configuration.TlsClientConfig)8 File (java.io.File)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 KeyStore (java.security.KeyStore)2 TlsConfig (org.apache.nifi.toolkit.tls.configuration.TlsConfig)2 NiFiPropertiesWriter (org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriter)2 NiFiPropertiesWriterFactory (org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriterFactory)2 OutputStreamFactory (org.apache.nifi.toolkit.tls.util.OutputStreamFactory)2 JcaMiscPEMGenerator (org.bouncycastle.openssl.jcajce.JcaMiscPEMGenerator)2 PemWriter (org.bouncycastle.util.io.pem.PemWriter)2 Before (org.junit.Before)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1