Repository: flume Updated Branches: refs/heads/trunk 1b4378396 -> c5168c902
http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/main/java/org/apache/flume/api/ThriftRpcClient.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/main/java/org/apache/flume/api/ThriftRpcClient.java b/flume-ng-sdk/src/main/java/org/apache/flume/api/ThriftRpcClient.java index 07d9c90..0048e61 100644 --- a/flume-ng-sdk/src/main/java/org/apache/flume/api/ThriftRpcClient.java +++ b/flume-ng-sdk/src/main/java/org/apache/flume/api/ThriftRpcClient.java @@ -24,6 +24,7 @@ import org.apache.flume.FlumeException; import org.apache.flume.thrift.Status; import org.apache.flume.thrift.ThriftFlumeEvent; import org.apache.flume.thrift.ThriftSourceProtocol; +import org.apache.flume.util.SSLUtil; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TCompactProtocol; import org.apache.thrift.transport.TFastFramedTransport; @@ -318,11 +319,13 @@ public class ThriftRpcClient extends AbstractRpcClient { RpcClientConfigurationConstants.CONFIG_SSL)); if (enableSsl) { truststore = properties.getProperty( - RpcClientConfigurationConstants.CONFIG_TRUSTSTORE); + RpcClientConfigurationConstants.CONFIG_TRUSTSTORE, SSLUtil.getGlobalTruststorePath()); truststorePassword = properties.getProperty( - RpcClientConfigurationConstants.CONFIG_TRUSTSTORE_PASSWORD); + RpcClientConfigurationConstants.CONFIG_TRUSTSTORE_PASSWORD, + SSLUtil.getGlobalTruststorePassword()); truststoreType = properties.getProperty( - RpcClientConfigurationConstants.CONFIG_TRUSTSTORE_TYPE, "JKS"); + RpcClientConfigurationConstants.CONFIG_TRUSTSTORE_TYPE, + SSLUtil.getGlobalTruststoreType("JKS")); String excludeProtocolsStr = properties.getProperty( RpcClientConfigurationConstants.CONFIG_EXCLUDE_PROTOCOLS); if (excludeProtocolsStr == null) { @@ -520,7 +523,8 @@ public class ThriftRpcClient extends AbstractRpcClient { KeyStore ts = null; if (truststore != null && truststoreType != null) { ts = KeyStore.getInstance(truststoreType); - ts.load(new FileInputStream(truststore), truststorePassword.toCharArray()); + ts.load(new FileInputStream(truststore), + truststorePassword != null ? truststorePassword.toCharArray() : null); tmf.init(ts); } http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/main/java/org/apache/flume/util/SSLUtil.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/main/java/org/apache/flume/util/SSLUtil.java b/flume-ng-sdk/src/main/java/org/apache/flume/util/SSLUtil.java new file mode 100644 index 0000000..02fe8ed --- /dev/null +++ b/flume-ng-sdk/src/main/java/org/apache/flume/util/SSLUtil.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SSLUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(SSLUtil.class); + + private static final String SYS_PROP_KEYSTORE_PATH = "javax.net.ssl.keyStore"; + private static final String SYS_PROP_KEYSTORE_PASSWORD = "javax.net.ssl.keyStorePassword"; + private static final String SYS_PROP_KEYSTORE_TYPE = "javax.net.ssl.keyStoreType"; + private static final String SYS_PROP_TRUSTSTORE_PATH = "javax.net.ssl.trustStore"; + private static final String SYS_PROP_TRUSTSTORE_PASSWORD = "javax.net.ssl.trustStorePassword"; + private static final String SYS_PROP_TRUSTSTORE_TYPE = "javax.net.ssl.trustStoreType"; + + private static final String ENV_VAR_KEYSTORE_PATH = "FLUME_SSL_KEYSTORE_PATH"; + private static final String ENV_VAR_KEYSTORE_PASSWORD = "FLUME_SSL_KEYSTORE_PASSWORD"; + private static final String ENV_VAR_KEYSTORE_TYPE = "FLUME_SSL_KEYSTORE_TYPE"; + private static final String ENV_VAR_TRUSTSTORE_PATH = "FLUME_SSL_TRUSTSTORE_PATH"; + private static final String ENV_VAR_TRUSTSTORE_PASSWORD = "FLUME_SSL_TRUSTSTORE_PASSWORD"; + private static final String ENV_VAR_TRUSTSTORE_TYPE = "FLUME_SSL_TRUSTSTORE_TYPE"; + + private static final String DESCR_KEYSTORE_PATH = "keystore path"; + private static final String DESCR_KEYSTORE_PASSWORD = "keystore password"; + private static final String DESCR_KEYSTORE_TYPE = "keystore type"; + private static final String DESCR_TRUSTSTORE_PATH = "truststore path"; + private static final String DESCR_TRUSTSTORE_PASSWORD = "truststore password"; + private static final String DESCR_TRUSTSTORE_TYPE = "truststore type"; + + public static void initGlobalSSLParameters() { + initSysPropFromEnvVar( + SYS_PROP_KEYSTORE_PATH, ENV_VAR_KEYSTORE_PATH, DESCR_KEYSTORE_PATH); + initSysPropFromEnvVar( + SYS_PROP_KEYSTORE_PASSWORD, ENV_VAR_KEYSTORE_PASSWORD, DESCR_KEYSTORE_PASSWORD); + initSysPropFromEnvVar( + SYS_PROP_KEYSTORE_TYPE, ENV_VAR_KEYSTORE_TYPE, DESCR_KEYSTORE_TYPE); + initSysPropFromEnvVar( + SYS_PROP_TRUSTSTORE_PATH, ENV_VAR_TRUSTSTORE_PATH, DESCR_TRUSTSTORE_PATH); + initSysPropFromEnvVar( + SYS_PROP_TRUSTSTORE_PASSWORD, ENV_VAR_TRUSTSTORE_PASSWORD, DESCR_TRUSTSTORE_PASSWORD); + initSysPropFromEnvVar( + SYS_PROP_TRUSTSTORE_TYPE, ENV_VAR_TRUSTSTORE_TYPE, DESCR_TRUSTSTORE_TYPE); + } + + private static void initSysPropFromEnvVar(String sysPropName, String envVarName, + String description) { + if (System.getProperty(sysPropName) != null) { + LOGGER.debug("Global SSL " + description + " has been initialized from system property."); + } else { + String envVarValue = System.getenv(envVarName); + if (envVarValue != null) { + System.setProperty(sysPropName, envVarValue); + LOGGER.debug("Global SSL " + description + + " has been initialized from environment variable."); + } else { + LOGGER.debug("No global SSL " + description + " specified."); + } + } + } + + public static String getGlobalKeystorePath() { + return System.getProperty(SYS_PROP_KEYSTORE_PATH); + } + + public static String getGlobalKeystorePassword() { + return System.getProperty(SYS_PROP_KEYSTORE_PASSWORD); + } + + public static String getGlobalKeystoreType(String defaultValue) { + String sysPropValue = System.getProperty(SYS_PROP_KEYSTORE_TYPE); + return sysPropValue != null ? sysPropValue : defaultValue; + } + + public static String getGlobalTruststorePath() { + return System.getProperty(SYS_PROP_TRUSTSTORE_PATH); + } + + public static String getGlobalTruststorePassword() { + return System.getProperty(SYS_PROP_TRUSTSTORE_PASSWORD); + } + + public static String getGlobalTruststoreType(String defaultValue) { + String sysPropValue = System.getProperty(SYS_PROP_TRUSTSTORE_TYPE); + return sysPropValue != null ? sysPropValue : defaultValue; + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java index 2eee0ef..8ae86e0 100644 --- a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java +++ b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java @@ -41,9 +41,9 @@ import java.util.concurrent.TimeoutException; public class TestThriftRpcClient { private static final String SEQ = "sequence"; private final Properties props = new Properties(); - ThriftRpcClient client; - ThriftTestingSource src; - int port; + private ThriftRpcClient client; + private ThriftTestingSource src; + private int port; @Before public void setUp() throws Exception { @@ -70,7 +70,7 @@ public class TestThriftRpcClient { * @param count * @throws Exception */ - public static void insertEvents(RpcClient client, int count) throws Exception { + private static void insertEvents(RpcClient client, int count) throws Exception { for (int i = 0; i < count; i++) { Map<String, String> header = new HashMap<String, String>(); header.put(SEQ, String.valueOf(i)); @@ -87,7 +87,7 @@ public class TestThriftRpcClient { * @throws Exception */ - public static void insertAsBatch(RpcClient client, int start, + private static void insertAsBatch(RpcClient client, int start, int limit) throws Exception { List<Event> events = new ArrayList<Event>(); for (int i = start; i <= limit; i++) { http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/AbstractSSLUtilTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/AbstractSSLUtilTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/AbstractSSLUtilTest.java new file mode 100644 index 0000000..944a485 --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/AbstractSSLUtilTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.After; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; + +@RunWith(Parameterized.class) +public abstract class AbstractSSLUtilTest { + + @Parameters + public static Collection<?> data() { + return Arrays.asList(new Object[][]{ + // system property value, environment variable value, expected value + { null, null, null }, + { "sysprop", null, "sysprop" }, + { null, "envvar", "envvar" }, + { "sysprop", "envvar", "sysprop" } + }); + } + + protected String sysPropValue; + protected String envVarValue; + protected String expectedValue; + + protected AbstractSSLUtilTest(String sysPropValue, String envVarValue, String expectedValue) { + this.sysPropValue = sysPropValue; + this.envVarValue = envVarValue; + this.expectedValue = expectedValue; + } + + protected abstract String getSysPropName(); + + protected abstract String getEnvVarName(); + + @Before + public void setUp() { + setSysProp(getSysPropName(), sysPropValue); + setEnvVar(getEnvVarName(), envVarValue); + } + + @After + public void tearDown() { + setSysProp(getSysPropName(), null); + setEnvVar(getEnvVarName(), null); + } + + private static void setSysProp(String name, String value) { + if (value != null) { + System.setProperty(name, value); + } else { + System.clearProperty(name); + } + } + + private static void setEnvVar(String name, String value) { + try { + injectEnvironmentVariable(name, value); + } catch (ReflectiveOperationException e) { + throw new AssertionError("Test setup failed.", e); + } + } + + // based on https://dzone.com/articles/how-to-change-environment-variables-in-java + private static void injectEnvironmentVariable(String key, String value) + throws ReflectiveOperationException { + Class<?> processEnvironment = Class.forName("java.lang.ProcessEnvironment"); + Field unmodifiableMapField = getAccessibleField(processEnvironment, + "theUnmodifiableEnvironment"); + Object unmodifiableMap = unmodifiableMapField.get(null); + injectIntoUnmodifiableMap(key, value, unmodifiableMap); + Field mapField = getAccessibleField(processEnvironment, "theEnvironment"); + Map<String, String> map = (Map<String, String>) mapField.get(null); + if (value != null) { + map.put(key, value); + } else { + map.remove(key); + } + } + + private static Field getAccessibleField(Class<?> clazz, String fieldName) + throws NoSuchFieldException { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + return field; + } + + private static void injectIntoUnmodifiableMap(String key, String value, Object map) + throws ReflectiveOperationException { + Class unmodifiableMap = Class.forName("java.util.Collections$UnmodifiableMap"); + Field field = getAccessibleField(unmodifiableMap, "m"); + Object obj = field.get(map); + if (value != null) { + ((Map<String, String>) obj).put(key, value); + } else { + ((Map<String, String>) obj).remove(key); + } + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePasswordTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePasswordTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePasswordTest.java new file mode 100644 index 0000000..c54b309 --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePasswordTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; + +public class SSLUtilKeystorePasswordTest extends AbstractSSLUtilTest { + + public SSLUtilKeystorePasswordTest(String sysPropValue, String envVarValue, + String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.keyStorePassword"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_KEYSTORE_PASSWORD"; + } + + @Test + public void testKeystorePassword() { + SSLUtil.initGlobalSSLParameters(); + String keystorePassword = SSLUtil.getGlobalKeystorePassword(); + + Assert.assertEquals(expectedValue, keystorePassword); + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePathTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePathTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePathTest.java new file mode 100644 index 0000000..a7b3206 --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystorePathTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; + +public class SSLUtilKeystorePathTest extends AbstractSSLUtilTest { + + public SSLUtilKeystorePathTest(String sysPropValue, String envVarValue, String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.keyStore"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_KEYSTORE_PATH"; + } + + @Test + public void testKeystorePath() { + SSLUtil.initGlobalSSLParameters(); + String keystorePath = SSLUtil.getGlobalKeystorePath(); + + Assert.assertEquals(expectedValue, keystorePath); + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeTest.java new file mode 100644 index 0000000..a8c00c7 --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; + +public class SSLUtilKeystoreTypeTest extends AbstractSSLUtilTest { + + public SSLUtilKeystoreTypeTest(String sysPropValue, String envVarValue, String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.keyStoreType"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_KEYSTORE_TYPE"; + } + + @Test + public void testKeystoreType() { + SSLUtil.initGlobalSSLParameters(); + String keystoreType = SSLUtil.getGlobalKeystoreType(null); + + Assert.assertEquals(expectedValue, keystoreType); + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeWithDefaultTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeWithDefaultTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeWithDefaultTest.java new file mode 100644 index 0000000..d30e30a --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilKeystoreTypeWithDefaultTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameters; + +import java.util.Arrays; +import java.util.Collection; + +public class SSLUtilKeystoreTypeWithDefaultTest extends AbstractSSLUtilTest { + + @Parameters + public static Collection<?> data() { + return Arrays.asList(new Object[][]{ + // system property value, environment variable value, expected value + { null, null, "default" }, + { "sysprop", null, "sysprop" }, + { null, "envvar", "envvar" }, + { "sysprop", "envvar", "sysprop" } + }); + } + + public SSLUtilKeystoreTypeWithDefaultTest(String sysPropValue, String envVarValue, + String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.keyStoreType"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_KEYSTORE_TYPE"; + } + + @Test + public void testKeystoreType() { + SSLUtil.initGlobalSSLParameters(); + String keystoreType = SSLUtil.getGlobalKeystoreType("default"); + + Assert.assertEquals(expectedValue, keystoreType); + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePasswordTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePasswordTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePasswordTest.java new file mode 100644 index 0000000..9d69d44 --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePasswordTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; + +public class SSLUtilTruststorePasswordTest extends AbstractSSLUtilTest { + + public SSLUtilTruststorePasswordTest(String sysPropValue, String envVarValue, + String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.trustStorePassword"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_TRUSTSTORE_PASSWORD"; + } + + @Test + public void testTruststorePassword() { + SSLUtil.initGlobalSSLParameters(); + String truststorePassword = SSLUtil.getGlobalTruststorePassword(); + + Assert.assertEquals(expectedValue, truststorePassword); + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePathTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePathTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePathTest.java new file mode 100644 index 0000000..c3e23c6 --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststorePathTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; + +public class SSLUtilTruststorePathTest extends AbstractSSLUtilTest { + + public SSLUtilTruststorePathTest(String sysPropValue, String envVarValue, String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.trustStore"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_TRUSTSTORE_PATH"; + } + + @Test + public void testTruststorePath() { + SSLUtil.initGlobalSSLParameters(); + String truststorePath = SSLUtil.getGlobalTruststorePath(); + + Assert.assertEquals(expectedValue, truststorePath); + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeTest.java new file mode 100644 index 0000000..5ef080b --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; + +public class SSLUtilTruststoreTypeTest extends AbstractSSLUtilTest { + + public SSLUtilTruststoreTypeTest(String sysPropValue, String envVarValue, String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.trustStoreType"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_TRUSTSTORE_TYPE"; + } + + @Test + public void testTruststoreType() { + SSLUtil.initGlobalSSLParameters(); + String truststoreType = SSLUtil.getGlobalTruststoreType(null); + + Assert.assertEquals(expectedValue, truststoreType); + } + +} http://git-wip-us.apache.org/repos/asf/flume/blob/c5168c90/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeWithDefaultTest.java ---------------------------------------------------------------------- diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeWithDefaultTest.java b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeWithDefaultTest.java new file mode 100644 index 0000000..34dda4f --- /dev/null +++ b/flume-ng-sdk/src/test/java/org/apache/flume/util/SSLUtilTruststoreTypeWithDefaultTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.flume.util; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameters; + +import java.util.Arrays; +import java.util.Collection; + +public class SSLUtilTruststoreTypeWithDefaultTest extends AbstractSSLUtilTest { + + @Parameters + public static Collection<?> data() { + return Arrays.asList(new Object[][]{ + // system property value, environment variable value, expected value + { null, null, "default" }, + { "sysprop", null, "sysprop" }, + { null, "envvar", "envvar" }, + { "sysprop", "envvar", "sysprop" } + }); + } + + public SSLUtilTruststoreTypeWithDefaultTest(String sysPropValue, String envVarValue, + String expectedValue) { + super(sysPropValue, envVarValue, expectedValue); + } + + @Override + protected String getSysPropName() { + return "javax.net.ssl.trustStoreType"; + } + + @Override + protected String getEnvVarName() { + return "FLUME_SSL_TRUSTSTORE_TYPE"; + } + + @Test + public void testTruststoreType() { + SSLUtil.initGlobalSSLParameters(); + String truststoreType = SSLUtil.getGlobalTruststoreType("default"); + + Assert.assertEquals(expectedValue, truststoreType); + } + +}
