summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/test
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-rest/src/test
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-rest/src/test')
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy13
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy6
2 files changed, 11 insertions, 8 deletions
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
index 983f2438c0..dba2b30fd4 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
@@ -135,6 +135,7 @@ class NetworkCmProxyControllerSpec extends Specification {
@Shared
def NO_TOPIC = null
def NO_REQUEST_ID = null
+ def NO_AUTH_HEADER = null
def TIMOUT_FOR_TEST = 1234
def logger = Spy(ListAppender<ILoggingEvent>)
@@ -162,7 +163,7 @@ class NetworkCmProxyControllerSpec extends Specification {
).andReturn().response
then: 'the NCMP data service is called with getResourceDataOperationalForCmHandle'
1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_OPERATIONAL.datastoreName, 'testCmHandle',
- 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID)
+ 'parent/child','(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER)
and: 'response status is Ok'
response.status == HttpStatus.OK.value()
}
@@ -279,7 +280,7 @@ class NetworkCmProxyControllerSpec extends Specification {
"?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)"
and: 'ncmp service returns json object'
mockNetworkCmProxyDataService.getResourceDataForCmHandle(PASSTHROUGH_RUNNING.datastoreName, 'testCmHandle',
- resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID) >> '{valid-json}'
+ resourceIdentifier,'(a=1,b=2)', NO_TOPIC, NO_REQUEST_ID, NO_AUTH_HEADER) >> '{valid-json}'
when: 'get data resource request is performed'
def response = mvc.perform(
get(getUrl)
@@ -310,7 +311,7 @@ class NetworkCmProxyControllerSpec extends Specification {
).andReturn().response
then: 'ncmp service method to update resource is called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8')
+ 'parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'the response status is OK'
response.status == HttpStatus.OK.value()
}
@@ -326,7 +327,7 @@ class NetworkCmProxyControllerSpec extends Specification {
).andReturn().response
then: 'ncmp service method to create resource called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8')
+ 'parent/child', CREATE, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'resource is created'
response.status == HttpStatus.CREATED.value()
}
@@ -492,7 +493,7 @@ class NetworkCmProxyControllerSpec extends Specification {
).andReturn().response
then: 'ncmp service method to update resource is called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8')
+ 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'the response status is OK'
response.status == HttpStatus.OK.value()
}
@@ -507,7 +508,7 @@ class NetworkCmProxyControllerSpec extends Specification {
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andReturn().response
then: 'the ncmp service method to delete resource is called (with null as body)'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', DELETE, null, 'application/json;charset=UTF-8')
+ 'parent/child', DELETE, null, 'application/json;charset=UTF-8', NO_AUTH_HEADER)
and: 'the response is No Content'
response.status == HttpStatus.NO_CONTENT.value()
}
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy
index 4edbf3569f..328a85e714 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/handlers/NcmpDatastoreRequestHandlerSpec.groovy
@@ -37,6 +37,8 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
def objectUnderTest = new NcmpPassthroughResourceRequestHandler(spiedCpsNcmpTaskExecutor, mockNetworkCmProxyDataService)
+ def NO_AUTH_HEADER = null
+
def setup() {
objectUnderTest.timeOutInMilliSeconds = 100
}
@@ -47,11 +49,11 @@ class NcmpDatastoreRequestHandlerSpec extends Specification {
and: 'a flag to track the network service call'
def networkServiceMethodCalled = false
and: 'the (mocked) service will use the flag to indicate if it is called'
- mockNetworkCmProxyDataService.getResourceDataForCmHandle('ds', 'ch1', 'resource1', 'options', _, _) >> {
+ mockNetworkCmProxyDataService.getResourceDataForCmHandle('ds', 'ch1', 'resource1', 'options', _, _, NO_AUTH_HEADER) >> {
networkServiceMethodCalled = true
}
when: 'get request is executed with topic = #topic'
- objectUnderTest.executeRequest('ds', 'ch1', 'resource1', 'options', topic, false)
+ objectUnderTest.executeRequest('ds', 'ch1', 'resource1', 'options', topic, false, NO_AUTH_HEADER)
then: 'the task is executed in an async fashion or not'
expectedCalls * spiedCpsNcmpTaskExecutor.executeTask(*_)
and: 'the service request is invoked'