diff options
-rw-r--r-- | certService/pom.xml | 18 | ||||
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java | 2 | ||||
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java | 8 | ||||
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java | 9 | ||||
-rw-r--r-- | certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java | 9 | ||||
-rw-r--r-- | certServiceClient/pom.xml | 11 | ||||
-rw-r--r-- | certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClientApp.java (renamed from certServiceClient/src/main/java/org/onap/certservice/client/CertServiceClientApp.java) | 4 | ||||
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientAppTest.java | 33 | ||||
-rw-r--r-- | pom.xml | 28 |
9 files changed, 99 insertions, 23 deletions
diff --git a/certService/pom.xml b/certService/pom.xml index 03200dd3..a8a5296c 100644 --- a/certService/pom.xml +++ b/certService/pom.xml @@ -70,24 +70,6 @@ </dependencies> <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <version>${spring-boot-starter.version}</version> - </plugin> - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - <version>${maven-javadoc-plugin.version}</version> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>${maven-surefire-plugin.version}</version> - </plugin> - </plugins> - </pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java index 1b10c379..507ce3c1 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java +++ b/certService/src/main/java/org/onap/aaf/certservice/certification/CertificationModelFactory.java @@ -40,7 +40,7 @@ public class CertificationModelFactory { public CertificationModel createCertificationModel(CsrModel csr, String caName) { - LOGGER.info("Generating certificates for CA named: {}, and certificate signing request:\n{}", + LOGGER.info("Generating certification model for CA named: {}, and certificate signing request:\n{}", caName, csr); return new CertificationModel( Arrays.asList(ENTITY_CERT, INTERMEDIATE_CERT), diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java index 4abf4d04..f89c34e5 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java +++ b/certService/src/main/java/org/onap/aaf/certservice/certification/CsrModelFactory.java @@ -29,6 +29,8 @@ import org.onap.aaf.certservice.certification.exceptions.CsrDecryptionException; import org.onap.aaf.certservice.certification.exceptions.DecryptionException; import org.onap.aaf.certservice.certification.exceptions.KeyDecryptionException; import org.onap.aaf.certservice.certification.model.CsrModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -71,6 +73,7 @@ public class CsrModelFactory { public static class StringBase64 { private final String value; private final Base64.Decoder decoder = Base64.getDecoder(); + private static final Logger LOGGER = LoggerFactory.getLogger(StringBase64.class); public StringBase64(String value) { this.value = value; @@ -78,8 +81,11 @@ public class CsrModelFactory { public Optional<String> asString() { try { - return Optional.of(new String(decoder.decode(value))); + String decodedString = new String(decoder.decode(value)); + LOGGER.debug("Decoded string: {}", decodedString); + return Optional.of(decodedString); } catch(RuntimeException e) { + LOGGER.error("Exception occurred during decoding:", e); return Optional.empty(); } } diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java index 8f89de2f..b255b7c2 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java +++ b/certService/src/main/java/org/onap/aaf/certservice/certification/PKCS10CertificationRequestFactory.java @@ -21,17 +21,24 @@ package org.onap.aaf.certservice.certification; import org.bouncycastle.pkcs.PKCS10CertificationRequest; +import org.bouncycastle.util.encoders.DecoderException; import org.bouncycastle.util.io.pem.PemObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.Optional; public class PKCS10CertificationRequestFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(PKCS10CertificationRequestFactory.class); + public Optional<PKCS10CertificationRequest> createKCS10CertificationRequest(PemObject pemObject) { try { + LOGGER.debug("Creating certification request from pem object"); return Optional.of(new PKCS10CertificationRequest(pemObject.getContent())); - } catch (IOException e) { + } catch (DecoderException | IOException e) { + LOGGER.error("Exception occurred during creation of certification request:", e); return Optional.empty(); } } diff --git a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java index 514101b9..c2293d2d 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java +++ b/certService/src/main/java/org/onap/aaf/certservice/certification/PemObjectFactory.java @@ -24,18 +24,25 @@ import java.io.IOException; import java.io.StringReader; import java.util.Optional; +import org.bouncycastle.util.encoders.DecoderException; import org.bouncycastle.util.io.pem.PemObject; import org.bouncycastle.util.io.pem.PemReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PemObjectFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(PemObjectFactory.class); + public Optional<PemObject> createPemObject(String pem) { try (StringReader stringReader = new StringReader(pem); PemReader pemReader = new PemReader(stringReader)) { + LOGGER.debug("Creating pem object from: {}", pem); return Optional.ofNullable(pemReader.readPemObject()); - } catch (IOException e) { + } catch (DecoderException | IOException e) { + LOGGER.error("Exception occurred during creation of PEM:", e); return Optional.empty(); } } diff --git a/certServiceClient/pom.xml b/certServiceClient/pom.xml index 70cd38a7..2b4f2d02 100644 --- a/certServiceClient/pom.xml +++ b/certServiceClient/pom.xml @@ -27,5 +27,16 @@ </pluginManagement> </build> + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + </dependencies> + </project>
\ No newline at end of file diff --git a/certServiceClient/src/main/java/org/onap/certservice/client/CertServiceClientApp.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClientApp.java index 64d58633..f3b1c0f3 100644 --- a/certServiceClient/src/main/java/org/onap/certservice/client/CertServiceClientApp.java +++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClientApp.java @@ -1,4 +1,4 @@ -package org.onap.certservice.client;/* +/* * ============LICENSE_START======================================================= * aaf-certservice-client * ================================================================================ @@ -18,6 +18,8 @@ package org.onap.certservice.client;/* * ============LICENSE_END========================================================= */ +package org.onap.aaf.certservice.client; + public class CertServiceClientApp { public static void main(String[] args) { diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientAppTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientAppTest.java new file mode 100644 index 00000000..a79095c4 --- /dev/null +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientAppTest.java @@ -0,0 +1,33 @@ +/*============LICENSE_START======================================================= + * aaf-certservice-client + * ================================================================================ + * 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.aaf.certservice.client; + +import org.junit.jupiter.api.Test; + +class CertServiceClientAppTest { + // Sonar check for this test disabled due to lack of assertion in test. + // Intention of this test is to check if app runs without exiting Java. + @Test + public void mainShouldSucceed() { //NOSONAR + String[] params = {""}; + CertServiceClientApp.main(params); + } + +}
\ No newline at end of file @@ -52,6 +52,7 @@ <springdoc-openapi-maven-plugin.version>0.2</springdoc-openapi-maven-plugin.version> <gson.version>2.8.6</gson.version> <docker-maven-plugin.version>0.33.0</docker-maven-plugin.version> + <junit.version>5.6.0</junit.version> <!-- Docker --> <skipDockerPush>true</skipDockerPush> @@ -70,6 +71,27 @@ <module>certServiceClient</module> </modules> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${spring-boot-starter.version}</version> + </plugin> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <version>${maven-javadoc-plugin.version}</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${maven-surefire-plugin.version}</version> + </plugin> + </plugins> + </pluginManagement> + </build> + <distributionManagement> <repository> <id>ecomp-releases</id> @@ -155,6 +177,12 @@ <!-- Test dependecies --> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>${mockito-core.version}</version> |