From: danielhanrahan Date: Fri, 5 Jul 2024 12:20:31 +0000 (+0100) Subject: [BUG] Fix handling of special characters in moduleSetTag X-Git-Tag: 3.5.1~20 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=8b6882c68290520fe238562d0bd3739de61beaef;p=cps.git [BUG] Fix handling of special characters in moduleSetTag During CM-handle registration, moduleSetTag is sent as part of the JSON request body when getting modules from DMI. However, it incorrectly parses the moduleSetTag as JSON, instead of encoding to JSON. This results in parsing errors when moduleSetTag includes characters such as ':' Issue-ID: CPS-2302 Signed-off-by: danielhanrahan Change-Id: Ie38008e0effac2423a4d069a91587e47d8747d66 --- diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java index 7d6677ca38..c1f89b3440 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperations.java @@ -25,9 +25,7 @@ import static org.onap.cps.ncmp.api.data.models.OperationType.READ; import static org.onap.cps.ncmp.impl.models.RequiredDmiService.MODEL; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -126,8 +124,7 @@ public class DmiModelOperations { data.add("modules", moduleReferencesAsJson); final JsonObject jsonRequestObject = new JsonObject(); if (!moduleSetTag.isEmpty()) { - final JsonElement moduleSetTagAsJson = JsonParser.parseString(moduleSetTag); - jsonRequestObject.add("moduleSetTag", moduleSetTagAsJson); + jsonRequestObject.addProperty("moduleSetTag", moduleSetTag); } jsonRequestObject.add("data", data); jsonRequestObject.add("cmHandleProperties", toJsonObject(dmiProperties)); diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy index 1268bc7683..17352977b8 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/DmiModelOperationsSpec.groovy @@ -170,9 +170,10 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec { then: 'the result is the response from DMI service' assert result == [mod1:'some yang source'] where: 'the following Module Set Tags are used' - scenario | moduleSetTag || expectedModuleSetTagInRequest - 'Without module set tag' | '' || '' - 'With module set tag' | 'moduleSetTag1' || '"moduleSetTag":"moduleSetTag1",' + scenario | moduleSetTag || expectedModuleSetTagInRequest + 'Without module set tag' | '' || '' + 'With module set tag' | 'moduleSetTag1' || '"moduleSetTag":"moduleSetTag1",' + 'Special characters in module set tag' | 'module:set#tag$2' || '"moduleSetTag":"module:set#tag$2",' } def 'Retrieving yang resources from DMI with no module references.'() { diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 01735df61e..ce2c028076 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -39,6 +39,7 @@ Release Data Bug Fixes --------- 3.5.1 + - `CPS-2302 `_ Fix handling of special characters in moduleSetTag. Features --------