aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-12-06 22:51:41 +0000
committerGerrit Code Review <gerrit@onap.org>2018-12-06 22:51:41 +0000
commitbaf3f278fce6bcc15b4db1219be66e091530b1ee (patch)
treee64f58040457339b5a99ca8ab0f0739678b35761 /mso-api-handlers
parent3e54398897655230f1a524321ac4783f332a4bd4 (diff)
parent7882eaefffb7f4927f2bde9fb9ab91582004cc66 (diff)
Merge "grm clients use encrypted auth loading"
Diffstat (limited to 'mso-api-handlers')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java19
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java172
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json145
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml3
4 files changed, 327 insertions, 12 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
index f83e707258..60a05d74e5 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
@@ -32,15 +32,14 @@ import org.springframework.context.ApplicationContext;
public class GrmClientPropertiesImpl implements GRMProperties {
private String grmEndpoint;
- private String grmUsername;
- private String grmPassword;
+ private String grmAuth;
+ private String grmKey;
public GrmClientPropertiesImpl() {
- ApplicationContext context = SpringContextHelper.getAppContext();
-
+ ApplicationContext context = SpringContextHelper.getAppContext();
grmEndpoint = context.getEnvironment().getProperty("mso.grm.endpoint");
- grmUsername = context.getEnvironment().getProperty("mso.grm.username");
- grmPassword = context.getEnvironment().getProperty("mso.grm.password");
+ grmAuth = context.getEnvironment().getProperty("mso.grm.auth");
+ grmKey = context.getEnvironment().getProperty("mso.msoKey");
}
@Override
@@ -59,13 +58,13 @@ public class GrmClientPropertiesImpl implements GRMProperties {
}
@Override
- public String getUsername() {
- return grmUsername;
+ public String getAuth() {
+ return grmAuth;
}
@Override
- public String getPassword() {
- return grmPassword;
+ public String getKey() {
+ return grmKey;
}
@Override
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java
new file mode 100644
index 0000000000..6555a9a66e
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java
@@ -0,0 +1,172 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.grm;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.matching;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.apihandlerinfra.BaseTest;
+import org.onap.so.apihandlerinfra.TestAppender;
+import org.onap.so.client.grm.GRMClient;
+import org.onap.so.client.grm.beans.ServiceEndPoint;
+import org.onap.so.client.grm.beans.ServiceEndPointList;
+import org.onap.so.client.grm.beans.ServiceEndPointLookupRequest;
+import org.onap.so.client.grm.beans.ServiceEndPointRequest;
+import org.onap.so.client.grm.exceptions.GRMClientCallFailed;
+import org.slf4j.MDC;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+
+
+public class GRMClientTest extends BaseTest{
+
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private static final String uuidRegex = "(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-5][0-9a-f]{3}-?[089ab][0-9a-f]{3}-?[0-9a-f]{12}$";
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ System.setProperty("mso.config.path", "src/test/resources");
+ }
+
+ @Test
+ public void testFind() throws Exception {
+ TestAppender.events.clear();
+ String endpoints = getFileContentsAsString("__files/grm/endpoints.json");
+ stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning"))
+ .willReturn(aResponse()
+ .withStatus(200)
+ .withHeader("Content-Type", MediaType.APPLICATION_JSON)
+ .withBody(endpoints)));
+
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, "/test");
+ GRMClient client = new GRMClient();
+ ServiceEndPointList sel = client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST");
+ List<ServiceEndPoint> list = sel.getServiceEndPointList();
+ assertEquals(3, list.size());
+
+ boolean foundInvoke = false;
+ boolean foundInvokeReturn = false;
+ for(ILoggingEvent logEvent : TestAppender.events)
+ if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") &&
+ logEvent.getMarker() != null && logEvent.getMarker().getName().equals("INVOKE")
+ ){
+ Map<String,String> mdc = logEvent.getMDCPropertyMap();
+ assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
+ assertEquals("GRM",mdc.get("TargetEntity"));
+ assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ foundInvoke=true;
+ }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") &&
+ logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("INVOKE_RETURN")){
+ Map<String,String> mdc = logEvent.getMDCPropertyMap();
+ assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
+ assertEquals("200",mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE));
+ assertEquals("COMPLETED",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
+ foundInvokeReturn=true;
+ }
+
+ if(!foundInvoke)
+ fail("INVOKE Marker not found");
+
+ if(!foundInvokeReturn)
+ fail("INVOKE RETURN Marker not found");
+
+ verify(postRequestedFor(urlEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning"))
+ .withHeader(ONAPLogConstants.Headers.INVOCATION_ID.toString(), matching(uuidRegex))
+ .withHeader(ONAPLogConstants.Headers.REQUEST_ID.toString(), matching(uuidRegex))
+ .withHeader(ONAPLogConstants.Headers.PARTNER_NAME.toString(), equalTo("SO")));
+ TestAppender.events.clear();
+ }
+
+ @Test
+ public void testFindFail() throws Exception {
+ stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning"))
+ .willReturn(aResponse()
+ .withStatus(400)
+ .withHeader("Content-Type", MediaType.APPLICATION_JSON)
+ .withBody("")));
+
+ GRMClient client = new GRMClient();
+ thrown.expect(GRMClientCallFailed.class);
+ client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST");
+ }
+
+ @Test
+ public void testAddFail() throws Exception {
+ stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add"))
+ .willReturn(aResponse()
+ .withStatus(404)
+ .withHeader("Content-Type", MediaType.APPLICATION_JSON)
+ .withBody("test")));
+ ServiceEndPointRequest request = new ServiceEndPointRequest();
+ GRMClient client = new GRMClient();
+ thrown.expect(GRMClientCallFailed.class);
+ client.addServiceEndPoint(request);
+ }
+
+ @Test
+ public void testBuildServiceEndPointLookupRequest() {
+ GRMClient client = new GRMClient();
+ ServiceEndPointLookupRequest request = client.buildServiceEndPointlookupRequest("TEST.ECOMP_PSL.Inventory", 1, "DEV");
+ assertEquals("TEST.ECOMP_PSL.Inventory", request.getServiceEndPoint().getName());
+ assertEquals(Integer.valueOf(1), Integer.valueOf(request.getServiceEndPoint().getVersion().getMajor()));
+ assertEquals("DEV", request.getEnv());
+
+ }
+
+ protected String getFileContentsAsString(String fileName) {
+ String content = "";
+ try {
+ ClassLoader classLoader = this.getClass().getClassLoader();
+ File file = new File(classLoader.getResource(fileName).getFile());
+ content = new String(Files.readAllBytes(file.toPath()));
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage());
+ }
+ return content;
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json
new file mode 100644
index 0000000000..7e92c21c9e
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json
@@ -0,0 +1,145 @@
+{
+ "serviceEndPointList": [
+ {
+ "name": "dummy.pod.ns.dummy-pod3",
+ "version": {
+ "major": 1,
+ "minor": 0,
+ "patch": "0"
+ },
+ "hostAddress": "192.168.120.218",
+ "listenPort": "32004",
+ "latitude": "37.7022",
+ "longitude": "121.9358",
+ "registrationTime": "2017-07-18T15:39:17.367+0000",
+ "expirationTime": "9999-10-09T15:39:17.368+0000",
+ "contextPath": "/",
+ "routeOffer": "DEFAULT",
+ "statusInfo": {
+ "status": "RUNNING"
+ },
+ "eventStatusInfo": {
+ "status": "RUNNING"
+ },
+ "validatorStatusInfo": {
+ "status": "RUNNING"
+ },
+ "operationalInfo": {
+ "createdBy": "edge",
+ "updatedBy": "edge",
+ "createdTimestamp": "2017-07-18T15:39:17.367+0000",
+ "updatedTimestamp": "2017-07-18T15:39:17.367+0000"
+ },
+ "protocol": "dummypod-port",
+ "properties": [
+ {
+ "name": "Environment",
+ "value": "DEV"
+ },
+ {
+ "name": "Kubernetes Namespace",
+ "value": "dummy-pod-ns"
+ },
+ {
+ "name": "cpfrun_cluster_name",
+ "value": "CI-PDK1-TFINIT-CJ9125401"
+ }
+ ],
+ "disableType": []
+ },
+ {
+ "name": "dummy.pod.ns.dummy-pod3",
+ "version": {
+ "major": 1,
+ "minor": 0,
+ "patch": "0"
+ },
+ "hostAddress": "192.168.120.22",
+ "listenPort": "32004",
+ "latitude": "1.0",
+ "longitude": "1.0",
+ "registrationTime": "2017-07-18T15:39:17.816+0000",
+ "expirationTime": "9999-10-09T15:39:17.817+0000",
+ "contextPath": "/",
+ "routeOffer": "DEFAULT",
+ "statusInfo": {
+ "status": "RUNNING"
+ },
+ "eventStatusInfo": {
+ "status": "RUNNING"
+ },
+ "validatorStatusInfo": {
+ "status": "RUNNING"
+ },
+ "operationalInfo": {
+ "createdBy": "edge",
+ "updatedBy": "edge",
+ "createdTimestamp": "2017-07-18T15:39:17.816+0000",
+ "updatedTimestamp": "2017-07-18T15:39:17.816+0000"
+ },
+ "protocol": "dummypod-port",
+ "properties": [
+ {
+ "name": "Environment",
+ "value": "DEV"
+ },
+ {
+ "name": "Kubernetes Namespace",
+ "value": "dummy-pod-ns"
+ },
+ {
+ "name": "cpfrun_cluster_name",
+ "value": "CI-PDK1-TFINIT-CJ9125401"
+ }
+ ],
+ "disableType": []
+ },
+ {
+ "name": "dummy.pod.ns.dummy-pod1",
+ "version": {
+ "major": 1,
+ "minor": 0,
+ "patch": "0"
+ },
+ "hostAddress": "192.168.120.218",
+ "listenPort": "32002",
+ "latitude": "1.0",
+ "longitude": "1.0",
+ "registrationTime": "2017-07-18T15:39:14.443+0000",
+ "expirationTime": "9999-10-09T15:39:14.453+0000",
+ "contextPath": "/",
+ "routeOffer": "DEFAULT",
+ "statusInfo": {
+ "status": "RUNNING"
+ },
+ "eventStatusInfo": {
+ "status": "RUNNING"
+ },
+ "validatorStatusInfo": {
+ "status": "RUNNING"
+ },
+ "operationalInfo": {
+ "createdBy": "edge",
+ "updatedBy": "edge",
+ "createdTimestamp": "2017-07-18T15:39:14.443+0000",
+ "updatedTimestamp": "2017-07-18T15:39:14.443+0000"
+ },
+ "protocol": "dummypod-port",
+ "properties": [
+ {
+ "name": "Environment",
+ "value": "DEV"
+ },
+ {
+ "name": "Kubernetes Namespace",
+ "value": "dummy-pod-ns"
+ },
+ {
+ "name": "cpfrun_cluster_name",
+ "value": "CI-PDK1-TFINIT-CJ9125401"
+ }
+ ],
+ "disableType": []
+ }
+ ]
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
index 6e1d6f3376..63eb0534ea 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
@@ -70,8 +70,7 @@ mso:
auth: 5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C
grm:
endpoint: http://localhost:${wiremock.server.port}
- username: gmruser
- password: test
+ auth: 6AAD26000E278148A0B987436D9696A5B2D99BBF0DC545F9E64D6DF05298FFA987A6CF565F6F274EBC085678
so:
operational-environment:
dmaap: