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 f6c114acc1..7b488e4aed 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 @@ -436,7 +436,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a } } - + logger.info(GlobalConstants.POST_REQ_URL + url); GlobalMethods.reportRequest(null, inputJson, url); try { @@ -1117,7 +1117,8 @@ protected Response postWithBodyAndCookieForAutoGeneratedId(String url, String js if (BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.equals("auth") || BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET) || BaseTestCase.currentModule.equals(GlobalConstants.RESIDENT) - || BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA)) { + || BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA) + || BaseTestCase.currentModule.equals(GlobalConstants.PREREG)) { inputJson = smtpOtpHandler(inputJson, testCaseName); } if (bothAccessAndIdToken) { @@ -2271,6 +2272,40 @@ protected byte[] postWithBodyAndCookieForPdf(String url, String jsonInput, Strin } } + protected byte[] postWithFormDataBodyForPdf(String url, String jsonInput, String cookieName, String role, + String testCaseName) { + + HashMap formDataMap = new HashMap<>(); + jsonInput = inputJsonKeyWordHandeler(jsonInput, testCaseName); + logger.info("inputJson is::" + jsonInput); + + JSONObject req = new JSONObject(jsonInput); + logger.info(GlobalConstants.REQ_STR + req); + jsonInput = req.toString(); + + byte[] pdf = null; + + try { + formDataMap = new Gson().fromJson(jsonInput, new TypeToken>() { + }.getType()); + } catch (Exception e) { + logger.error( + GlobalConstants.ERROR_STRING_1 + jsonInput + GlobalConstants.EXCEPTION_STRING_1 + e.getMessage()); + } + + logger.info("******Post request to EndPointUrl: " + url); + GlobalMethods.reportRequest(null, jsonInput, url); + + try { + pdf = RestClient.postRequestWithFormDataBodyForPdf(url, formDataMap); + return pdf; + } catch (Exception e) { + logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); + return pdf; + } + + } + protected byte[] getWithQueryParamAndCookieForPdf(String url, String jsonInput, String cookieName, String role, String testCaseName) { return getWithQueryParamAndCookieForPdf(url, jsonInput, cookieName, role, testCaseName, false); @@ -3312,10 +3347,18 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$OIDCCLIENT$", getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.module.clientID")); } + if (jsonString.contains("$GETCLIENTIDFROMMIMOTOACTUATOR$")) { + jsonString = replaceKeywordWithValue(jsonString, "$GETCLIENTIDFROMMIMOTOACTUATOR$", + getValueFromMimotoActuator("configService:overrides", "mimoto.oidc.partner.clientid")); + } if (jsonString.contains("$IDPREDIRECTURI$")) { jsonString = replaceKeywordWithValue(jsonString, "$IDPREDIRECTURI$", ApplnURI.replace(GlobalConstants.API_INTERNAL, "healthservices") + "/userprofile"); } + if (jsonString.contains("$INJIREDIRECTURI$")) { + jsonString = replaceKeywordWithValue(jsonString, "$INJIREDIRECTURI$", + ApplnURI.replace(GlobalConstants.API_INTERNAL, "inji") + "/redirect"); + } if (jsonString.contains("$BASE64URI$")) { String redirectUri = ApplnURI.replace(GlobalConstants.API_INTERNAL, GlobalConstants.RESIDENT) + propsKernel.getProperty("currentUserURI"); @@ -6039,6 +6082,44 @@ public static String getValueFromActuator(String section, String key) { } } + + public static JSONArray mimotoActuatorResponseArray = null; + + public static String getValueFromMimotoActuator(String section, String key) { + String url = ApplnURI + propsKernel.getProperty("actuatorMimotoEndpoint"); + String actuatorCacheKey = url + section + key; + String value = actuatorValueCache.get(actuatorCacheKey); + if (value != null && !value.isEmpty()) + return value; + + try { + if (mimotoActuatorResponseArray == null) { + Response response = null; + JSONObject responseJson = null; + response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); + + responseJson = new JSONObject(response.getBody().asString()); + mimotoActuatorResponseArray = responseJson.getJSONArray("propertySources"); + } + for (int i = 0, size = mimotoActuatorResponseArray.length(); i < size; i++) { + JSONObject eachJson = mimotoActuatorResponseArray.getJSONObject(i); + if (eachJson.get("name").toString().contains(section)) { + value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key) + .get(GlobalConstants.VALUE).toString(); + if (ConfigManager.IsDebugEnabled()) + logger.info("Actuator: " + url + " key: " + key + " value: " + value); + break; + } + } + actuatorValueCache.put(actuatorCacheKey, value); + + return value; + } catch (Exception e) { + logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); + return ""; + } + + } public static JSONArray regprocActuatorResponseArray = null; @@ -6431,18 +6512,7 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) { } } } - if (BaseTestCase.currentModule.equals(GlobalConstants.PREREG)) { - if (request.has(GlobalConstants.REQUEST)) { - if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) { - emailId = request.getJSONObject(GlobalConstants.REQUEST).getString("userId"); - logger.info(emailId); - otp = MockSMTPListener.getOtp(emailId); - request.getJSONObject(GlobalConstants.REQUEST).put("otp", otp); - inputJson = request.toString(); - return inputJson; - } - } - } + if (BaseTestCase.currentModule.equals("auth")) { if (testCaseName.startsWith("auth_GenerateVID") || testCaseName.startsWith("auth_AuthLock") @@ -6528,6 +6598,7 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) { } if (BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET) + || BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO) || testCaseName.startsWith("Mimoto_WalletBinding")) { if (request.has(GlobalConstants.REQUEST)) { if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) { @@ -6604,7 +6675,8 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) { .getString(GlobalConstants.CHALLENGE).endsWith(GlobalConstants.MOSIP_NET) || request.getJSONObject(GlobalConstants.REQUEST) .getJSONArray(GlobalConstants.CHALLENGELIST).getJSONObject(0) - .getString(GlobalConstants.CHALLENGE).endsWith(GlobalConstants.OTP_AS_PHONE)) { + .getString(GlobalConstants.CHALLENGE) + .endsWith(GlobalConstants.OTP_AS_PHONE)) { emailId = request.getJSONObject(GlobalConstants.REQUEST) .getJSONArray(GlobalConstants.CHALLENGELIST).getJSONObject(0) .getString(GlobalConstants.CHALLENGE);