diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index 434702e74e..ea8280dd5e 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -95,6 +95,7 @@ import com.auth0.jwt.exceptions.JWTDecodeException; import com.auth0.jwt.interfaces.DecodedJWT; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.jknack.handlebars.Context; @@ -1382,20 +1383,40 @@ protected Response postWithBodyAndBearerTokenForAutoGeneratedId(String url, Stri return response; } } - + protected Response postWithBodyAndCookieForAutoGeneratedIdForUrlEncoded(String url, String jsonInput, String testCaseName, String idKeyName) throws SecurityXSSException { Response response = null; String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); ObjectMapper mapper = new ObjectMapper(); - Map map = null; + Map formData = new HashMap<>(); + try { - map = mapper.readValue(inputJson, Map.class); + @SuppressWarnings("unchecked") + Map jsonMap = mapper.readValue(inputJson, Map.class); + + // conversion: simple strings → raw values, complex → JSON strings + for (Map.Entry entry : jsonMap.entrySet()) { + Object value = entry.getValue(); + String formValue; + + if (value instanceof String) { + // String values should remain raw + formValue = (String) value; + } else { + // Arrays/objects/other types → JSON string + formValue = mapper.writeValueAsString(value); + } + + formData.put(entry.getKey(), formValue); + } + logger.info(GlobalConstants.POST_REQ_URL + url); - logger.info(inputJson); + GlobalMethods.reportRequest(null, inputJson, url); - response = RestClient.postRequestWithFormDataBody(url, map); - // check if X-XSS-Protection is enabled or not + + response = RestClient.postRequestWithFormDataBody(url, formData); + GlobalMethods.checkXSSProtectionHeader(response, url); GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response); @@ -1408,7 +1429,6 @@ protected Response postWithBodyAndCookieForAutoGeneratedIdForUrlEncoded(String u keyName = ESIGNETUINCOOKIESRESPONSE; else keyName = ESIGNETVIDCOOKIESRESPONSE; - CertsUtil.addCertificateToCache(keyName, response.getBody().asString()); } @@ -1426,6 +1446,7 @@ protected Response postWithBodyAndCookieForAutoGeneratedIdForUrlEncoded(String u } } + protected Response patchWithBodyAndCookieWithAutoGeneratedId(String url, String jsonInput, String cookieName, String role, String testCaseName, String idKeyName) throws SecurityXSSException { Response response = null;