import org.onap.oom.truststoremerger.certification.file.provider.PasswordReader;
import org.onap.oom.truststoremerger.certification.file.TruststoreFileFactory;
import org.onap.oom.truststoremerger.certification.file.TruststoreFilesListProvider;
-import org.onap.oom.truststoremerger.certification.path.EnvProvider;
-import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProvider;
-import org.onap.oom.truststoremerger.configuration.MergerConfiguration;
-import org.onap.oom.truststoremerger.configuration.MergerConfigurationFactory;
-import org.onap.oom.truststoremerger.certification.path.PathValidator;
+import org.onap.oom.truststoremerger.configuration.path.TruststoresPathsProviderFactory;
+import org.onap.oom.truststoremerger.configuration.path.TruststoresPathsProvider;
+import org.onap.oom.truststoremerger.configuration.model.MergerConfiguration;
+import org.onap.oom.truststoremerger.configuration.MergerConfigurationProvider;
import java.util.List;
import org.slf4j.Logger;
}
private MergerConfiguration loadConfiguration() throws ExitableException {
- TruststoresPathsProvider truststoresPathsProvider = new TruststoresPathsProvider(new EnvProvider(),
- new PathValidator());
- MergerConfigurationFactory factory = new MergerConfigurationFactory(truststoresPathsProvider);
+ TruststoresPathsProvider truststoresPathsProvider = TruststoresPathsProviderFactory.create();
+ MergerConfigurationProvider factory = new MergerConfigurationProvider(truststoresPathsProvider);
return factory.createConfiguration();
}
package org.onap.oom.truststoremerger.configuration;
-import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProvider;
-import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProviderException;
-
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV;
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV;
import java.util.List;
+import org.onap.oom.truststoremerger.configuration.exception.MergerConfigurationException;
+import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
+import org.onap.oom.truststoremerger.configuration.model.MergerConfiguration;
+import org.onap.oom.truststoremerger.configuration.path.TruststoresPathsProvider;
-public class MergerConfigurationFactory {
+public class MergerConfigurationProvider {
private final TruststoresPathsProvider pathsProvider;
- public MergerConfigurationFactory(TruststoresPathsProvider pathsProvider) {
+ public MergerConfigurationProvider(TruststoresPathsProvider pathsProvider) {
this.pathsProvider = pathsProvider;
}
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.configuration;
+package org.onap.oom.truststoremerger.configuration.exception;
import org.onap.oom.truststoremerger.api.ExitStatus;
import org.onap.oom.truststoremerger.api.ExitableException;
public class MergerConfigurationException extends ExitableException {
- MergerConfigurationException(String message) {
+ public MergerConfigurationException(String message) {
super(message, ExitStatus.MERGER_CONFIGURATION_EXCEPTION);
}
}
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.path;
+package org.onap.oom.truststoremerger.configuration.exception;
import org.onap.oom.truststoremerger.api.ExitStatus;
import org.onap.oom.truststoremerger.api.ExitableException;
public class TruststoresPathsProviderException extends ExitableException {
- TruststoresPathsProviderException(String message) {
+ public TruststoresPathsProviderException(String message) {
super(message, ExitStatus.TRUSTSTORES_PATHS_PROVIDER_EXCEPTION);
}
}
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.configuration;
+package org.onap.oom.truststoremerger.configuration.model;
import java.util.Collections;
import java.util.List;
-public class MergerConfiguration {
+public final class MergerConfiguration {
private final List<String> truststoreFilePaths;
private final List<String> truststoreFilePasswordPaths;
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.path;
+package org.onap.oom.truststoremerger.configuration.path;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class EnvProvider {
+class EnvProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(EnvProvider.class);
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.path;
+package org.onap.oom.truststoremerger.configuration.path;
-public class PathValidator {
+class PathValidator {
private static final String TRUSTSTORE_PATH_REGEX = "^(/[a-zA-Z0-9_-]+)+\\.(pem|jks|p12)";
private static final String TRUSTSTORE_PASSWORD_PATH_REGEX = "^(/[a-zA-Z0-9_-]+)+\\.pass";
- public boolean isTruststorePathValid(String truststorePath) {
+ boolean isTruststorePathValid(String truststorePath) {
return isPathValid(truststorePath, TRUSTSTORE_PATH_REGEX);
}
- public boolean isTruststorePasswordPathValid(String truststorePasswordPath) {
+ boolean isTruststorePasswordPathValid(String truststorePasswordPath) {
return truststorePasswordPath.isEmpty() || isPathValid(truststorePasswordPath, TRUSTSTORE_PASSWORD_PATH_REGEX);
}
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.path;
+package org.onap.oom.truststoremerger.configuration.path;
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV;
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
+import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
public class TruststoresPathsProvider {
private final EnvProvider envProvider;
private final PathValidator pathValidator;
- public TruststoresPathsProvider(EnvProvider envProvider, PathValidator pathValidator) {
+ TruststoresPathsProvider(EnvProvider envProvider, PathValidator pathValidator) {
this.envProvider = envProvider;
this.pathValidator = pathValidator;
}
--- /dev/null
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.configuration.path;
+
+public class TruststoresPathsProviderFactory {
+
+ private TruststoresPathsProviderFactory() {
+ }
+
+ public static TruststoresPathsProvider create() {
+ return new TruststoresPathsProvider(new EnvProvider(), new PathValidator());
+ }
+}
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProvider;
-import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProviderException;
import java.util.ArrayList;
import java.util.List;
+import org.onap.oom.truststoremerger.configuration.exception.MergerConfigurationException;
+import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
+import org.onap.oom.truststoremerger.configuration.model.MergerConfiguration;
+import org.onap.oom.truststoremerger.configuration.path.TruststoresPathsProvider;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
-class MergerConfigurationFactoryTest {
+class MergerConfigurationProviderTest {
private static final String BASE_TRUSTSTORE_PATH = "/opt/app/truststore_";
private static final String TRUSTSTORE_EXTENSION = ".jks";
@Mock
private TruststoresPathsProvider pathsProvider;
- private MergerConfigurationFactory factory;
+ private MergerConfigurationProvider factory;
@BeforeEach
void setUp() {
- factory = new MergerConfigurationFactory(pathsProvider);
+ factory = new MergerConfigurationProvider(pathsProvider);
}
@Test
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.path;
+package org.onap.oom.truststoremerger.configuration.path;
+
+import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import static org.assertj.core.api.Assertions.assertThat;
-
class PathValidatorTest {
private final PathValidator validator = new PathValidator();
@ParameterizedTest()
@ValueSource(strings = {"/opt/app/truststore.pem", "/opt/app/truststore.jks",
- "/opt/app/truststore.p12", "/truststore.pem"})
+ "/opt/app/truststore.p12", "/truststore.pem"})
void shouldAcceptValidTruststorePaths(String path) {
assertThat(validator.isTruststorePathValid(path)).isTrue();
}
@ParameterizedTest()
@ValueSource(strings = {"/opt/app/truststore.pass", "/opt/app/truststore.invalid", "/",
- "truststore", "opt/app/truststore.p12", "/?.pem", "/.pem"})
- void shouldRejectInValidTruststorePaths(String path) {
+ "truststore", "opt/app/truststore.p12", "/?.pem", "/.pem"})
+ void shouldRejectInvalidTruststorePaths(String path) {
assertThat(validator.isTruststorePathValid(path)).isFalse();
}
@ParameterizedTest()
@ValueSource(strings = {"/opt/app/truststore.pem", "/opt/app/truststore.jks",
- "/opt/app/truststore.p12", "/", "truststore", "opt/app/truststore.p12", "/?.pass", "/.pass"})
- void shouldRejectInValidTruststorePasswordPaths(String path) {
+ "/opt/app/truststore.p12", "/", "truststore", "opt/app/truststore.p12", "/?.pass", "/.pass"})
+ void shouldRejectInvalidTruststorePasswordPaths(String path) {
assertThat(validator.isTruststorePasswordPathValid(path)).isFalse();
}
--- /dev/null
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.configuration.path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class TruststoresPathsProviderFactoryTest {
+
+ @Test
+ void shouldReturnCorrectObject() {
+ // given, when, then
+ assertThat(TruststoresPathsProviderFactory.create()).isInstanceOf(TruststoresPathsProvider.class);
+ }
+
+}
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.path;
+package org.onap.oom.truststoremerger.configuration.path;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.mockito.Mockito.when;
+import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV;
+import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV;
+
+import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Optional;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.mockito.Mockito.when;
-import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV;
-import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV;
+import org.onap.oom.truststoremerger.configuration.exception.TruststoresPathsProviderException;
@ExtendWith(MockitoExtension.class)
private static final String VALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.pem";
private static final String VALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:";
+ private static final String VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE = "/opt/app/certificates/truststore.pass::/etc/truststore.pass";
private static final String INVALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.invalid";
private static final String INVALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:/.pass";
mockTruststoresEnv(VALID_TRUSTSTORES);
assertThat(truststoresPathsProvider.getTruststores())
- .contains("/opt/app/certificates/truststore.jks",
- "/opt/app/certificates/truststore.pem");
+ .containsSequence("/opt/app/certificates/truststore.jks",
+ "/opt/app/certificates/truststore.pem");
}
@Test
mockTruststoresPasswordsEnv(VALID_TRUSTSTORES_PASSWORDS);
assertThat(truststoresPathsProvider.getTruststoresPasswords())
- .contains("/opt/app/certificates/truststore.pass",
- "");
+ .containsSequence("/opt/app/certificates/truststore.pass", "");
+ }
+
+ @Test
+ void shouldReturnCorrectListWhenTruststoresPasswordsContainsEmptyPathsInTheMiddle()
+ throws TruststoresPathsProviderException {
+ mockTruststoresPasswordsEnv(VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE);
+
+ assertThat(truststoresPathsProvider.getTruststoresPasswords()).containsSequence(
+ "/opt/app/certificates/truststore.pass",
+ "",
+ "/etc/truststore.pass"
+ );
}
@Test
mockTruststoresEnv("");
assertThatExceptionOfType(TruststoresPathsProviderException.class)
- .isThrownBy(truststoresPathsProvider::getTruststores);
+ .isThrownBy(truststoresPathsProvider::getTruststores);
}
@Test
mockTruststoresEnv(INVALID_TRUSTSTORES);
assertThatExceptionOfType(TruststoresPathsProviderException.class)
- .isThrownBy(truststoresPathsProvider::getTruststores);
+ .isThrownBy(truststoresPathsProvider::getTruststores);
}
@Test
mockTruststoresPasswordsEnv(INVALID_TRUSTSTORES_PASSWORDS);
assertThatExceptionOfType(TruststoresPathsProviderException.class)
- .isThrownBy(truststoresPathsProvider::getTruststoresPasswords);
+ .isThrownBy(truststoresPathsProvider::getTruststoresPasswords);
}
private void mockTruststoresEnv(String truststores) {
}
private void mockEnv(String envValue, String envName) {
- when(envProvider.getEnv(envName))
- .thenReturn(Optional.of(envValue));
+ when(envProvider.getEnv(envName)).thenReturn(Optional.of(envValue));
}
}