smiklosovic commented on a change in pull request #1027: URL: https://github.com/apache/cassandra/pull/1027#discussion_r694641338
########## File path: examples/security/test/unit/org/apache/cassandra/security/K8SecretsSslContextFactoryTest.java ########## @@ -0,0 +1,224 @@ +/* + * 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.cassandra.security; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class K8SecretsSslContextFactoryTest +{ + private static final Logger logger = LoggerFactory.getLogger(K8SecretsSslContextFactoryTest.class); + + private Map<String,Object> commonConfig = new HashMap<>(); + + private static class K8SecretsSslContextFactoryForTestOnly extends K8SecretsSslContextFactory { + + public K8SecretsSslContextFactoryForTestOnly() { + } + + public K8SecretsSslContextFactoryForTestOnly(Map<String,Object> config) { + super(config); + } + + /* + * This is overriden to first give priority to the input map configuration since we should not be setting env + * variables from the unit tests. However, if the input map configuration doesn't have the value for the + * given key then fallback to loading from the real environment variables. + */ + @Override + String getValueFromEnv(String envVarName, String defaultValue) { + String envVarValue = parameters.get(envVarName) != null ? parameters.get(envVarName).toString() : null; + if (StringUtils.isEmpty(envVarValue)) { + logger.info("Configuration doesn't have env variable {}. Will use parent's implementation", envVarName); + return super.getValueFromEnv(envVarName, defaultValue); + } else { + logger.info("Configuration has env variable {} with value {}. Will use that.", + envVarName, envVarValue); + return envVarValue; + } + } + } + + /* + private final String K8_SECRET_KEYSTORE_UPDATED_TIMESTAMP_ENV_VAR = "KEYSTORE_LAST_UPDATEDTIME"; + private final String K8_SECRET_TRUSTSTORE_UPDATED_TIMESTAMP_ENV_VAR = "TRUSTSTORE_LAST_UPDATEDTIME"; + */ + + @Before + public void setup() + { + commonConfig.put("TRUSTSTORE_PATH", "test/conf/cassandra_ssl_test.truststore"); Review comment: cant be this string a constant? similar for KEYSTORE_PATH, my idea is to somehow import it and reuse from K8SecretsSslContextFactory -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

