diff options
author | 2020-08-19 10:38:43 +0200 | |
---|---|---|
committer | 2020-08-27 15:02:07 +0200 | |
commit | 2512d60868bf25f91e4aa4b857d4ba373579f0fd (patch) | |
tree | e46d4010b6fc873facbf0222225eb822d3284dac /trustStoreMerger/src/test | |
parent | a1def56303f42c197156ed3862f733df32001bb7 (diff) |
Add Certification merge logic
Issue-ID: DCAEGEN2-2253
Signed-off-by: Tomasz Wrobel <tomasz.wrobel@nokia.com>
Change-Id: I4157ce71373b41d9f7ee03b76d407ec7a2b17ec3
Diffstat (limited to 'trustStoreMerger/src/test')
16 files changed, 807 insertions, 55 deletions
diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/TestCertificateProvider.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/TestCertificateProvider.java new file mode 100644 index 00000000..c971ca17 --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/TestCertificateProvider.java @@ -0,0 +1,157 @@ +/*============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.certification.file; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import org.onap.oom.truststoremerger.certification.file.exception.KeystoreInstanceException; +import org.onap.oom.truststoremerger.certification.file.exception.LoadTruststoreException; +import org.onap.oom.truststoremerger.certification.file.model.JavaTruststore; +import org.onap.oom.truststoremerger.certification.file.model.PemTruststore; +import org.onap.oom.truststoremerger.certification.file.provider.JavaCertificateStoreController; +import org.onap.oom.truststoremerger.certification.file.provider.CertificateStoreControllerFactory; +import org.onap.oom.truststoremerger.certification.file.provider.PemCertificateController; + +public class TestCertificateProvider { + + public static final String SAMPLE_P12_TRUSTSTORE_FILE_PATH = "src/test/resources/truststore-p12.p12"; + public static final String SAMPLE_P12_TRUSTSTORE_PASSWORD = "88y9v5D8H3SG6bZWRVHDfOAo"; + public static final String TMP_P12_TRUSTSTORE_FILE_PATH = "src/test/resources/tmp-truststore-p12.p12"; + + public static final String SAMPLE_P12_KEYSTORE_FILE_PATH = "src/test/resources/keystore.p12"; + public static final String SAMPLE_P12_KEYSTORE_PASSWORD = "Foh49MJNYI7S_pEzE9gvUDSu"; + + public static final String SAMPLE_JKS_TRUSTSTORE_FILE_PATH = "src/test/resources/truststore-jks.jks"; + public static final String SAMPLE_JKS_TRUSTSTORE_UNIQUE_ALIAS_FILE_PATH = "src/test/resources/truststore-jks-uniq.jks"; + public static final String SAMPLE_JKS_TRUSTSTORE_PASSWORD = "EOyuFbuYDyq_EhpboM72RHua"; + public static final String TMP_JKS_TRUSTSTORE_FILE_PATH = "src/test/resources/tmp-truststore-jks.jks"; + + public static final String SAMPLE_PEM_TRUSTSTORE_FILE_PATH = "src/test/resources/truststore.pem"; + public static final String EMPTY_PEM_TRUSTSTORE_FILE_PATH = "src/test/resources/empty-truststore.pem"; + public static final String TMP_PEM_TRUSTSTORE_FILE_PATH = "src/test/resources/tmp-truststore.pem"; + public static final String SAMPLE_PEM_TRUSTSTORE_WITH_PRIVATE_KEY_FILE_PATH = "src/test/resources/truststore-with-private-key.pem"; + + private static final CertificateStoreControllerFactory certificateStoreControllerFactory = new CertificateStoreControllerFactory(); + + public static JavaTruststore getSampleP12Truststore() throws LoadTruststoreException, KeystoreInstanceException { + return createP12TruststoreInstance(SAMPLE_P12_TRUSTSTORE_FILE_PATH, SAMPLE_P12_TRUSTSTORE_PASSWORD); + } + + public static JavaTruststore getSampleP12Keystore() throws LoadTruststoreException, KeystoreInstanceException { + return createP12TruststoreInstance(SAMPLE_P12_KEYSTORE_FILE_PATH, SAMPLE_P12_KEYSTORE_PASSWORD); + } + + public static JavaTruststore createTmpP12TruststoreFile() + throws IOException, LoadTruststoreException, KeystoreInstanceException { + copyFile(SAMPLE_P12_TRUSTSTORE_FILE_PATH, TMP_P12_TRUSTSTORE_FILE_PATH); + return createP12TruststoreInstance(TMP_P12_TRUSTSTORE_FILE_PATH, SAMPLE_P12_TRUSTSTORE_PASSWORD); + } + + public static JavaTruststore getTmpP12TruststoreFile() throws LoadTruststoreException, KeystoreInstanceException { + return createP12TruststoreInstance(TMP_P12_TRUSTSTORE_FILE_PATH, SAMPLE_P12_TRUSTSTORE_PASSWORD); + } + + private static JavaTruststore createP12TruststoreInstance(String filePath, String password) + throws LoadTruststoreException, KeystoreInstanceException { + File certFile = getFile(filePath); + JavaCertificateStoreController storeController = certificateStoreControllerFactory + .createLoadedPkcs12CertificateStoreController(certFile, password); + return new JavaTruststore(certFile, storeController); + } + + public static PemTruststore getSamplePemTruststoreFile() { + return getPemTruststoreInstance(SAMPLE_PEM_TRUSTSTORE_FILE_PATH); + } + + public static PemTruststore getEmptyPemTruststoreFile() { + return getPemTruststoreInstance(EMPTY_PEM_TRUSTSTORE_FILE_PATH); + } + + public static PemTruststore createEmptyTmpPemTruststoreFile() throws IOException { + copyFile(EMPTY_PEM_TRUSTSTORE_FILE_PATH, TMP_PEM_TRUSTSTORE_FILE_PATH); + return getPemTruststoreInstance(TMP_PEM_TRUSTSTORE_FILE_PATH); + } + + public static PemTruststore createTmpPemTruststoreFile() throws IOException { + copyFile(SAMPLE_PEM_TRUSTSTORE_FILE_PATH, TMP_PEM_TRUSTSTORE_FILE_PATH); + return getPemTruststoreInstance(TMP_PEM_TRUSTSTORE_FILE_PATH); + } + + public static PemTruststore getTmpPemTruststoreFile() { + return getPemTruststoreInstance(TMP_PEM_TRUSTSTORE_FILE_PATH); + } + + public static PemTruststore getPemWithPrivateKeyTruststoreFile() { + return getPemTruststoreInstance(SAMPLE_PEM_TRUSTSTORE_WITH_PRIVATE_KEY_FILE_PATH); + } + + public static String getExpectedPemCertificateAsString() throws IOException { + Path samplePemFilePath = Paths.get(SAMPLE_PEM_TRUSTSTORE_FILE_PATH); + return Files.readString(samplePemFilePath); + } + + public static JavaTruststore getSampleJksTruststoreFile() + throws LoadTruststoreException, KeystoreInstanceException { + return createJKSTruststoreInstance(SAMPLE_JKS_TRUSTSTORE_FILE_PATH, SAMPLE_JKS_TRUSTSTORE_PASSWORD); + } + + public static JavaTruststore getSampleJksTruststoreFileWithUniqueAlias() + throws LoadTruststoreException, KeystoreInstanceException { + return createJKSTruststoreInstance(SAMPLE_JKS_TRUSTSTORE_UNIQUE_ALIAS_FILE_PATH, + SAMPLE_JKS_TRUSTSTORE_PASSWORD); + } + + public static JavaTruststore createTmpJksTruststoreFileWithUniqAlias() + throws IOException, LoadTruststoreException, KeystoreInstanceException { + copyFile(SAMPLE_JKS_TRUSTSTORE_UNIQUE_ALIAS_FILE_PATH, TMP_JKS_TRUSTSTORE_FILE_PATH); + return createJKSTruststoreInstance(TMP_JKS_TRUSTSTORE_FILE_PATH, SAMPLE_JKS_TRUSTSTORE_PASSWORD); + } + + public static void removeTemporaryFiles() throws IOException { + Files.deleteIfExists(Paths.get(TMP_PEM_TRUSTSTORE_FILE_PATH)); + Files.deleteIfExists(Paths.get(TMP_JKS_TRUSTSTORE_FILE_PATH)); + Files.deleteIfExists(Paths.get(TMP_P12_TRUSTSTORE_FILE_PATH)); + } + + private static JavaTruststore createJKSTruststoreInstance(String filePath, String password) + throws LoadTruststoreException, KeystoreInstanceException { + File certFile = getFile(filePath); + JavaCertificateStoreController storeController = certificateStoreControllerFactory + .createLoadedJksCertificateStoreController(certFile, password); + return new JavaTruststore(certFile, storeController); + } + + private static PemTruststore getPemTruststoreInstance(String tmpPemTruststoreFilePath) { + File file = getFile(tmpPemTruststoreFilePath); + return new PemTruststore(file, new PemCertificateController(file)); + } + + private static void copyFile(String sourcePath, String destPath) throws IOException { + Files.copy(Paths.get(sourcePath), Paths.get(destPath), StandardCopyOption.REPLACE_EXISTING); + } + + private static File getFile(String path) { + return new File(path); + } +} diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/JavaTruststoreTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/JavaTruststoreTest.java new file mode 100644 index 00000000..eccf36bc --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/JavaTruststoreTest.java @@ -0,0 +1,116 @@ +/*============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.certification.file.model; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.oom.truststoremerger.api.CertificateConstants.X_509_CERTIFICATE; + +import java.io.IOException; +import java.security.cert.Certificate; +import java.util.List; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.onap.oom.truststoremerger.api.ExitableException; +import org.onap.oom.truststoremerger.certification.file.provider.entry.CertificateWithAlias; +import org.onap.oom.truststoremerger.certification.file.TestCertificateProvider; + + +class JavaTruststoreTest { + public static final int FIRST_ELEMENT = 0; + private static final int EXPECTED_ONE = 1; + public static final int EXPECTED_THREE = 3; + + @Test + void jksTruststoreShouldReadCertificatesFromFile() throws ExitableException { + + //given + JavaTruststore jksTruststoreFile = TestCertificateProvider.getSampleJksTruststoreFile(); + + //when + List<CertificateWithAlias> certificates = jksTruststoreFile.getCertificates(); + Certificate certificate = certificates.get(FIRST_ELEMENT).getCertificate(); + + //then + assertThat(certificates).hasSize(EXPECTED_ONE); + assertThat(certificate.getType()).isEqualTo(X_509_CERTIFICATE); + } + + @Test + void jksTruststoreShouldAddDifferentCertificates() throws Exception { + + //given + JavaTruststore jksTruststore = TestCertificateProvider.createTmpJksTruststoreFileWithUniqAlias(); + List<CertificateWithAlias> p12certificates = TestCertificateProvider.getSampleP12Truststore() + .getCertificates(); + List<CertificateWithAlias> pemCertificates = TestCertificateProvider.getSamplePemTruststoreFile() + .getCertificates(); + + //when + jksTruststore.addCertificate(p12certificates); + jksTruststore.addCertificate(pemCertificates); + + //then + assertThat(jksTruststore.getCertificates()).hasSize(EXPECTED_THREE); + + } + + @Test + void p12TruststoreShouldReadCertificatesFromFile() throws ExitableException { + //given + JavaTruststore p12Truststore = TestCertificateProvider.getSampleP12Truststore(); + + //when + List<CertificateWithAlias> certificatesWithAliases = p12Truststore.getCertificates(); + Certificate certificate = certificatesWithAliases.get(FIRST_ELEMENT).getCertificate(); + + //then + assertThat(certificatesWithAliases).hasSize(EXPECTED_ONE); + assertThat(certificate.getType()).isEqualTo(X_509_CERTIFICATE); + } + + + @Test + void p12TruststoreShouldAddDifferentCertificates() throws Exception { + //given + JavaTruststore p12Truststore = TestCertificateProvider.createTmpP12TruststoreFile(); + List<CertificateWithAlias> jksTruststoreCertificates = TestCertificateProvider + .getSampleJksTruststoreFileWithUniqueAlias() + .getCertificates(); + List<CertificateWithAlias> pemTruststoreCertificates = TestCertificateProvider.getSamplePemTruststoreFile() + .getCertificates(); + + //when + p12Truststore.addCertificate(jksTruststoreCertificates); + p12Truststore.addCertificate(pemTruststoreCertificates); + p12Truststore.saveFile(); + + + //then + JavaTruststore p12TruststoreSaved = TestCertificateProvider.getTmpP12TruststoreFile(); + assertThat(p12TruststoreSaved.getCertificates()).hasSize(EXPECTED_THREE); + } + + + + @AfterAll + static void removeTemporaryFiles() throws IOException { + TestCertificateProvider.removeTemporaryFiles(); + } +} diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/PemTruststoreTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/PemTruststoreTest.java new file mode 100644 index 00000000..e7ffa093 --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/PemTruststoreTest.java @@ -0,0 +1,149 @@ +/*============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.certification.file.model; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.onap.oom.truststoremerger.api.CertificateConstants.X_509_CERTIFICATE; + +import java.io.IOException; +import java.security.cert.Certificate; +import java.security.cert.CertificateEncodingException; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.onap.oom.truststoremerger.api.ExitableException; +import org.onap.oom.truststoremerger.certification.file.provider.entry.CertificateWithAlias; +import org.onap.oom.truststoremerger.certification.file.provider.entry.CertificateWithAliasFactory; +import org.onap.oom.truststoremerger.certification.file.TestCertificateProvider; +import org.onap.oom.truststoremerger.certification.file.exception.MissingTruststoreException; +import org.onap.oom.truststoremerger.certification.file.exception.TruststoreDataOperationException; +import org.onap.oom.truststoremerger.certification.file.exception.WriteTruststoreFileException; + +class PemTruststoreTest { + + public static final int EXPECTED_ONE = 1; + public static final int EXPECTED_THREE = 3; + public static final int FIRST_ELEMENT = 0; + + private final CertificateWithAliasFactory factory = new CertificateWithAliasFactory(); + + @Test + void pemTruststoreShouldReadCertificatesFromFile() throws ExitableException { + + //given + PemTruststore pemTruststore = TestCertificateProvider.getSamplePemTruststoreFile(); + + //when + List<CertificateWithAlias> certificates = pemTruststore.getCertificates(); + Certificate certificate = certificates.get(FIRST_ELEMENT).getCertificate(); + //then + + assertThat(certificates).hasSize(EXPECTED_ONE); + assertThat(certificate.getType()).isEqualTo(X_509_CERTIFICATE); + } + + @Test + void pemTruststoreShouldAddDifferentCertificates() throws IOException, ExitableException { + + //given + PemTruststore tmpPemTruststoreFile = TestCertificateProvider.createTmpPemTruststoreFile(); + List<CertificateWithAlias> jksTruststoreCertificates = TestCertificateProvider + .getSampleJksTruststoreFileWithUniqueAlias().getCertificates(); + List<CertificateWithAlias> p12TruststoreCertificates = TestCertificateProvider.getSampleP12Truststore() + .getCertificates(); + + //when + tmpPemTruststoreFile.addCertificate(jksTruststoreCertificates); + tmpPemTruststoreFile.addCertificate(p12TruststoreCertificates); + tmpPemTruststoreFile.saveFile(); + + PemTruststore tmpPemTruststoreSaved = TestCertificateProvider.getTmpPemTruststoreFile(); + List<CertificateWithAlias> addedCertificates = tmpPemTruststoreSaved.getCertificates(); + Certificate certificate = addedCertificates.get(FIRST_ELEMENT).getCertificate(); + + //then + assertThat(addedCertificates).hasSize(EXPECTED_THREE); + assertThat(certificate.getType()).isEqualTo(X_509_CERTIFICATE); + + } + + @Test + void privateKeyIsSkippedWhileReadingCertificates() throws ExitableException { + //given + PemTruststore pemTruststore = TestCertificateProvider.getPemWithPrivateKeyTruststoreFile(); + + //when + List<CertificateWithAlias> certificate = pemTruststore.getCertificates(); + //then + + assertThat(certificate).hasSize(EXPECTED_ONE); + } + + @Test + void shouldThrowExceptionWhenCannotSaveFile() throws IOException, ExitableException { + //given + PemTruststore tmpPemTruststoreFile = TestCertificateProvider.createTmpPemTruststoreFile(); + List<CertificateWithAlias> pemTruststoreCertificates = + TestCertificateProvider.getSamplePemTruststoreFile().getCertificates(); + //when + tmpPemTruststoreFile.addCertificate(pemTruststoreCertificates); + tmpPemTruststoreFile.getFile().setWritable(false); + //then + assertThatExceptionOfType(WriteTruststoreFileException.class) + .isThrownBy(tmpPemTruststoreFile::saveFile); + + } + + @Test + void shouldThrowExceptionWhenFileNotContainsCertificate() throws IOException { + //given + PemTruststore tmpPemTruststoreFile = TestCertificateProvider.createEmptyTmpPemTruststoreFile(); + //when//then + assertThatExceptionOfType(MissingTruststoreException.class) + .isThrownBy(tmpPemTruststoreFile::getCertificates); + } + + @Test + void shouldThrowExceptionWhenCannotConvertCertificateToPem() throws Exception { + //given + PemTruststore pemTruststore = TestCertificateProvider.createTmpPemTruststoreFile(); + Certificate certificate = mock(Certificate.class); + + when(certificate.getEncoded()).thenThrow(new CertificateEncodingException()); + + List<CertificateWithAlias> certificatesWithAliases = new ArrayList<>(); + certificatesWithAliases.add(factory.createPemCertificate(certificate)); + pemTruststore.addCertificate(certificatesWithAliases); + + //when //then + assertThatExceptionOfType(TruststoreDataOperationException.class) + .isThrownBy(pemTruststore::saveFile); + } + + @AfterAll + static void removeTemporaryFiles() throws IOException { + TestCertificateProvider.removeTemporaryFiles(); + } + +} diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/TruststoreTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/TruststoreTest.java new file mode 100644 index 00000000..eea1f9c7 --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/model/TruststoreTest.java @@ -0,0 +1,60 @@ +/*============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.certification.file.model; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.onap.oom.truststoremerger.certification.file.exception.CreateBackupException; +import org.onap.oom.truststoremerger.certification.file.provider.PemCertificateController; + +import static org.assertj.core.api.Assertions.assertThat; + +class TruststoreTest { + + private static final String PEM_FILE_PATH = "src/test/resources/truststore.pem"; + private static final String PEM_BACKUP_FILE_PATH = "src/test/resources/truststore.pem.bak"; + private static final String BACKUP_EXTENSION = ".bak"; + + + @Test + void createBackupShouldCreateFileWithExtension() throws CreateBackupException { + //given + File pemFile = new File(PEM_FILE_PATH); + Truststore truststore = new PemTruststore(pemFile, new PemCertificateController(pemFile)); + //when + truststore.createBackup(); + + //then + File backupFile = new File(PEM_BACKUP_FILE_PATH); + assertThat(backupFile.getName().endsWith(BACKUP_EXTENSION)).isTrue(); + assertThat(backupFile.isFile()).isTrue(); + } + + + @AfterAll + static void removeBackupFile() throws IOException { + Files.deleteIfExists(Paths.get(PEM_BACKUP_FILE_PATH)); + } + +} diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/FileManagerTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/FileManagerTest.java index d348dd7e..c649ba68 100644 --- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/FileManagerTest.java +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/FileManagerTest.java @@ -33,12 +33,13 @@ class FileManagerTest { @ParameterizedTest @CsvSource(value = { - "opt/app/truststore.jks:.jks", - "opt/app/truststore.p12:.p12", - "opt/app/truststore.pem:.pem", - "opt/app/truststore:''", + "opt/app/truststore.jks:.jks", + "opt/app/truststore.p12:.p12", + "opt/app/truststore.pem:.pem", + "opt/app/truststore.PEM:.pem", + "opt/app/truststore:''", }, delimiter = ':') - void shouldReturnCorrectExtension(String filePath, String expectedExtension){ + void shouldReturnCorrectExtension(String filePath, String expectedExtension) { String extension = fileManager.getExtension(new File(filePath)); assertThat(extension).isEqualTo(expectedExtension); } diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/JavaCertificateStoreControllerTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/JavaCertificateStoreControllerTest.java new file mode 100644 index 00000000..8ee77ef2 --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/JavaCertificateStoreControllerTest.java @@ -0,0 +1,59 @@ +/*============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.certification.file.provider; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.onap.oom.truststoremerger.certification.file.TestCertificateProvider.getSampleJksTruststoreFile; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.oom.truststoremerger.api.ExitableException; +import org.onap.oom.truststoremerger.certification.file.provider.entry.CertificateWithAlias; +import org.onap.oom.truststoremerger.certification.file.TestCertificateProvider; +import org.onap.oom.truststoremerger.certification.file.exception.AliasConflictException; +import org.onap.oom.truststoremerger.certification.file.exception.MissingTruststoreException; +import org.onap.oom.truststoremerger.certification.file.model.JavaTruststore; + +class JavaCertificateStoreControllerTest { + + + @Test + void throwExceptionWhenAliasConflictDetected() throws Exception { + //given + JavaTruststore p12Truststore = TestCertificateProvider.getSampleP12Truststore(); + List<CertificateWithAlias> jksTruststoreCertificates = getSampleJksTruststoreFile().getCertificates(); + + //when //then + assertThatExceptionOfType(AliasConflictException.class) + .isThrownBy(() -> p12Truststore.addCertificate(jksTruststoreCertificates)); + } + + + @Test + void throwExceptionWhenFileNotContainsTruststoreEntry() throws ExitableException { + //given + JavaTruststore p12Truststore = TestCertificateProvider.getSampleP12Keystore(); + + //when//then + assertThatExceptionOfType(MissingTruststoreException.class) + .isThrownBy(p12Truststore::getCertificates); + } + +} diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderTest.java index 712935ac..40eda4dd 100644 --- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderTest.java +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderTest.java @@ -22,6 +22,7 @@ package org.onap.oom.truststoremerger.certification.file.provider; import org.junit.jupiter.api.Test; import java.io.File; +import org.onap.oom.truststoremerger.certification.file.exception.PasswordReaderException; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/PemCertificateControllerTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/PemCertificateControllerTest.java new file mode 100644 index 00000000..080fcca3 --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/PemCertificateControllerTest.java @@ -0,0 +1,95 @@ +/*============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.certification.file.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.io.File; +import java.io.IOException; +import java.security.cert.Certificate; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; +import org.onap.oom.truststoremerger.api.ExitableException; +import org.onap.oom.truststoremerger.certification.file.provider.entry.CertificateWithAlias; +import org.onap.oom.truststoremerger.certification.file.TestCertificateProvider; +import org.onap.oom.truststoremerger.certification.file.exception.MissingTruststoreException; +import org.onap.oom.truststoremerger.certification.file.exception.TruststoreDataOperationException; +import org.onap.oom.truststoremerger.certification.file.model.PemTruststore; + +class PemCertificateControllerTest { + + @Test + void getNotEmptyCertificateListShouldThrowExceptionWhenFileNotContainsCertificate() { + //given + File emptyPemFile = TestCertificateProvider.getEmptyPemTruststoreFile().getFile(); + PemCertificateController pemCertificateController = new PemCertificateController(emptyPemFile); + //when//then + assertThatExceptionOfType(MissingTruststoreException.class) + .isThrownBy(pemCertificateController::getNotEmptyCertificateList); + } + + @Test + void transformToStringInPemFormatShouldCorrectlyTransform() throws ExitableException, IOException { + //given + PemTruststore pemTruststore = TestCertificateProvider.getSamplePemTruststoreFile(); + List<CertificateWithAlias> wrappedCertificates = pemTruststore.getCertificates(); + File notEmptyPemFile = pemTruststore.getFile(); + List<Certificate> certificateList = unWrapCertificate(wrappedCertificates); + PemCertificateController pemCertificateController = new PemCertificateController(notEmptyPemFile); + String expected = TestCertificateProvider.getExpectedPemCertificateAsString(); + + //when + String certificateTransformed = pemCertificateController.transformToStringInPemFormat(certificateList); + + //then + assertThat(certificateTransformed).isEqualTo(expected); + } + + @Test + void fileNotContainsPemCertificateShouldReturnTrueIfFileNotContainsCertificate() + throws TruststoreDataOperationException { + //given + File emptyPemFile = TestCertificateProvider.getEmptyPemTruststoreFile().getFile(); + PemCertificateController pemCertificateController = new PemCertificateController(emptyPemFile); + //when//then + assertThat(pemCertificateController.isFileWithoutPemCertificate()).isTrue(); + } + + @Test + void fileNotContainsPemCertificateShouldReturnFalseIfFileContainsCertificate() + throws TruststoreDataOperationException { + //given + File notEmptyPemFile = TestCertificateProvider.getSamplePemTruststoreFile().getFile(); + PemCertificateController pemCertificateController = new PemCertificateController(notEmptyPemFile); + + //when//then + assertThat(pemCertificateController.isFileWithoutPemCertificate()).isFalse(); + } + + private List<Certificate> unWrapCertificate(List<CertificateWithAlias> certificateWithAliases) { + return certificateWithAliases + .stream() + .map(CertificateWithAlias::getCertificate) + .collect(Collectors.toList()); + } + +} diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactoryTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFactoryTest.java index f00b2bc4..b2063cc3 100644 --- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactoryTest.java +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFactoryTest.java @@ -24,25 +24,27 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import org.onap.oom.truststoremerger.certification.file.JksTruststore; -import org.onap.oom.truststoremerger.certification.file.P12Truststore; -import org.onap.oom.truststoremerger.certification.file.PemTruststore; -import org.onap.oom.truststoremerger.certification.file.TruststoreFile; +import org.onap.oom.truststoremerger.certification.file.TruststoreFileFactory; +import org.onap.oom.truststoremerger.certification.file.model.JavaTruststore; +import org.onap.oom.truststoremerger.certification.file.model.PemTruststore; +import org.onap.oom.truststoremerger.certification.file.model.Truststore; +import org.onap.oom.truststoremerger.certification.file.exception.KeystoreInstanceException; +import org.onap.oom.truststoremerger.certification.file.exception.LoadTruststoreException; import java.io.File; +import org.onap.oom.truststoremerger.certification.file.exception.PasswordReaderException; +import org.onap.oom.truststoremerger.certification.file.exception.TruststoreFileFactoryException; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @ExtendWith(MockitoExtension.class) -class TruststoreFileFactoryTest { +class TruststoreFactoryTest { private static final String TRUSTSTORE_JKS_PATH = "src/test/resources/truststore-jks.jks"; private static final String TRUSTSTORE_JKS_PASS_PATH = "src/test/resources/truststore-jks.pass"; - private static final String TRUSTSTORE_JKS_PASS = "EOyuFbuYDyq_EhpboM72RHua"; private static final String TRUSTSTORE_P12_PATH = "src/test/resources/truststore-p12.p12"; private static final String TRUSTSTORE_P12_PASS_PATH = "src/test/resources/truststore-p12.pass"; - private static final String TRUSTSTORE_P12_PASS = "88y9v5D8H3SG6bZWRVHDfOAo"; private static final String TRUSTSTORE_PEM_PATH = "src/test/resources/truststore.pem"; private static final String EMPTY_PASS_PATH = ""; private static final String TRUSTSTORE_UNKNOWN_EXTENSION_PATH = "src/test/resources/truststore-jks.unknown"; @@ -56,28 +58,28 @@ class TruststoreFileFactoryTest { } @Test - void shouldReturnCorrectJksTruststoreForJksFile() throws TruststoreFileFactoryException, PasswordReaderException { - TruststoreFile truststore = truststoreFileFactory + void shouldReturnCorrectJksTruststoreForJksFile() + throws LoadTruststoreException, PasswordReaderException, TruststoreFileFactoryException, KeystoreInstanceException { + Truststore truststore = truststoreFileFactory .create(TRUSTSTORE_JKS_PATH, TRUSTSTORE_JKS_PASS_PATH); - assertThat(truststore).isInstanceOf(JksTruststore.class); - JksTruststore jksTruststore = (JksTruststore) truststore; - assertThat(jksTruststore.getPassword()).isEqualTo(TRUSTSTORE_JKS_PASS); - assertThat(jksTruststore.getTruststoreFile()).isEqualTo(new File(TRUSTSTORE_JKS_PATH)); + assertThat(truststore).isInstanceOf(JavaTruststore.class); + JavaTruststore jksTruststore = (JavaTruststore) truststore; + assertThat(jksTruststore.getFile()).isEqualTo(new File(TRUSTSTORE_JKS_PATH)); } @Test - void shouldReturnCorrectP12TruststoreForP12File() throws TruststoreFileFactoryException, PasswordReaderException { - TruststoreFile truststore = truststoreFileFactory + void shouldReturnCorrectP12TruststoreForP12File() + throws LoadTruststoreException, PasswordReaderException, TruststoreFileFactoryException, KeystoreInstanceException { + Truststore truststore = truststoreFileFactory .create(TRUSTSTORE_P12_PATH, TRUSTSTORE_P12_PASS_PATH); - assertThat(truststore).isInstanceOf(P12Truststore.class); - P12Truststore jksTruststore = (P12Truststore) truststore; - assertThat(jksTruststore.getPassword()).isEqualTo(TRUSTSTORE_P12_PASS); + assertThat(truststore).isInstanceOf(JavaTruststore.class); } @Test - void shouldReturnCorrectPemTruststoreForPemFile() throws TruststoreFileFactoryException, PasswordReaderException { - TruststoreFile truststore = truststoreFileFactory + void shouldReturnCorrectPemTruststoreForPemFile() + throws LoadTruststoreException, PasswordReaderException, TruststoreFileFactoryException, KeystoreInstanceException { + Truststore truststore = truststoreFileFactory .create(TRUSTSTORE_PEM_PATH, EMPTY_PASS_PATH); assertThat(truststore).isInstanceOf(PemTruststore.class); diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProviderTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProviderTest.java index 034e1b32..0dadcfef 100644 --- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProviderTest.java +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProviderTest.java @@ -22,15 +22,19 @@ package org.onap.oom.truststoremerger.certification.file.provider; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.onap.oom.truststoremerger.certification.file.JksTruststore; -import org.onap.oom.truststoremerger.certification.file.P12Truststore; -import org.onap.oom.truststoremerger.certification.file.PemTruststore; -import org.onap.oom.truststoremerger.certification.file.TruststoreFile; -import org.onap.oom.truststoremerger.certification.file.TruststoreFileWithPassword; +import org.onap.oom.truststoremerger.certification.file.TruststoreFileFactory; +import org.onap.oom.truststoremerger.certification.file.TruststoreFilesListProvider; +import org.onap.oom.truststoremerger.certification.file.model.JavaTruststore; +import org.onap.oom.truststoremerger.certification.file.model.PemTruststore; +import org.onap.oom.truststoremerger.certification.file.model.Truststore; +import org.onap.oom.truststoremerger.certification.file.exception.KeystoreInstanceException; +import org.onap.oom.truststoremerger.certification.file.exception.LoadTruststoreException; import java.io.File; import java.util.Arrays; import java.util.List; +import org.onap.oom.truststoremerger.certification.file.exception.PasswordReaderException; +import org.onap.oom.truststoremerger.certification.file.exception.TruststoreFileFactoryException; import static org.assertj.core.api.Assertions.assertThat; @@ -38,10 +42,8 @@ class TruststoreFilesListProviderTest { private static final String TRUSTSTORE_JKS_PATH = "src/test/resources/truststore-jks.jks"; private static final String TRUSTSTORE_JKS_PASS_PATH = "src/test/resources/truststore-jks.pass"; - private static final String TRUSTSTORE_JKS_PASS = "EOyuFbuYDyq_EhpboM72RHua"; private static final String TRUSTSTORE_P12_PATH = "src/test/resources/truststore-p12.p12"; private static final String TRUSTSTORE_P12_PASS_PATH = "src/test/resources/truststore-p12.pass"; - private static final String TRUSTSTORE_P12_PASS = "88y9v5D8H3SG6bZWRVHDfOAo"; private static final String TRUSTSTORE_PEM_PATH = "src/test/resources/truststore.pem"; private static final String EMPTY_PASS_PATH = ""; @@ -54,37 +56,32 @@ class TruststoreFilesListProviderTest { } @Test - void shouldReturnTruststoreFilesList() throws PasswordReaderException, TruststoreFileFactoryException { + void shouldReturnTruststoreFilesList() + throws TruststoreFileFactoryException, PasswordReaderException, LoadTruststoreException, KeystoreInstanceException { List<String> truststorePaths = Arrays.asList(TRUSTSTORE_JKS_PATH, TRUSTSTORE_P12_PATH, TRUSTSTORE_PEM_PATH); List<String> truststorePasswordPaths = Arrays.asList(TRUSTSTORE_JKS_PASS_PATH, TRUSTSTORE_P12_PASS_PATH, EMPTY_PASS_PATH); - List<TruststoreFile> truststoreFilesList = truststoreFilesListProvider.getTruststoreFilesList(truststorePaths, truststorePasswordPaths); + List<Truststore> truststoreFilesList = truststoreFilesListProvider.getTruststoreFilesList(truststorePaths, truststorePasswordPaths); assertThat(truststoreFilesList.size()).isEqualTo(3); - assertCorrectJksTruststore(truststoreFilesList.get(0), TRUSTSTORE_JKS_PATH, TRUSTSTORE_JKS_PASS); - assertCorrectP12Truststore(truststoreFilesList.get(1), TRUSTSTORE_P12_PATH, TRUSTSTORE_P12_PASS); + assertCorrectJksTruststore(truststoreFilesList.get(0), TRUSTSTORE_JKS_PATH); + assertCorrectP12Truststore(truststoreFilesList.get(1), TRUSTSTORE_P12_PATH); assertCorrectPemTruststore(truststoreFilesList.get(2), TRUSTSTORE_PEM_PATH); } - private void assertCorrectJksTruststore(TruststoreFile truststoreFile, String truststorePath, String truststorePass) { - assertCorrectTypeAndTruststorePath(truststoreFile, truststorePath, JksTruststore.class); - assertContainsCorrectPassword(truststoreFile, truststorePass); + private void assertCorrectJksTruststore(Truststore truststore, String truststorePath) { + assertCorrectTypeAndTruststorePath(truststore, truststorePath, JavaTruststore.class); } - private void assertCorrectP12Truststore(TruststoreFile truststoreFile, String truststorePath, String truststorePass) { - assertCorrectTypeAndTruststorePath(truststoreFile, truststorePath, P12Truststore.class); - assertContainsCorrectPassword(truststoreFile, truststorePass); + private void assertCorrectP12Truststore(Truststore truststore, String truststorePath) { + assertCorrectTypeAndTruststorePath(truststore, truststorePath, JavaTruststore.class); } - private void assertCorrectPemTruststore(TruststoreFile truststoreFile, String truststorePath) { - assertCorrectTypeAndTruststorePath(truststoreFile, truststorePath, PemTruststore.class); + private void assertCorrectPemTruststore(Truststore truststore, String truststorePath) { + assertCorrectTypeAndTruststorePath(truststore, truststorePath, PemTruststore.class); } - private void assertCorrectTypeAndTruststorePath(TruststoreFile truststoreFile, String truststorePath, Class<?> truststoreType) { - assertThat(truststoreFile).isInstanceOf(truststoreType); - assertThat(truststoreFile.getTruststoreFile()).isEqualTo(new File(truststorePath)); + private void assertCorrectTypeAndTruststorePath(Truststore truststore, String truststorePath, Class<?> truststoreType) { + assertThat(truststore).isInstanceOf(truststoreType); + assertThat(truststore.getFile()).isEqualTo(new File(truststorePath)); } - private void assertContainsCorrectPassword(TruststoreFile truststoreFile, String truststorePass) { - TruststoreFileWithPassword truststoreFileWithPassword = (TruststoreFileWithPassword) truststoreFile; - assertThat(truststoreFileWithPassword.getPassword()).isEqualTo(truststorePass); - } } diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/entry/PemAliasGeneratorTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/entry/PemAliasGeneratorTest.java new file mode 100644 index 00000000..0897de29 --- /dev/null +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/file/provider/entry/PemAliasGeneratorTest.java @@ -0,0 +1,58 @@ +/*============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.certification.file.provider.entry; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.HashSet; +import java.util.Set; +import org.junit.jupiter.api.Test; + +class PemAliasGeneratorTest { + + private final static String PREFIX_ALIAS_NAME = "pem-trusted-certificate-"; + static final int GENERATED_ALIASES_NUMBER = 100; + + @Test + void aliasHasPemPrefix() { + //given + PemAliasGenerator pemAliasGenerator = PemAliasGenerator.getInstance(); + //when + String alias = pemAliasGenerator.getAlias(); + //then + assertThat(alias.contains(PREFIX_ALIAS_NAME)).isTrue(); + } + + @Test + void generatedAliasesHaveUniqNames() { + //given + PemAliasGenerator pemAliasGenerator = PemAliasGenerator.getInstance(); + Set<String> aliases = new HashSet<>(); + + //when + for (int i = 0; i < GENERATED_ALIASES_NUMBER; i++) { + aliases.add(pemAliasGenerator.getAlias()); + } + + //then + assertThat(aliases).hasSize(GENERATED_ALIASES_NUMBER); + } + +} diff --git a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProviderTest.java b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProviderTest.java index 945a1077..38422d5c 100644 --- a/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProviderTest.java +++ b/trustStoreMerger/src/test/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProviderTest.java @@ -30,8 +30,8 @@ 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_ENV; -import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_ENV; +import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PATHS_ENV; +import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_PATHS_ENV; @ExtendWith(MockitoExtension.class) @@ -94,11 +94,11 @@ class TruststoresPathsProviderTest { } private void mockTruststoresEnv(String truststores) { - mockEnv(truststores, TRUSTSTORES_ENV); + mockEnv(truststores, TRUSTSTORES_PATHS_ENV); } private void mockTruststoresPasswordsEnv(String truststoresPasswords) { - mockEnv(truststoresPasswords, TRUSTSTORES_PASSWORDS_ENV); + mockEnv(truststoresPasswords, TRUSTSTORES_PASSWORDS_PATHS_ENV); } private void mockEnv(String envValue, String envName) { diff --git a/trustStoreMerger/src/test/resources/empty-truststore.pem b/trustStoreMerger/src/test/resources/empty-truststore.pem new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/trustStoreMerger/src/test/resources/empty-truststore.pem @@ -0,0 +1 @@ + diff --git a/trustStoreMerger/src/test/resources/keystore.p12 b/trustStoreMerger/src/test/resources/keystore.p12 Binary files differnew file mode 100644 index 00000000..bc047a98 --- /dev/null +++ b/trustStoreMerger/src/test/resources/keystore.p12 diff --git a/trustStoreMerger/src/test/resources/truststore-jks-uniq.jks b/trustStoreMerger/src/test/resources/truststore-jks-uniq.jks Binary files differnew file mode 100644 index 00000000..76ce8bc4 --- /dev/null +++ b/trustStoreMerger/src/test/resources/truststore-jks-uniq.jks diff --git a/trustStoreMerger/src/test/resources/truststore-with-private-key.pem b/trustStoreMerger/src/test/resources/truststore-with-private-key.pem new file mode 100644 index 00000000..95179062 --- /dev/null +++ b/trustStoreMerger/src/test/resources/truststore-with-private-key.pem @@ -0,0 +1,56 @@ +-----BEGIN CERTIFICATE----- +MIIEszCCAxugAwIBAgIUE+27eIlr12tQ+AMxkJTf2Y+ycOEwDQYJKoZIhvcNAQEL +BQAwYTEjMCEGCgmSJomT8ixkAQEME2MtMDRjYmE2YjhhMDQ5ODEyNGQxFTATBgNV +BAMMDE1hbmFnZW1lbnRDQTEjMCEGA1UECgwaRUpCQ0EgQ29udGFpbmVyIFF1aWNr +c3RhcnQwHhcNMjAwNzA4MTIzODU4WhcNMzAwNzA4MTIzODU4WjBhMSMwIQYKCZIm +iZPyLGQBAQwTYy0wNGNiYTZiOGEwNDk4MTI0ZDEVMBMGA1UEAwwMTWFuYWdlbWVu +dENBMSMwIQYDVQQKDBpFSkJDQSBDb250YWluZXIgUXV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