summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-02-28 16:05:07 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-02-29 12:21:52 +0000
commitc5222a72ef11bd440f5c2bd017e820922ff6735a (patch)
tree072780e0dc9426a0828f29447eedeb4e4f75116d /cps-ncmp-service
parent181c63d7007e685657cbd0d2c9b7693a073835dc (diff)
Add bearer token to NCMP passthrough operations (CPS-2126 #2)
For NCMP resource data passthrough operations, accept an authorization header and propagate it to outgoing DMI request if it has a bearer token, otherwise use same behaviour as before Issue-ID: CPS-2128 Change-Id: Ib3bf401abce4221a8b706989fb6f07618aa33fe2 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java8
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java11
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java14
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java16
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy17
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy23
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy15
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy11
9 files changed, 74 insertions, 43 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
index 0c8474839b..dbfeca1804 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
@@ -59,6 +59,7 @@ public interface NetworkCmProxyDataService {
* @param optionsParamInQuery options query
* @param topicParamInQuery topic name for (triggering) async responses
* @param requestId unique requestId for async request
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code Object} resource data
*/
Object getResourceDataForCmHandle(String datastoreName,
@@ -66,7 +67,8 @@ public interface NetworkCmProxyDataService {
String resourceIdentifier,
String optionsParamInQuery,
String topicParamInQuery,
- String requestId);
+ String requestId,
+ String authorization);
/**
* Get resource data for operational.
@@ -101,13 +103,15 @@ public interface NetworkCmProxyDataService {
* @param operationType required operation type
* @param requestBody request body to create resource
* @param contentType content type in body
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code Object} return data
*/
Object writeResourceDataPassThroughRunningForCmHandle(String cmHandleId,
String resourceIdentifier,
OperationType operationType,
String requestBody,
- String contentType);
+ String contentType,
+ String authorization);
/**
* Retrieve module references for the given cm handle.
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index 08afde49a1..3e304a4fd0 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -132,12 +132,14 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final String resourceIdentifier,
final String optionsParamInQuery,
final String topicParamInQuery,
- final String requestId) {
+ final String requestId,
+ final String authorization) {
final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId,
resourceIdentifier,
optionsParamInQuery,
topicParamInQuery,
- requestId);
+ requestId,
+ authorization);
return responseEntity.getBody();
}
@@ -163,9 +165,10 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final String resourceIdentifier,
final OperationType operationType,
final String requestData,
- final String dataType) {
+ final String dataType,
+ final String authorization) {
return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
- operationType, requestData, dataType);
+ operationType, requestData, dataType, authorization);
}
@Override
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
index 5b93eb4853..798a280c8a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/client/DmiRestClient.java
@@ -22,6 +22,7 @@
package org.onap.cps.ncmp.api.impl.client;
import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Locale;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration.DmiProperties;
@@ -51,12 +52,15 @@ public class DmiRestClient {
* @param dmiResourceUrl dmi resource url
* @param requestBodyAsJsonString json data body
* @param operationType the type of operation being executed (for error reporting only)
+ * @param authorization contents of Authorization header, or null if not present
* @return response entity of type String
*/
public ResponseEntity<Object> postOperationWithJsonData(final String dmiResourceUrl,
final String requestBodyAsJsonString,
- final OperationType operationType) {
- final var httpEntity = new HttpEntity<>(requestBodyAsJsonString, configureHttpHeaders(new HttpHeaders()));
+ final OperationType operationType,
+ final String authorization) {
+ final var httpEntity = new HttpEntity<>(requestBodyAsJsonString, configureHttpHeaders(new HttpHeaders(),
+ authorization));
try {
return restTemplate.postForEntity(dmiResourceUrl, httpEntity, Object.class);
} catch (final HttpStatusCodeException httpStatusCodeException) {
@@ -73,7 +77,7 @@ public class DmiRestClient {
* @return plugin health status ("UP" is all OK, "" (not-specified) in case of any exception)
*/
public String getDmiHealthStatus(final String dmiPluginBaseUrl) {
- final HttpEntity<Object> httpHeaders = new HttpEntity<>(configureHttpHeaders(new HttpHeaders()));
+ final HttpEntity<Object> httpHeaders = new HttpEntity<>(configureHttpHeaders(new HttpHeaders(), null));
try {
final JsonNode responseHealthStatus =
restTemplate.getForObject(dmiPluginBaseUrl + HEALTH_CHECK_URL_EXTENSION,
@@ -86,9 +90,11 @@ public class DmiRestClient {
}
}
- private HttpHeaders configureHttpHeaders(final HttpHeaders httpHeaders) {
+ private HttpHeaders configureHttpHeaders(final HttpHeaders httpHeaders, final String authorization) {
if (dmiProperties.isDmiBasicAuthEnabled()) {
httpHeaders.setBasicAuth(dmiProperties.getAuthUsername(), dmiProperties.getAuthPassword());
+ } else if (authorization != null && authorization.toLowerCase(Locale.getDefault()).startsWith("bearer ")) {
+ httpHeaders.add(HttpHeaders.AUTHORIZATION, authorization);
}
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return httpHeaders;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
index fa18767dbe..05b6ec3001 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
@@ -79,6 +79,7 @@ public class DmiDataOperations extends DmiOperations {
* @param optionsParamInQuery options query
* @param topicParamInQuery topic name for (triggering) async responses
* @param requestId requestId for async responses
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code ResponseEntity} response entity
*/
@Timed(value = "cps.ncmp.dmi.get",
@@ -89,7 +90,8 @@ public class DmiDataOperations extends DmiOperations {
final String resourceId,
final String optionsParamInQuery,
final String topicParamInQuery,
- final String requestId) {
+ final String requestId,
+ final String authorization) {
final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmHandleId);
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
@@ -97,7 +99,7 @@ public class DmiDataOperations extends DmiOperations {
yangModelCmHandle);
final String dmiResourceDataUrl = getDmiRequestUrl(dataStoreName, cmHandleId, resourceId, optionsParamInQuery,
topicParamInQuery, yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA));
- return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ);
+ return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ, authorization);
}
/**
@@ -120,7 +122,7 @@ public class DmiDataOperations extends DmiOperations {
yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA));
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
- return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ);
+ return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ, null);
}
/**
@@ -157,13 +159,15 @@ public class DmiDataOperations extends DmiOperations {
* @param operationType operation enum
* @param requestData the request data
* @param dataType data type
+ * @param authorization contents of Authorization header, or null if not present
* @return {@code ResponseEntity} response entity
*/
public ResponseEntity<Object> writeResourceDataPassThroughRunningFromDmi(final String cmHandleId,
final String resourceId,
final OperationType operationType,
final String requestData,
- final String dataType) {
+ final String dataType,
+ final String authorization) {
final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmHandleId);
final String jsonRequestBody = getDmiRequestBody(operationType, null, requestData, dataType,
yangModelCmHandle);
@@ -172,7 +176,7 @@ public class DmiDataOperations extends DmiOperations {
yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA));
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
- return dmiRestClient.postOperationWithJsonData(dmiUrl, jsonRequestBody, operationType);
+ return dmiRestClient.postOperationWithJsonData(dmiUrl, jsonRequestBody, operationType, authorization);
}
private YangModelCmHandle getYangModelCmHandle(final String cmHandleId) {
@@ -250,7 +254,7 @@ public class DmiDataOperations extends DmiOperations {
final String dmiDataOperationRequestAsJsonString =
jsonObjectMapper.asJsonString(dmiDataOperationRequest);
TaskExecutor.executeTask(() -> dmiRestClient.postOperationWithJsonData(dataOperationResourceUrl,
- dmiDataOperationRequestAsJsonString, READ),
+ dmiDataOperationRequestAsJsonString, READ, null),
DEFAULT_ASYNC_TASK_EXECUTOR_TIMEOUT_IN_MILLISECONDS)
.whenCompleteAsync((response, throwable) -> handleTaskCompletionException(throwable,
dataOperationResourceUrl, dmiDataOperationRequestBodies));
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
index dbe386d7ca..f99fe86f66 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiModelOperations.java
@@ -112,7 +112,7 @@ public class DmiModelOperations extends DmiOperations {
final String resourceName) {
final String dmiResourceDataUrl = getDmiResourceUrl(dmiServiceName, cmHandle, resourceName);
return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody,
- OperationType.READ);
+ OperationType.READ, null);
}
private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences,
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 9b4fe146b9..71380d46a6 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -86,6 +86,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def NO_TOPIC = null
def NO_REQUEST_ID = null
+ def NO_AUTH_HEADER = null
def OPTIONS_PARAM = '(a=1,b=2)'
def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'test-cm-handle-id')
@@ -113,10 +114,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
when: 'write resource data is called'
objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId', CREATE,
- '{some-json}', 'application/json')
+ '{some-json}', 'application/json', null)
then: 'DMI called with correct data'
1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
- CREATE, '{some-json}', 'application/json')
+ CREATE, '{some-json}', 'application/json', null)
>> { new ResponseEntity<>(HttpStatus.CREATED) }
}
@@ -124,10 +125,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
given: 'cpsDataService returns valid data node'
mockDataNode()
and: 'get resource data from DMI is called'
- mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_OPERATIONAL.datastoreName,'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID) >>
+ mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_OPERATIONAL.datastoreName,'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >>
new ResponseEntity<>('dmi-response', HttpStatus.OK)
when: 'get resource data operational for cm-handle is called'
- def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID)
+ def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
then: 'DMI returns a json response'
assert response == 'dmi-response'
}
@@ -136,10 +137,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
given: 'cpsDataService returns valid data node'
mockDataNode()
and: 'DMI returns valid response and data'
- mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID) >>
+ mockDmiDataOperations.getResourceDataFromDmi(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >>
new ResponseEntity<>('{dmi-response}', HttpStatus.OK)
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID)
+ def response = objectUnderTest.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle', 'testResourceId', OPTIONS_PARAM, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
then: 'get resource data returns expected response'
assert response == '{dmi-response}'
}
@@ -259,10 +260,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
when: 'get resource data is called'
objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId', UPDATE,
- '{some-json}', 'application/json')
+ '{some-json}', 'application/json', NO_AUTH_HEADER)
then: 'DMI called with correct data'
1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
- UPDATE, '{some-json}', 'application/json')
+ UPDATE, '{some-json}', 'application/json', NO_AUTH_HEADER)
>> { new ResponseEntity<>(HttpStatus.OK) }
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
index 0176de7147..c8e34b1a5e 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
@@ -48,6 +48,10 @@ import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE
@ContextConfiguration(classes = [DmiProperties, DmiRestClient, ObjectMapper])
class DmiRestClientSpec extends Specification {
+ static final NO_AUTH_HEADER = null
+ static final BASIC_AUTH_HEADER = 'Basic c29tZS11c2VyOnNvbWUtcGFzc3dvcmQ='
+ static final BEARER_AUTH_HEADER = 'Bearer my-bearer-token'
+
@SpringBean
RestTemplate mockRestTemplate = Mock(RestTemplate)
@@ -66,7 +70,7 @@ class DmiRestClientSpec extends Specification {
given: 'the rest template returns a valid response entity for the expected parameters'
mockRestTemplate.postForEntity('my url', _ as HttpEntity, Object.class) >> responseFromRestTemplate
when: 'POST operation is invoked'
- def result = objectUnderTest.postOperationWithJsonData('my url', 'some json', READ)
+ def result = objectUnderTest.postOperationWithJsonData('my url', 'some json', READ, null)
then: 'the output of the method is equal to the output from the test template'
result == responseFromRestTemplate
}
@@ -77,7 +81,7 @@ class DmiRestClientSpec extends Specification {
def httpServerErrorException = new HttpServerErrorException(HttpStatus.FORBIDDEN, 'status text', serverResponse, null)
mockRestTemplate.postForEntity(*_) >> { throw httpServerErrorException }
when: 'POST operation is invoked'
- def result = objectUnderTest.postOperationWithJsonData('some url', 'some json', operation)
+ def result = objectUnderTest.postOperationWithJsonData('some url', 'some json', operation, null)
then: 'a Http Client Exception is thrown'
def thrown = thrown(HttpClientRequestException)
and: 'the exception has the relevant details from the error response'
@@ -113,15 +117,20 @@ class DmiRestClientSpec extends Specification {
'exception' | {throw new Exception()}
}
- def 'Basic auth header #scenario'() {
+ def 'DMI auth header #scenario'() {
when: 'Specific dmi properties are provided'
dmiProperties.dmiBasicAuthEnabled = authEnabled
then: 'http headers to conditionally have Authorization header'
- assert (objectUnderTest.configureHttpHeaders(new HttpHeaders()).get('Authorization') != null) == isPresentInHttpHeader
+ def authHeaderValues = objectUnderTest.configureHttpHeaders(new HttpHeaders(), ncmpAuthHeader).getOrEmpty('Authorization')
+ def outputAuthHeader = (authHeaderValues == null ? null : authHeaderValues[0])
+ assert outputAuthHeader == expectedAuthHeader
where: 'the following configurations are used'
- scenario | authEnabled || isPresentInHttpHeader
- 'auth enabled' | true || true
- 'auth disabled' | false || false
+ scenario | authEnabled | ncmpAuthHeader || expectedAuthHeader
+ 'DMI basic auth enabled, no NCMP bearer token' | true | NO_AUTH_HEADER || BASIC_AUTH_HEADER
+ 'DMI basic auth enabled, with NCMP bearer token' | true | BEARER_AUTH_HEADER || BASIC_AUTH_HEADER
+ 'DMI basic auth disabled, no NCMP bearer token' | false | NO_AUTH_HEADER || NO_AUTH_HEADER
+ 'DMI basic auth disabled, with NCMP bearer token' | false | BEARER_AUTH_HEADER || BEARER_AUTH_HEADER
+ 'DMI basic auth disabled, with NCMP basic auth' | false | BASIC_AUTH_HEADER || NO_AUTH_HEADER
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy
index 2229b32b0c..26d44f28b3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiDataOperationsSpec.groovy
@@ -59,6 +59,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
def dmiServiceBaseUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/data/ds/ncmp-datastore:"
def NO_TOPIC = null
def NO_REQUEST_ID = null
+ def NO_AUTH_HEADER = null
@Shared
def OPTIONS_PARAM = '(a=1,b=2)'
@@ -77,11 +78,11 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
def expectedUrl = dmiServiceBaseUrl + "${expectedDatastoreInUrl}?resourceIdentifier=${resourceIdentifier}${expectedOptionsInUrl}"
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, READ) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, READ, NO_AUTH_HEADER) >> responseFromDmi
dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
when: 'get resource data is invoked'
def result = objectUnderTest.getResourceDataFromDmi(dataStore.datastoreName, cmHandleId, resourceIdentifier,
- options, NO_TOPIC, NO_REQUEST_ID)
+ options, NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
then: 'the result is the response from the DMI service'
assert result == responseFromDmi
where: 'the following parameters are used'
@@ -104,12 +105,12 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.ACCEPTED)
def expectedDmiBatchResourceDataUrl = "ncmp/v1/data/topic=my-topic-name"
def expectedBatchRequestAsJson = '{"operations":[{"operation":"read","operationId":"operational-14","datastore":"ncmp-datastore:passthrough-operational","options":"some option","resourceIdentifier":"some resource identifier","cmHandles":[{"id":"some-cm-handle","cmHandleProperties":{"prop1":"val1"}}]}]}'
- mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, _, READ.operationName) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, _, READ.operationName, NO_AUTH_HEADER) >> responseFromDmi
dmiServiceUrlBuilder.getDataOperationRequestUrl(_, _) >> expectedDmiBatchResourceDataUrl
and: ' a flag to track the post operation call'
def postOperationWithJsonDataMethodCalled = false
and: 'the (mocked) dmi rest client will use the flag to indicate it is called and capture the request body'
- mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, expectedBatchRequestAsJson, READ) >> {
+ mockDmiRestClient.postOperationWithJsonData(expectedDmiBatchResourceDataUrl, expectedBatchRequestAsJson, READ, null) >> {
postOperationWithJsonDataMethodCalled = true
}
when: 'get resource data for group of cm handles are invoked'
@@ -148,7 +149,7 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
def expectedUrl = dmiServiceBaseUrl + "passthrough-operational?resourceIdentifier=/"
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}', READ) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"operation":"read","cmHandleProperties":{"prop1":"val1"}}', READ, null) >> responseFromDmi
dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
when: 'get resource data is invoked'
def result = objectUnderTest.getResourceDataFromDmi( PASSTHROUGH_OPERATIONAL.datastoreName, cmHandleId, NO_REQUEST_ID)
@@ -164,9 +165,9 @@ class DmiDataOperationsSpec extends DmiOperationsBaseSpec {
def expectedJson = '{"operation":"' + expectedOperationInUrl + '","dataType":"some data type","data":"requestData","cmHandleProperties":{"prop1":"val1"}}'
def responseFromDmi = new ResponseEntity<Object>(HttpStatus.OK)
dmiServiceUrlBuilder.getDmiDatastoreUrl(_, _) >> expectedUrl
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, operation) >> responseFromDmi
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, expectedJson, operation, NO_AUTH_HEADER) >> responseFromDmi
when: 'write resource method is invoked'
- def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId, 'parent/child', operation, 'requestData', 'some data type')
+ def result = objectUnderTest.writeResourceDataPassThroughRunningFromDmi(cmHandleId, 'parent/child', operation, 'requestData', 'some data type', NO_AUTH_HEADER)
then: 'the result is the response from the DMI service'
assert result == responseFromDmi
where: 'the following operation is performed'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy
index a105f84ebe..ae17c56ef3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operations/DmiModelOperationsSpec.groovy
@@ -51,6 +51,8 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
@SpringBean
JsonObjectMapper spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
+ def NO_AUTH_HEADER = null
+
def 'Retrieving module references.'() {
given: 'a cm handle'
mockYangModelCmHandleRetrieval([])
@@ -58,7 +60,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
def moduleReferencesAsLisOfMaps = [[moduleName: 'mod1', revision: 'A'], [moduleName: 'mod2', revision: 'X']]
def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules"
def responseFromDmi = new ResponseEntity([schemas: moduleReferencesAsLisOfMaps], HttpStatus.OK)
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{}}', READ)
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{}}', READ, NO_AUTH_HEADER)
>> responseFromDmi
when: 'get module references is called'
def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
@@ -91,7 +93,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
and: 'a positive response from DMI service when it is called with tha expected parameters'
def responseFromDmi = new ResponseEntity<String>(HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules",
- '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ) >> responseFromDmi
+ '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'a get module references is called'
def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
then: 'the result is the response from DMI service'
@@ -110,7 +112,7 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
[moduleName: 'mod2', revision: 'C', yangSource: 'other yang source']], HttpStatus.OK)
def expectedModuleReferencesInRequest = '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
- '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ) >> responseFromDmi
+ '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get new yang resources from DMI service'
def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
then: 'the result has the 2 expected yang (re)sources (order is not guaranteed)'
@@ -142,7 +144,8 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
and: 'a positive response from DMI service when it is called with the expected parameters'
def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
- '{"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}', READ) >> responseFromDmi
+ '{"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}',
+ READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'get new yang resources from DMI service'
def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
then: 'the result is the response from DMI service'