aboutsummaryrefslogtreecommitdiffstats
path: root/certServiceClient/src
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2020-03-02 11:16:09 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-02 11:16:09 +0000
commitbe552bb854e00ad79d0854304226829d0f969fb6 (patch)
treefb270306b183765edd2dc34265f3cf781d3faada /certServiceClient/src
parentcaa59bc41e4de0d52da73fe22e75e6e9134a0d1c (diff)
parente78bfe13bb52196ad84e68f4d4aa476aad1b6c52 (diff)
Merge "Add HttpClient"
Diffstat (limited to 'certServiceClient/src')
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java15
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java4
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java1
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/common/Base64Coder.java29
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/CloseableHttpClientProvider.java40
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java109
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/CertServiceApiResponseException.java42
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/HttpClientException.java37
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/CertServiceResponse.java44
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/ErrorCertServiceResponse.java40
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/CerServiceRequestTestData.java89
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java125
-rw-r--r--certServiceClient/src/test/resources/correctResponse10
-rw-r--r--certServiceClient/src/test/resources/expectedFirstElementOfCertificateChain21
-rw-r--r--certServiceClient/src/test/resources/expectedFirstElementOfTrustedCertificates22
-rw-r--r--certServiceClient/src/test/resources/missingPkResponse7
-rw-r--r--certServiceClient/src/test/resources/testCsr1
-rw-r--r--certServiceClient/src/test/resources/testPk1
18 files changed, 634 insertions, 3 deletions
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java
index 3e8f73eb..59d0c032 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java
@@ -28,12 +28,16 @@ import org.onap.aaf.certservice.client.configuration.factory.ClientConfiguration
import org.onap.aaf.certservice.client.configuration.factory.CsrConfigurationFactory;
import org.onap.aaf.certservice.client.configuration.model.ClientConfiguration;
import org.onap.aaf.certservice.client.configuration.model.CsrConfiguration;
+import org.onap.aaf.certservice.client.httpclient.CloseableHttpClientProvider;
+import org.onap.aaf.certservice.client.httpclient.HttpClient;
+import org.onap.aaf.certservice.client.httpclient.model.CertServiceResponse;
import java.security.KeyPair;
import static org.onap.aaf.certservice.client.api.ExitCode.SUCCESS_EXIT_CODE;
import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.KEY_SIZE;
import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM;
+import static org.onap.aaf.certservice.client.common.Base64Coder.encode;
public class CertServiceClient {
private AppExitHandler appExitHandler;
@@ -49,7 +53,16 @@ public class CertServiceClient {
CsrConfiguration csrConfiguration = new CsrConfigurationFactory(new EnvsForCsr()).create();
KeyPair keyPair = keyPairFactory.create();
CsrFactory csrFactory = new CsrFactory(csrConfiguration);
- String csr = csrFactory.createEncodedCsr(keyPair);
+
+ CloseableHttpClientProvider provider = new CloseableHttpClientProvider(clientConfiguration.getRequestTimeout());
+ HttpClient httpClient = new HttpClient(provider, clientConfiguration.getUrlToCertService());
+
+ CertServiceResponse certServiceData =
+ httpClient.retrieveCertServiceData(
+ clientConfiguration.getCaName(),
+ csrFactory.createEncodedCsr(keyPair),
+ encode(keyPair.getPrivate().toString()));
+
} catch (ExitableException e) {
appExitHandler.exit(e.applicationExitCode());
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java
index 45f2c400..b72a0e2d 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java
@@ -23,7 +23,9 @@ public enum ExitCode {
CLIENT_CONFIGURATION_EXCEPTION(1),
CSR_CONFIGURATION_EXCEPTION(2),
KEY_PAIR_GENERATION_EXCEPTION(3),
- CSR_GENERATION_EXCEPTION(4);
+ CSR_GENERATION_EXCEPTION(4),
+ CERT_SERVICE_API_CONNECTION_EXCEPTION(5),
+ HTTP_CLIENT_EXCEPTION(6);
private final int value;
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java
index 51981a48..f9166c96 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java
@@ -26,6 +26,5 @@ public abstract class ExitableException extends Exception {
public ExitableException(String message) {
super(message);
}
-
public abstract int applicationExitCode();
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/common/Base64Coder.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/common/Base64Coder.java
new file mode 100644
index 00000000..c066187d
--- /dev/null
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/common/Base64Coder.java
@@ -0,0 +1,29 @@
+/*
+ * ============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.common;
+
+import org.bouncycastle.util.encoders.Base64;
+
+public class Base64Coder {
+ public static String encode(String string){
+ return new String(Base64.encode(string.getBytes()));
+ }
+}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/CloseableHttpClientProvider.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/CloseableHttpClientProvider.java
new file mode 100644
index 00000000..ff29a14d
--- /dev/null
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/CloseableHttpClientProvider.java
@@ -0,0 +1,40 @@
+/*
+ * ============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.httpclient;
+
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+
+public class CloseableHttpClientProvider {
+
+ private final int timeout;
+
+ public CloseableHttpClientProvider(int timeout) {
+ this.timeout = timeout;
+ }
+
+ public CloseableHttpClient getClient() {
+ RequestConfig config =
+ RequestConfig.custom().setConnectionRequestTimeout(timeout).build();
+ return HttpClientBuilder.create().setDefaultRequestConfig(config).build();
+ }
+}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java
new file mode 100644
index 00000000..603d5848
--- /dev/null
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/HttpClient.java
@@ -0,0 +1,109 @@
+/*
+ * ============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.httpclient;
+
+import com.google.gson.Gson;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.onap.aaf.certservice.client.httpclient.exception.CertServiceApiResponseException;
+import org.onap.aaf.certservice.client.httpclient.exception.HttpClientException;
+import org.onap.aaf.certservice.client.httpclient.model.CertServiceResponse;
+import org.onap.aaf.certservice.client.httpclient.model.ErrorCertServiceResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public class HttpClient {
+
+ private static final String CSR_HEADER_NAME = "CSR";
+ private static final String PK_HEADER_NAME = "PK";
+ private static final String CHARSET_UTF_8 = "UTF-8";
+
+ private final Logger LOGGER = LoggerFactory.getLogger(HttpClient.class);
+
+ private final Gson gson = new Gson();
+ private final CloseableHttpClientProvider httpClientProvider;
+ private final String certServiceAddress;
+
+ public HttpClient(CloseableHttpClientProvider httpClientProvider, String certServiceAddress) {
+ this.httpClientProvider = httpClientProvider;
+ this.certServiceAddress = certServiceAddress;
+ }
+
+ public CertServiceResponse retrieveCertServiceData(String caName, String csr, String encodedPk)
+ throws CertServiceApiResponseException, HttpClientException {
+
+ try (CloseableHttpClient httpClient = httpClientProvider.getClient()) {
+ HttpResponse httpResponse = httpClient.execute(createHttpPayload(caName, csr, encodedPk));
+ return extractCertServiceResponse(httpResponse);
+
+ } catch (IOException e) {
+ LOGGER.error(String.format("Failed on communication between client and API for URL: '%s' . Exception message: '%s'",
+ certServiceAddress + caName, e.getMessage()));
+ throw new HttpClientException(e);
+ }
+ }
+
+ private int getStatusCode(HttpResponse httpResponse) {
+ return httpResponse.getStatusLine().getStatusCode();
+ }
+
+ private CertServiceResponse extractCertServiceResponse(HttpResponse httpResponse)
+ throws CertServiceApiResponseException, IOException {
+ int httpResponseCode = getStatusCode(httpResponse);
+ if (HttpStatus.SC_OK != httpResponseCode) {
+ LOGGER.error(String.format("Error on API response. Response Code: %d", httpResponseCode));
+ throw generateApiResponseException(httpResponse);
+ }
+ String jsonResponse = getStringResponse(httpResponse.getEntity());
+ return gson.fromJson(jsonResponse, CertServiceResponse.class);
+ }
+
+ private String getStringResponse(HttpEntity httpEntity) throws IOException {
+ return EntityUtils.toString(httpEntity, CHARSET_UTF_8);
+ }
+
+ private HttpGet createHttpPayload(String caName, String csr, String pk) {
+ String url = certServiceAddress + caName;
+ HttpGet httpGet = new HttpGet(url);
+ httpGet.addHeader(CSR_HEADER_NAME, csr);
+ httpGet.addHeader(PK_HEADER_NAME, pk);
+ return httpGet;
+ }
+
+
+ private CertServiceApiResponseException generateApiResponseException(HttpResponse httpResponse) throws IOException {
+ String stringResponse = getStringResponse(httpResponse.getEntity());
+ ErrorCertServiceResponse errorCertServiceResponse =
+ gson.fromJson(stringResponse, ErrorCertServiceResponse.class);
+
+ String messageFromApi = errorCertServiceResponse.getMessage();
+ String path = errorCertServiceResponse.getPath();
+ int httpResponseCode = getStatusCode(httpResponse);
+
+ return new CertServiceApiResponseException(certServiceAddress + path, httpResponseCode, messageFromApi);
+ }
+}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/CertServiceApiResponseException.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/CertServiceApiResponseException.java
new file mode 100644
index 00000000..40470af3
--- /dev/null
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/CertServiceApiResponseException.java
@@ -0,0 +1,42 @@
+/*
+ * ============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.httpclient.exception;
+
+import org.onap.aaf.certservice.client.api.ExitCode;
+import org.onap.aaf.certservice.client.api.ExitableException;
+
+public class CertServiceApiResponseException extends ExitableException {
+ private final ExitCode EXIT_CODE = ExitCode.CERT_SERVICE_API_CONNECTION_EXCEPTION;
+
+ public CertServiceApiResponseException(String url, int responseCode, String messageFromAPI) {
+
+ super(String.format("Request failed for URL '%s'. Response code: %d . Message from API: %s",
+ url,
+ responseCode,
+ messageFromAPI));
+ }
+
+ @Override
+ public int applicationExitCode() {
+ return EXIT_CODE.getValue();
+ }
+
+}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/HttpClientException.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/HttpClientException.java
new file mode 100644
index 00000000..d6fb1461
--- /dev/null
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/exception/HttpClientException.java
@@ -0,0 +1,37 @@
+/*
+ * ============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.httpclient.exception;
+
+import org.onap.aaf.certservice.client.api.ExitCode;
+import org.onap.aaf.certservice.client.api.ExitableException;
+
+public class HttpClientException extends ExitableException {
+ private final ExitCode EXIT_CODE = ExitCode.HTTP_CLIENT_EXCEPTION;
+
+ public HttpClientException(Throwable e) {
+ super(e);
+ }
+
+ @Override
+ public int applicationExitCode() {
+ return EXIT_CODE.getValue();
+ }
+}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/CertServiceResponse.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/CertServiceResponse.java
new file mode 100644
index 00000000..4ca17999
--- /dev/null
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/CertServiceResponse.java
@@ -0,0 +1,44 @@
+/*
+ * ============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.httpclient.model;
+
+import java.util.Collections;
+import java.util.List;
+
+public class CertServiceResponse {
+
+ private final List<String> certificateChain;
+ private final List<String> trustedCertificates;
+
+ public CertServiceResponse(List<String> certificateChain, List<String> trustedCertificates) {
+ this.certificateChain = certificateChain;
+ this.trustedCertificates = trustedCertificates;
+ }
+
+ public List<String> getCertificateChain() {
+ return Collections.unmodifiableList(certificateChain);
+ }
+
+ public List<String> getTrustedCertificates() {
+ return Collections.unmodifiableList(trustedCertificates);
+ }
+
+}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/ErrorCertServiceResponse.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/ErrorCertServiceResponse.java
new file mode 100644
index 00000000..6fe99ce5
--- /dev/null
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/httpclient/model/ErrorCertServiceResponse.java
@@ -0,0 +1,40 @@
+/*
+ * ============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.httpclient.model;
+
+public class ErrorCertServiceResponse {
+
+ private final String message;
+ private final String path;
+
+ public ErrorCertServiceResponse(String message, String path) {
+ this.message = message;
+ this.path = path;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getPath() {
+ return path;
+ }
+}
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CerServiceRequestTestData.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CerServiceRequestTestData.java
new file mode 100644
index 00000000..8f252c31
--- /dev/null
+++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CerServiceRequestTestData.java
@@ -0,0 +1,89 @@
+/*
+ * ============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 java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+public final class CerServiceRequestTestData {
+
+ private static final String RESOURCE_PATH = "src/test/resources/";
+
+ // Request parameters
+ public static final String CA_NAME = "TestCA";
+ public static final String CSR = getCsrValue();
+ public static final String PK = getPkValue();
+
+ // Correct response data
+ public static final String CORRECT_RESPONSE = getCorrectResponse();
+ public static final String EXPECTED_FIRST_ELEMENT_OF_CERTIFICATE_CHAIN =
+ getExpectedFirstElementOfCertificateChain();
+ public static final String EXPECTED_FIRST_ELEMENT_OF_TRUSTED_CERTIFICATES =
+ getExpectedFirstElementOfTrustedCertificates();
+
+ // Error response data
+ public static final String MISSING_PK_RESPONSE = getMissingPkResponse();
+
+ private CerServiceRequestTestData() {
+ }
+
+ private static String getMissingPkResponse() {
+ String fileName = "missingPkResponse";
+ return readFromFile(RESOURCE_PATH + fileName);
+ }
+
+ private static String getExpectedFirstElementOfTrustedCertificates() {
+
+ String fileName = "expectedFirstElementOfTrustedCertificates";
+ return readFromFile(RESOURCE_PATH + fileName);
+ }
+
+ private static String getExpectedFirstElementOfCertificateChain() {
+ String fileName = "expectedFirstElementOfCertificateChain";
+ return readFromFile(RESOURCE_PATH + fileName);
+ }
+
+ private static String getCorrectResponse() {
+ String fileName = "correctResponse";
+ return readFromFile(RESOURCE_PATH + fileName);
+ }
+
+ private static String getPkValue() {
+ String fileName = "testPk";
+ return readFromFile(RESOURCE_PATH + fileName);
+ }
+
+ private static String getCsrValue() {
+ String fileName = "testCsr";
+ return readFromFile(RESOURCE_PATH + fileName);
+ }
+
+ private static String readFromFile(String path) {
+ try {
+ return Files.readString(Paths.get(path), StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return "File not found";
+ }
+ }
+}
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java
new file mode 100644
index 00000000..f65aefdf
--- /dev/null
+++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/httpclient/HttpClientTest.java
@@ -0,0 +1,125 @@
+/*
+ * ============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.httpclient;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.aaf.certservice.client.api.ExitCode;
+import org.onap.aaf.certservice.client.httpclient.exception.CertServiceApiResponseException;
+import org.onap.aaf.certservice.client.httpclient.model.CertServiceResponse;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.List;
+
+import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
+import static java.net.HttpURLConnection.HTTP_OK;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.aaf.certservice.client.CerServiceRequestTestData.CA_NAME;
+import static org.onap.aaf.certservice.client.CerServiceRequestTestData.CORRECT_RESPONSE;
+import static org.onap.aaf.certservice.client.CerServiceRequestTestData.CSR;
+import static org.onap.aaf.certservice.client.CerServiceRequestTestData.EXPECTED_FIRST_ELEMENT_OF_CERTIFICATE_CHAIN;
+import static org.onap.aaf.certservice.client.CerServiceRequestTestData.EXPECTED_FIRST_ELEMENT_OF_TRUSTED_CERTIFICATES;
+import static org.onap.aaf.certservice.client.CerServiceRequestTestData.MISSING_PK_RESPONSE;
+import static org.onap.aaf.certservice.client.CerServiceRequestTestData.PK;
+
+class HttpClientTest {
+
+ private HttpClient httpClient;
+ private CloseableHttpClient closeableHttpClient;
+ private HttpEntity httpEntity;
+ private StatusLine statusLine;
+ private CloseableHttpResponse httpResponse;
+
+ @BeforeEach
+ void setUp() {
+
+ closeableHttpClient = mock(CloseableHttpClient.class);
+ httpEntity = mock(HttpEntity.class);
+ statusLine = mock(StatusLine.class);
+ httpResponse = mock(CloseableHttpResponse.class);
+
+ CloseableHttpClientProvider httpClientProvider = mock(CloseableHttpClientProvider.class);
+
+ when(httpClientProvider.getClient()).thenReturn(closeableHttpClient);
+ String testCertServiceAddress = "";
+ httpClient = new HttpClient(httpClientProvider, testCertServiceAddress);
+ }
+
+ @Test
+ void shouldReturnCorrectListsOfCertificatedChainsAndTrustedCertificates_WhenRequestDataIsCorrect()
+ throws Exception {
+
+ // given
+ mockServerResponse(HTTP_OK, CORRECT_RESPONSE);
+
+ // when
+ CertServiceResponse certServiceResponse =
+ httpClient.retrieveCertServiceData(CA_NAME, CSR, PK);
+ List<String> certificateChain = certServiceResponse.getCertificateChain();
+ List<String> trustedCertificate = certServiceResponse.getTrustedCertificates();
+
+ // then
+ assertNotNull(certServiceResponse);
+
+ final int expectedTwoElements = 2;
+ assertEquals(expectedTwoElements, certificateChain.size());
+ assertEquals(expectedTwoElements, trustedCertificate.size());
+
+ assertEquals(EXPECTED_FIRST_ELEMENT_OF_CERTIFICATE_CHAIN, certificateChain.get(0));
+ assertEquals(EXPECTED_FIRST_ELEMENT_OF_TRUSTED_CERTIFICATES, trustedCertificate.get(0));
+ }
+
+ @Test
+ void shouldThrowCertServiceApiResponseException_WhenPkHeaderIsMissing() throws Exception {
+
+ // given
+ mockServerResponse(HTTP_BAD_REQUEST, MISSING_PK_RESPONSE);
+
+ // when
+ CertServiceApiResponseException exception =
+ assertThrows(CertServiceApiResponseException.class,
+ () -> httpClient.retrieveCertServiceData(CA_NAME, CSR, ""));
+
+ // then
+ assertEquals(ExitCode.CERT_SERVICE_API_CONNECTION_EXCEPTION.getValue(), exception.applicationExitCode());
+ }
+
+ private void mockServerResponse(int serverCodeResponse, String stringResponse)
+ throws IOException {
+ when(statusLine.getStatusCode()).thenReturn(serverCodeResponse);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpResponse.getEntity()).thenReturn(httpEntity);
+ when(closeableHttpClient.execute(any(HttpGet.class))).thenReturn(httpResponse);
+
+ when(httpEntity.getContent()).thenReturn(new ByteArrayInputStream(stringResponse.getBytes()));
+ }
+}
diff --git a/certServiceClient/src/test/resources/correctResponse b/certServiceClient/src/test/resources/correctResponse
new file mode 100644
index 00000000..c7bf349e
--- /dev/null
+++ b/certServiceClient/src/test/resources/correctResponse
@@ -0,0 +1,10 @@
+{
+ "certificateChain": [
+ "-----BEGIN CERTIFICATE-----\nMIIDjDCCAnSgAwIBAgICEAIwDQYJKoZIhvcNAQELBQAwgYQxCzAJBgNVBAYTAlVT\nMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4tRnJhbmNpc2NvMRkw\nFwYDVQQKDBBMaW51eC1Gb3VuZGF0aW9uMQ0wCwYDVQQLDARPTkFQMR4wHAYDVQQD\nDBVpbnRlcm1lZGlhdGUub25hcC5vcmcwHhcNMjAwMjEyMDk1MTI2WhcNMjIxMTA4\nMDk1MTI2WjB7MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQG\nA1UEBwwNU2FuLUZyYW5jaXNjbzEZMBcGA1UECgwQTGludXgtRm91bmRhdGlvbjEN\nMAsGA1UECwwET05BUDEVMBMGA1UEAwwMdmlkLm9uYXAub3JnMIIBIjANBgkqhkiG\n9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw+GIRzJzUOh0gtc+wzFJEdTnn+q5F10L0Yhr\nG1xKdjPieHIFGsoiXwcuCU8arNSqlz7ocx62KQRkcA8y6edlOAsYtdOEJvqEI9vc\neyTB/HYsbzw3URPGch4AmibrQkKU9QvGwouHtHn4R2Ft2Y0tfEqv9hxj9v4njq4A\nEiDLAFLl5FmVyCZu/MtKngSgu1smcaFKTYySPMxytgJZexoa/ALZyyE0gRhsvwHm\nNLGCPt1bmE/PEGZybsCqliyTO0S56ncD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7sQrpuxerGNTmQWIcw6olXI0J+OOwkik\nII7elrYtd5G1uALxXWdamNsaY0Du34moVL1YjexJ7qQ4oBUxg2tuY8NAQGDK+23I\nnCA+ZwzdTJo73TYS6sx64d/YLWkX4nHGUoMlF+xUH34csDyhpuTSzQhC2quB5N8z\ntSFdpe4z2jqx07qo2EBFxi03EQ8Q0ex6l421QM2gbs7cZQ66K0DkpPcF2+iHZnyx\nxq1lnlsWHklElF2bhyXTn3fPp5wtan00P8IolKx7CAWb92QjkW6M0RvTW/xuwIzh\n0rTO\n-----END CERTIFICATE-----"
+ ]
+} \ No newline at end of file
diff --git a/certServiceClient/src/test/resources/expectedFirstElementOfCertificateChain b/certServiceClient/src/test/resources/expectedFirstElementOfCertificateChain
new file mode 100644
index 00000000..1cbbc8d3
--- /dev/null
+++ b/certServiceClient/src/test/resources/expectedFirstElementOfCertificateChain
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDjDCCAnSgAwIBAgICEAIwDQYJKoZIhvcNAQELBQAwgYQxCzAJBgNVBAYTAlVT
+MRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1TYW4tRnJhbmNpc2NvMRkw
+FwYDVQQKDBBMaW51eC1Gb3VuZGF0aW9uMQ0wCwYDVQQLDARPTkFQMR4wHAYDVQQD
+DBVpbnRlcm1lZGlhdGUub25hcC5vcmcwHhcNMjAwMjEyMDk1MTI2WhcNMjIxMTA4
+MDk1MTI2WjB7MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQG
+A1UEBwwNU2FuLUZyYW5jaXNjbzEZMBcGA1UECgwQTGludXgtRm91bmRhdGlvbjEN
+MAsGA1UECwwET05BUDEVMBMGA1UEAwwMdmlkLm9uYXAub3JnMIIBIjANBgkqhkiG
+9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw+GIRzJzUOh0gtc+wzFJEdTnn+q5F10L0Yhr
+G1xKdjPieHIFGsoiXwcuCU8arNSqlz7ocx62KQRkcA8y6edlOAsYtdOEJvqEI9vc
+eyTB/HYsbzw3URPGch4AmibrQkKU9QvGwouHtHn4R2Ft2Y0tfEqv9hxj9v4njq4A
+EiDLAFLl5FmVyCZu/MtKngSgu1smcaFKTYySPMxytgJZexoa/ALZyyE0gRhsvwHm
+NLGCPt1bmE/PEGZybsCqliyTO0S56ncD55The7+D/UDS4kE1Wg0svlWon/YsE6QW
+B3oeJDX7Kr8ebDTIAErevIAD7Sm4ee5se2zxYrsYlj0MzHZtvwIDAQABoxAwDjAM
+BgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCvQ1pTvjON6vSlcJRKSY4r
+8q7L4/9ZaVXWJAjzEYJtPIqsgGiPWz0vGfgklowU6tZxp9zRZFXfMil+mPQSe+yo
+ULrZSQ/z48YHPueE/BNO/nT4aaVBEhPLR5aVwC7uQVX8H+m1V1UGT8lk9vdI9rej
+CI9l524sLCpdE4dFXiWK2XHEZ0Vfylk221u3IYEogVVA+UMX7BFPSsOnI2vtYK/i
+lwZtlri8LtTusNe4oiTkYyq+RSyDhtAswg8ANgvfHolhCHoLFj6w1IkG88UCmbwN
+d7BoGMy06y5MJxyXEZG0vR7eNeLey0TIh+rAszAFPsIQvrOHW+HuA+WLQAj1mhnm
+-----END CERTIFICATE----- \ No newline at end of file
diff --git a/certServiceClient/src/test/resources/expectedFirstElementOfTrustedCertificates b/certServiceClient/src/test/resources/expectedFirstElementOfTrustedCertificates
new file mode 100644
index 00000000..2d36a220
--- /dev/null
+++ b/certServiceClient/src/test/resources/expectedFirstElementOfTrustedCertificates
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
+MIIDtzCCAp8CFAwqQddh4/iyGfP8UZ3dpXlxfAN8MA0GCSqGSIb3DQEBCwUAMIGX
+MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2Fu
+LUZyYW5jaXNjbzEZMBcGA1UECgwQTGludX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JW+p9oSrLDSdGC+pAKK
+m/wB+2VPIYcsPMtIhHC4tgoSaiCqjXYptaOh4b8ye8CPBUCpX/AYYkN0Ow==
+-----END CERTIFICATE----- \ No newline at end of file
diff --git a/certServiceClient/src/test/resources/missingPkResponse b/certServiceClient/src/test/resources/missingPkResponse
new file mode 100644
index 00000000..c53358e0
--- /dev/null
+++ b/certServiceClient/src/test/resources/missingPkResponse
@@ -0,0 +1,7 @@
+{
+ "timestamp": "2020-02-25T06:36:23.651+0000",
+ "status": 400,
+ "error": "Bad Request",
+ "message": "Missing request header 'PK' for method parameter of type String",
+ "path": "//v1/certificate/TestCA"
+} \ No newline at end of file
diff --git a/certServiceClient/src/test/resources/testCsr b/certServiceClient/src/test/resources/testCsr
new file mode 100644
index 00000000..aa9387bf
--- /dev/null
+++ b/certServiceClient/src/test/resources/testCsr
@@ -0,0 +1 @@
+LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS0tLS0KTUlJRExEQ0NBaFFDQVFBd2daQXhDekFKQmdOVkJBWVRBbEJNTVJZd0ZBWURWUVFJREExTWIzZGxjaTFUYVd4bGMybGhNUkF3RGdZRFZRUUhEQWRYY205amJHRjNNUTR3REFZRFZRUUtEQVZPYjJ0cFlURU5NQXNHQTFVRUN3d0VUMDVCVURFWE1CVUdBMVVFQXd3T2RHVnpkQzV1YjJ0cFlTNWpiMjB4SHpBZEJna3Foa2lHOXcwQkNRRVdFSFJsYzNSbGNrQnViMnRwWVM1amIyMHdnZ0VpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFERzMwWUZKMDk3bS83dDJQV1pFbExBNmJ5bFc5Z1k0cDNod3NidC9paENqKzFqRG9YRFdpQk0wMXVGd1BqWmNiaXhwR3BQdXdVU3ZWREUzOUtwUDFHS3NCYVcrMHdLZG02Sit4YmN6ZTBEc0N6QUhCTnNYVXJEK3VzZC9jVUxOVm5UeXRZYzZubkF1VSswQzg0U1l6OGVkVHJ4UWVkSmF4MDBaS3YrdHluVnZvWUtyVVFsMlFrTDI4bFhhaWsxdWIzd1FGeFNQdndEM2xuMU81N2k0Wk9hOHlNcWx2NlpsTkxZYng2UFhsc1RqanBWTldPUllPKzdzeWdieEZ0bHYvbEgyN1BISHZJT3BUUmtGd0lVLzRHWXU2blQ0bDBqYkl0VEE0b2dhUFR6b3hodG5jaStLT1VVeVZ4OWk4eWd3cVBUb3d5UFkyNGpSb2xTd3RBQWpDYkJBZ01CQUFHZ1ZqQlVCZ2txaGtpRzl3MEJDUTR4UnpCRk1FTUdBMVVkRVFROE1EcUNEM1JsYzNReUxtNXZhMmxoTG1OdmJZSVBkR1Z6ZEM1dWIyc3VhWFF1WTI5dGdoWjBaWE4wTG1sdWRDNXVaWFF1Ym05cmFXRXVZMjl0TUEwR0NTcUdTSWIzRFFFQkN3VUFBNElCQVFBUmRlNnpiT2R2TXdKSkFETGV0TmlXT0p3TU9Ec0RJeFduUDBjbXkwTVovb21KK21JZFJSb1NZV0t2VDl5OXd3a3A1Sllzb2htMUN4c0RvS1pBZHFWWTloeENMSUJWRktEL2FveUlRUzRhM3prZFBVa0lnWW00UzJxMkI3bTFjT2YxTHpYNzVSQ3BKN3N2SDZ3RFlqV2dEOTBsVW5uamphNUF2VnJTWnRCVUhEQWZsUG5DTmhXU3hMREhTSkZhWHhERkpGbjhpT1FhdDkvUmNERHc2M0lrbWVaLzBWWDhVRjRsaWp2VWcxSGc4WUFrdXVOQnNwTmRDY2FFVFZFUHJwS3BjaFQxdDg1YnA2RnppSHczc3ZCVTM2cmhzUGNQVU5IM1NYT2tVcmZlOXp0RmJzUFB4dmJtZWx1MWEwS2FudmhDbEU0Z1dMT2tWb1k2Q0hlUktYeU0KLS0tLS1FTkQgQ0VSVElGSUNBVEUgUkVRVUVTVC0tLS0t \ No newline at end of file
diff --git a/certServiceClient/src/test/resources/testPk b/certServiceClient/src/test/resources/testPk
new file mode 100644
index 00000000..36bc9834
--- /dev/null
+++ b/certServiceClient/src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