From a845310d1f2b5e30d23bb7c633a64837bceed699 Mon Sep 17 00:00:00 2001 From: NitinHegde Date: Thu, 5 Dec 2024 12:47:18 +0530 Subject: [PATCH 1/3] MOSIP-38033 changed if condition for the challengeList negative scenarios Signed-off-by: NitinHegde --- .../testrig/apirig/utils/AdminTestUtil.java | 1474 ++++++++--------- .../main/resources/config/Kernel.properties | 49 +- 2 files changed, 742 insertions(+), 781 deletions(-) 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 c764cecdf0..bbf7d08d41 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 @@ -139,10 +139,9 @@ public class AdminTestUtil extends BaseTestCase { protected static Properties properties = null; protected static Properties propsMap = null; protected static Properties propsBio = null; - public static String propsHealthCheckURL = getGlobalResourcePath() + "/" - + "config/healthCheckEndpoint.properties"; + public static String propsHealthCheckURL = getGlobalResourcePath() + "/" + "config/healthCheckEndpoint.properties"; private static String serverComponentsCommitDetails; - private static boolean foundHandlesInIdSchema= false; + private static boolean foundHandlesInIdSchema = false; private static JSONArray globalRequiredFields = null; protected static String token = null; String idToken = null; @@ -171,9 +170,8 @@ public class AdminTestUtil extends BaseTestCase { protected static String policygroupId = null; protected static String regDeviceResponse = null; protected static String generatedVID = null; - public String RANDOM_ID = "mosip" + generateRandomNumberString(2) - + Calendar.getInstance().getTimeInMillis(); - public final String RANDOM_ID_2 = "mosip" + generateRandomNumberString(2) + public String RANDOM_ID = "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis(); + public final String RANDOM_ID_2 = "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis(); public static final String RANDOM_ID_V2 = "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis(); @@ -256,7 +254,6 @@ public class AdminTestUtil extends BaseTestCase { public static final String BINDINGCERTCONSENTEMPTYCLAIMFILE = "BINDINGCERTCONSENTEMPTYCLAIMFile"; public static final String BINDINGCERTCONSENTUSER2FILE = "BINDINGCERTCONSENTUSER2File"; public static final String BINDINGCERTVIDCONSENTUSER2FILE = "BINDINGCERTCONSENTVIDUSER2File"; - private static final String UIN_CODE_VERIFIER_POS_1 = generateRandomAlphaNumericString(GlobalConstants.INTEGER_36); @@ -265,24 +262,17 @@ public class AdminTestUtil extends BaseTestCase { public static final int OTP_CHECK_INTERVAL = 10000; private static final Map actuatorValueCache = new HashMap<>(); - - + public static void init() { - properties = getproperty( - getGlobalResourcePath() + "/" + "config/application.properties"); - propsMap = getproperty( - getGlobalResourcePath() + "/" + "config/valueMapping.properties"); - propsBio = getproperty( - getGlobalResourcePath() + "/" + "config/bioValue.properties"); - - PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION = properties - .getProperty("passwordForAddIdentity"); + properties = getproperty(getGlobalResourcePath() + "/" + "config/application.properties"); + propsMap = getproperty(getGlobalResourcePath() + "/" + "config/valueMapping.properties"); + propsBio = getproperty(getGlobalResourcePath() + "/" + "config/bioValue.properties"); + + PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION = properties.getProperty("passwordForAddIdentity"); PASSWORD_TO_RESET = properties.getProperty("passwordToReset"); - + BaseTestCase.init(); } - - protected static boolean triggerESignetKeyGen1 = true; @@ -445,7 +435,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a String role, String testCaseName) { return postWithBodyAndCookie(url, jsonInput, auditLogCheck, cookieName, role, testCaseName, false); } - + protected Response postWithBodyAndCookie(String url, String jsonInput, boolean auditLogCheck, String cookieName, String role, String testCaseName, boolean bothAccessAndIdToken) { Response response = null; @@ -494,7 +484,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a return response; } - + protected Response deleteWithBodyAndCookie(String url, String jsonInput, String cookieName, String role, String testCaseName) { Response response = null; @@ -535,7 +525,7 @@ protected Response postWithBodyAndCookieWithText(String url, String jsonInput, S protected Response postWithBodyAndCookieWithoutBody(String url, String jsonInput, String cookieName, String role, String testCaseName) { Response response = null; - + String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); url = uriKeyWordHandelerUri(url, testCaseName); token = kernelAuthLib.getTokenByRole(role); @@ -570,7 +560,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin .toString(); headers.put(OAUTH_TRANSID_HEADERNAME, transactionId); } - + token = properties.getProperty(GlobalConstants.XSRFTOKEN); if (request.has(GlobalConstants.HEADERTRANSACTIONID)) { @@ -599,7 +589,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin cookiesMap.put(GlobalConstants.XSRF_TOKEN, token); request.remove(GlobalConstants.IDV_TRANSACTION_ID); } - + inputJson = request.toString(); if (BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA)) { inputJson = smtpOtpHandler(inputJson, testCaseName); @@ -727,7 +717,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin String pathFragmentCookie = null; String pathFragmentCookieTransactionId = null; Map cookiesMap = new HashMap<>(); - + if (request.has(GlobalConstants.ENCODEDHASH)) { encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString(); request.remove(GlobalConstants.ENCODEDHASH); @@ -741,14 +731,16 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN)); headers.put(OAUTH_HASH_HEADERNAME, encodedResp); headers.put(OAUTH_TRANSID_HEADERNAME, transactionId); - - if (request.has(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID) && request.has(GlobalConstants.PATH_FRAGMENT_COOKIE)) { - pathFragmentCookieTransactionId = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID).toString(); + + if (request.has(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID) + && request.has(GlobalConstants.PATH_FRAGMENT_COOKIE)) { + pathFragmentCookieTransactionId = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID) + .toString(); pathFragmentCookie = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE).toString(); request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID); request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE); } - + inputJson = request.toString(); if (BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.equals("auth") || BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET) @@ -757,7 +749,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin } token = properties.getProperty(GlobalConstants.XSRFTOKEN); - + if (request.has(GlobalConstants.IDV_TRANSACTION_ID)) { headerTransactionID = request.get(GlobalConstants.IDV_TRANSACTION_ID).toString(); headers.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID); @@ -765,19 +757,20 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin cookiesMap.put(GlobalConstants.XSRF_TOKEN, token); request.remove(GlobalConstants.IDV_TRANSACTION_ID); } - + logger.info(GlobalConstants.POST_REQ_URL + url); GlobalMethods.reportRequest(headers.toString(), inputJson, url); try { - if (pathFragmentCookie!=null) { - response = RestClient.postRequestWithMultipleHeadersAndMultipleCookies(url, inputJson, MediaType.APPLICATION_JSON, - MediaType.APPLICATION_JSON, pathFragmentCookieTransactionId, pathFragmentCookie, headers); + if (pathFragmentCookie != null) { + response = RestClient.postRequestWithMultipleHeadersAndMultipleCookies(url, inputJson, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, pathFragmentCookieTransactionId, + pathFragmentCookie, headers); } else if (cookiesMap.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) { response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookiesMap, headers); } else { - response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON, - MediaType.APPLICATION_JSON, cookieName, token, headers); + response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, + MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token, headers); } GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response); if (testCaseName.toLowerCase().contains("_sid")) { @@ -792,7 +785,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin return response; } } - + protected Response getRequestWithCookieAuthHeaderAndXsrfToken(String url, String jsonInput, String cookieName, String role, String testCaseName) { Response response = null; @@ -812,9 +805,9 @@ protected Response getRequestWithCookieAuthHeaderAndXsrfToken(String url, String headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN)); headers.put(OAUTH_HASH_HEADERNAME, encodedResp); headers.put(OAUTH_TRANSID_HEADERNAME, transactionId); - + token = null; - + if (request.has(GlobalConstants.IDV_SLOT_ALLOTED)) { token = request.get(GlobalConstants.IDV_SLOT_ALLOTED).toString(); cookieName = "IDV_SLOT_ALLOTTED"; @@ -983,7 +976,7 @@ protected Response postRequestWithCookieAuthHeaderAndSignature(String url, Strin headers.put(AUTHORIZATHION_HEADERNAME, AUTH_HEADER_VALUE); String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); headers.put(SIGNATURE_HEADERNAME, generateSignatureWithRequest(inputJson, partnerId)); - + if (testCaseName.contains("NOAUTH")) { token = ""; } else { @@ -2172,7 +2165,7 @@ protected Response getWithPathParamAndCookie(String url, String jsonInput, boole cookiesMap.put(GlobalConstants.XSRF_TOKEN, token); map.remove(GlobalConstants.VERIFIEDTRANSACTIONID); } - + if (map != null && map.containsKey(GlobalConstants.IDV_TRANSACTION_ID)) { headerTransactionID = map.get(GlobalConstants.IDV_TRANSACTION_ID).toString(); cookiesMap.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID); @@ -2900,7 +2893,7 @@ public static void initiateMimotoTest() { public static void initiateesignetTest() { copyEsignetTestResource(); } - + public static void initiateSignupTest() { copySignupTestResource(); } @@ -2924,7 +2917,7 @@ public static void copyMimotoTestResource() { public static void copyEsignetTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.ESIGNET); } - + public static void copySignupTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.SIGNUP); } @@ -3084,37 +3077,37 @@ public String uriKeyWordHandelerUri(String uri, String testCaseName) { return uri; } - + public static String getAuthTransactionId(String oidcTransactionId) { final String transactionId = oidcTransactionId.replaceAll("_|-", ""); String lengthOfTransactionId = AdminTestUtil.getValueFromEsignetActuator( ConfigManager.getEsignetActuatorPropertySection(), "mosip.esignet.auth-txn-id-length"); - int authTransactionIdLength = lengthOfTransactionId != null ? Integer.parseInt(lengthOfTransactionId): 0; - final byte[] oidcTransactionIdBytes = transactionId.getBytes(); - final byte[] authTransactionIdBytes = new byte[authTransactionIdLength]; - int i = oidcTransactionIdBytes.length - 1; - int j = 0; - while(j < authTransactionIdLength) { - authTransactionIdBytes[j++] = oidcTransactionIdBytes[i--]; - if(i < 0) { i = oidcTransactionIdBytes.length - 1; } - } - return new String(authTransactionIdBytes); - } - - - private static String removeSuffixUnderscores(String input, String[] suffixes) { - for (String suffix : suffixes) { - if (input.endsWith(suffix)) { - // Remove underscores from the suffix - String modifiedSuffix = suffix.replace("_", ""); - // Replace the original suffix in the input string with the modified one - return input.substring(0, input.length() - suffix.length()) + modifiedSuffix; - } - } - return input; // Return the original input if no suffix matches - } - - + int authTransactionIdLength = lengthOfTransactionId != null ? Integer.parseInt(lengthOfTransactionId) : 0; + final byte[] oidcTransactionIdBytes = transactionId.getBytes(); + final byte[] authTransactionIdBytes = new byte[authTransactionIdLength]; + int i = oidcTransactionIdBytes.length - 1; + int j = 0; + while (j < authTransactionIdLength) { + authTransactionIdBytes[j++] = oidcTransactionIdBytes[i--]; + if (i < 0) { + i = oidcTransactionIdBytes.length - 1; + } + } + return new String(authTransactionIdBytes); + } + + private static String removeSuffixUnderscores(String input, String[] suffixes) { + for (String suffix : suffixes) { + if (input.endsWith(suffix)) { + // Remove underscores from the suffix + String modifiedSuffix = suffix.replace("_", ""); + // Replace the original suffix in the input string with the modified one + return input.substring(0, input.length() - suffix.length()) + modifiedSuffix; + } + } + return input; // Return the original input if no suffix matches + } + public static String getTestCaseIDFromKeyword(String keyword) { String[] suffixes = { "time_slot_from$", "appointment_date$", "access_token$" }; @@ -3137,7 +3130,6 @@ public static String getTestCaseIDFromKeyword(String keyword) { return tempString; } - public String replaceKeywordWithValue(String jsonString, String keyword, String value) { if (value != null && !value.isEmpty()) @@ -3174,9 +3166,6 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$POLICYNUMBERFORSUNBIRDRC$", properties.getProperty("policyNumberForSunBirdRC")); } - - - if (jsonString.contains("$FULLNAMEFORSUNBIRDRC$")) { jsonString = replaceKeywordWithValue(jsonString, "$FULLNAMEFORSUNBIRDRC$", fullNameForSunBirdRC); @@ -3185,12 +3174,12 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$DOBFORSUNBIRDRC$")) { jsonString = replaceKeywordWithValue(jsonString, "$DOBFORSUNBIRDRC$", dobForSunBirdRC); } - + if (jsonString.contains("$CHALLENGEVALUEFORSUNBIRDRC$")) { jsonString = replaceKeywordWithValue(jsonString, "$CHALLENGEVALUEFORSUNBIRDRC$", properties.getProperty("challengeValueForSunBirdRC")); } - + if (jsonString.contains("$CHALLENGEVALUEFORSUNBIRDC$")) { HashMap mapForChallenge = new HashMap(); @@ -3271,8 +3260,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$RID$", genRid); if (jsonString.contains("$SCHEMAVERSION$")) - jsonString = replaceKeywordWithValue(jsonString, "$SCHEMAVERSION$", generateLatestSchemaVersion()); - + jsonString = replaceKeywordWithValue(jsonString, "$SCHEMAVERSION$", generateLatestSchemaVersion()); if (jsonString.contains("$PHONENUMBERFORIDENTITY$")) { String phoneNumber = ""; @@ -3284,20 +3272,18 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { } jsonString = replaceKeywordWithValue(jsonString, "$PHONENUMBERFORIDENTITY$", phoneNumber); } - + if (jsonString.contains("$NRCID$")) { - String nrcId = (100000 + new Random().nextInt(900000)) + "/" + (10 + new Random().nextInt(90)) + "/" + (1 + new Random().nextInt(9)); + String nrcId = (100000 + new Random().nextInt(900000)) + "/" + (10 + new Random().nextInt(90)) + "/" + + (1 + new Random().nextInt(9)); jsonString = replaceKeywordWithValue(jsonString, "$NRCID$", nrcId); } - - - + if (jsonString.contains("$1STLANG$")) jsonString = replaceKeywordWithValue(jsonString, "$1STLANG$", BaseTestCase.languageList.get(0)); if (jsonString.contains("$2NDLANG$")) jsonString = replaceKeywordWithValue(jsonString, "$2NDLANG$", BaseTestCase.languageList.get(1)); - if (jsonString.contains(GlobalConstants.KEYCLOAK_USER_1)) jsonString = replaceKeywordWithValue(jsonString, GlobalConstants.KEYCLOAK_USER_1, @@ -3390,7 +3376,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$USERID$")) jsonString = replaceKeywordWithValue(jsonString, "$USERID$", BaseTestCase.currentModule + ConfigManager.getproperty("admin_userName")); - + if (jsonString.contains("$LEAF_ZONE_CODE$")) jsonString = replaceKeywordWithValue(jsonString, "$LEAF_ZONE_CODE$", leafZoneCode); @@ -3410,13 +3396,14 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$PARENTLOCCODE$")) { jsonString = replaceKeywordWithValue(jsonString, "$PARENTLOCCODE$", parentLocCode); } - + if (jsonString.contains("$LOCATIONNAME$")) { jsonString = replaceKeywordWithValue(jsonString, "$LOCATIONNAME$", locationName); } - + if (jsonString.contains("$HIERARCHYLEVELWITHLOCATIONCODE$")) { - jsonString = replaceKeywordWithValue(jsonString, "$HIERARCHYLEVELWITHLOCATIONCODE$", String.valueOf(hierarchyLevelWithLocationCode)); + jsonString = replaceKeywordWithValue(jsonString, "$HIERARCHYLEVELWITHLOCATIONCODE$", + String.valueOf(hierarchyLevelWithLocationCode)); } if (jsonString.contains("$CACERT$")) { @@ -3545,8 +3532,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { publickey = JsonPrecondtion.getJsonValueFromJson(jsonString, "request.publicKey"); } if (jsonString.contains("$PUBLICKEYFORBINDING$")) { - jsonString = replaceKeywordWithValue(jsonString, "$PUBLICKEYFORBINDING$", - generatePublicKeyForMimoto()); + jsonString = replaceKeywordWithValue(jsonString, "$PUBLICKEYFORBINDING$", generatePublicKeyForMimoto()); } if (jsonString.contains("$BLOCKEDPARTNERID$")) { jsonString = replaceKeywordWithValue(jsonString, "$BLOCKEDPARTNERID$", getPartnerId()); @@ -3569,12 +3555,12 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$RANDOMID$2", RANDOM_ID_2); jsonString = replaceKeywordWithValue(jsonString, "$RANDOMID$", RANDOM_ID); } - + if (jsonString.contains("$RANDOMIDFOROIDCCLIENT$")) { jsonString = replaceKeywordWithValue(jsonString, "$RANDOMIDFOROIDCCLIENT$", "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis()); } - + if (jsonString.contains("$RANDOMUUID$")) { jsonString = replaceKeywordWithValue(jsonString, "$RANDOMUUID$", UUID.randomUUID().toString()); } @@ -3588,10 +3574,10 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$OIDCCLIENT$", getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.module.clientID")); } - - if (jsonString.contains("$DOB$")) { - jsonString = replaceKeywordWithValue(jsonString, "$DOB$", - getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.date-of-birth.pattern")); + + if (jsonString.contains("$DOB$")) { + jsonString = replaceKeywordWithValue(jsonString, "$DOB$", + getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.date-of-birth.pattern")); } if (jsonString.contains("$IDPREDIRECTURI$")) { jsonString = replaceKeywordWithValue(jsonString, "$IDPREDIRECTURI$", @@ -3775,9 +3761,9 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (request.has("client_id")) { clientId = request.get("client_id").toString(); } - + String tempUrl = getValueFromEsignetWellKnownEndPoint("token_endpoint", ConfigManager.getEsignetBaseUrl()); - + jsonString = replaceKeywordWithValue(jsonString, "$CLIENT_ASSERTION_JWK$", signJWKKey(clientId, oidcJWKKey1, tempUrl)); } @@ -3796,7 +3782,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (request.has("client_id")) { clientId = request.get("client_id").toString(); } - + String tempUrl = getValueFromEsignetWellKnownEndPoint("token_endpoint", ConfigManager.getEsignetBaseUrl()); jsonString = replaceKeywordWithValue(jsonString, "$CLIENT_ASSERTION_USER3_JWK$", signJWKKey(clientId, oidcJWKKey3, tempUrl)); @@ -3948,10 +3934,10 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$NAMEFORUPDATEUIN$")) { String name = getValueFromAuthActuator("json-property", "name"); String nameResult = ""; - + if (new JSONArray(name).length() > 1) { nameResult = new JSONArray(name).getString(0); - }else { + } else { nameResult = name.replaceAll("\\[\"|\"\\]", ""); } jsonString = replaceKeywordWithValue(jsonString, "$NAMEFORUPDATEUIN$", nameResult); @@ -4030,22 +4016,26 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$PROOF_JWT_2$", signJWKForMock(clientId, accessToken, oidcJWKKey4, testCaseName, tempUrl)); } - - if (jsonString.contains(GlobalConstants.IDT_TOKEN) && jsonString.contains("$IDTINDIVIUALID$") && jsonString.contains("$IDTCHALLENGE$")) { + + if (jsonString.contains(GlobalConstants.IDT_TOKEN)) { + JSONObject request = new JSONObject(jsonString); String idtToken = request.get(GlobalConstants.IDT_TOKEN).toString(); request.remove(GlobalConstants.IDT_TOKEN); jsonString = request.toString(); - Map map = new HashMap<>(); map.put(GlobalConstants.TOKEN, idtToken); JSONObject encodingToken = new JSONObject(map); - String challenge = encodeBase64(encodingToken.toString()); - String individualId = getSubjectFromJwt(idtToken); + if (jsonString.contains("$IDTINDIVIUALID$")) { + String individualId = getSubjectFromJwt(idtToken); + jsonString = replaceKeywordWithValue(jsonString, "$IDTINDIVIUALID$", individualId); + } - jsonString = replaceKeywordWithValue(jsonString, "$IDTINDIVIUALID$", individualId); - jsonString = replaceKeywordWithValue(jsonString, "$IDTCHALLENGE$", challenge); + if (jsonString.contains("$IDTCHALLENGE$")) { + String challenge = encodeBase64(encodingToken.toString()); + jsonString = replaceKeywordWithValue(jsonString, "$IDTCHALLENGE$", challenge); + } } @@ -4179,7 +4169,7 @@ else if (testCaseName.contains("_Invalid_Exp_")) } return proofJWT; } - + public static String generatePulicKey() { String publicKey = null; try { @@ -4192,7 +4182,7 @@ public static String generatePulicKey() { } return publicKey; } - + public static KeyPairGenerator keyPairGen = null; public static KeyPairGenerator getKeyPairGeneratorInstance() { @@ -4208,7 +4198,7 @@ public static KeyPairGenerator getKeyPairGeneratorInstance() { return keyPairGen; } - + public static String generateJWKPublicKey() { try { KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA"); @@ -4223,7 +4213,7 @@ public static String generateJWKPublicKey() { return null; } } - + public static String generatePublicKeyForMimoto() { String vcString = ""; @@ -4410,7 +4400,7 @@ else if (testCaseName.toLowerCase().startsWith(GlobalConstants.INJICERTIFY)) autoGenFileName = injiCertifyAutoGeneratedIdPropFileName; else if (testCaseName.toLowerCase().startsWith(GlobalConstants.SIGNUP)) autoGenFileName = signupAutoGeneratedIdPropFileName; - + else { autoGenFileName = "default"; logger.info("testCaseName: " + testCaseName); @@ -4436,13 +4426,12 @@ public String updateTimestampOtp(String otpIdentyEnryptRequest, String otpChanne otpIdentyEnryptRequest = JsonPrecondtion.parseAndReturnJsonContent(otpIdentyEnryptRequest, generateCurrentUTCTimeStamp(), "timestamp"); String otp = null; - + otp = OTPListener.getOtp(otpChannel); - - if(otp!=null && !otp.isBlank()){ + + if (otp != null && !otp.isBlank()) { otpIdentyEnryptRequest = JsonPrecondtion.parseAndReturnJsonContent(otpIdentyEnryptRequest, otp, "otp"); - } - else { + } else { logger.error("Not Able To Fetch OTP From SMTP"); } return otpIdentyEnryptRequest; @@ -4527,31 +4516,32 @@ private String replaceIdWithAutogeneratedId(String jsonString, String idKey, Str return jsonString; String keyForIdProperty = StringUtils.substringBetween(jsonString, idKey, "$"); String keyToReplace = ""; - + // mock = email,phone; default // mock = phone; // mock = email; // $ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$ - + // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone - if (keyForIdProperty.endsWith("_EMAIL") && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("phone")) { - String temp = idKey + keyForIdProperty + "$" ; //$ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$ - keyForIdProperty = keyForIdProperty.replace("_EMAIL", "_PHONE"); // AddIdentity_withValidParameters_smoke_Pos_PHONE - keyToReplace = temp; // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone - - jsonString = jsonString.replace(temp, temp + "@phone"); - - - } else if (keyForIdProperty.endsWith("_PHONE") && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("email")) { - String temp = idKey + keyForIdProperty + "$" ; //$ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$ - keyForIdProperty = keyForIdProperty.replace("_PHONE", "_EMAIL"); // AddIdentity_withValidParameters_smoke_Pos_EMAIL - keyToReplace = temp + "@phone"; + if (keyForIdProperty.endsWith("_EMAIL") + && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("phone")) { + String temp = idKey + keyForIdProperty + "$"; // $ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$ + keyForIdProperty = keyForIdProperty.replace("_EMAIL", "_PHONE"); // AddIdentity_withValidParameters_smoke_Pos_PHONE + keyToReplace = temp; // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone + + jsonString = jsonString.replace(temp, temp + "@phone"); + + } else if (keyForIdProperty.endsWith("_PHONE") + && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("email")) { + String temp = idKey + keyForIdProperty + "$"; // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$ + keyForIdProperty = keyForIdProperty.replace("_PHONE", "_EMAIL"); // AddIdentity_withValidParameters_smoke_Pos_EMAIL + keyToReplace = temp + "@phone"; } else { - keyToReplace = idKey + keyForIdProperty + "$"; //AddIdentity_withValidParameters_smoke_Pos_EMAIL + keyToReplace = idKey + keyForIdProperty + "$"; // AddIdentity_withValidParameters_smoke_Pos_EMAIL } - + Properties props = new Properties(); try (FileInputStream inputStream = new FileInputStream(getResourcePath() + autoGenIdFileName);) { @@ -4600,74 +4590,73 @@ private String replaceIdWithAutogeneratedId(String jsonString, String idKey, Str } public String removeObject(JSONObject object) { - List keysToRemove = new ArrayList<>(); - Iterator keysItr = object.keys(); + List keysToRemove = new ArrayList<>(); + Iterator keysItr = object.keys(); - while (keysItr.hasNext()) { - String key = keysItr.next(); - Object value = object.get(key); + while (keysItr.hasNext()) { + String key = keysItr.next(); + Object value = object.get(key); - if (value instanceof JSONArray) { - JSONArray array = (JSONArray) value; - JSONArray updatedArray = new JSONArray(); + if (value instanceof JSONArray) { + JSONArray array = (JSONArray) value; + JSONArray updatedArray = new JSONArray(); - for (int i = 0; i < array.length(); i++) { - Object arrayElement = array.get(i); + for (int i = 0; i < array.length(); i++) { + Object arrayElement = array.get(i); - // Check if array element is JSONObject - if (arrayElement instanceof JSONObject) { - String updatedObject = removeObject((JSONObject) arrayElement); - updatedArray.put(new JSONObject(updatedObject)); + // Check if array element is JSONObject + if (arrayElement instanceof JSONObject) { + String updatedObject = removeObject((JSONObject) arrayElement); + updatedArray.put(new JSONObject(updatedObject)); - } else if (arrayElement instanceof String) { - if (!arrayElement.equals(GlobalConstants.REMOVE)) { - updatedArray.put(arrayElement); - } + } else if (arrayElement instanceof String) { + if (!arrayElement.equals(GlobalConstants.REMOVE)) { + updatedArray.put(arrayElement); + } - } else if (arrayElement instanceof JSONArray) { - updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); - } - } + } else if (arrayElement instanceof JSONArray) { + updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); + } + } - object.put(key, updatedArray); + object.put(key, updatedArray); - } else if (value instanceof JSONObject) { - String objectContent = removeObject((JSONObject) value); - object.put(key, new JSONObject(objectContent)); + } else if (value instanceof JSONObject) { + String objectContent = removeObject((JSONObject) value); + object.put(key, new JSONObject(objectContent)); - } else if (value instanceof String && value.equals(GlobalConstants.REMOVE)) { - keysToRemove.add(key); - } - } + } else if (value instanceof String && value.equals(GlobalConstants.REMOVE)) { + keysToRemove.add(key); + } + } - for (String keyToRemove : keysToRemove) { - object.remove(keyToRemove); - } + for (String keyToRemove : keysToRemove) { + object.remove(keyToRemove); + } - return object.toString(); + return object.toString(); } // Helper method to process JSONArray elements private String removeObject(JSONArray array) { - JSONArray updatedArray = new JSONArray(); + JSONArray updatedArray = new JSONArray(); - for (int i = 0; i < array.length(); i++) { - Object arrayElement = array.get(i); + for (int i = 0; i < array.length(); i++) { + Object arrayElement = array.get(i); - if (arrayElement instanceof JSONObject) { - updatedArray.put(new JSONObject(removeObject((JSONObject) arrayElement))); + if (arrayElement instanceof JSONObject) { + updatedArray.put(new JSONObject(removeObject((JSONObject) arrayElement))); - } else if (arrayElement instanceof String && !arrayElement.equals(GlobalConstants.REMOVE)) { - updatedArray.put(arrayElement); - } else if (arrayElement instanceof JSONArray) { - updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); - } - } + } else if (arrayElement instanceof String && !arrayElement.equals(GlobalConstants.REMOVE)) { + updatedArray.put(arrayElement); + } else if (arrayElement instanceof JSONArray) { + updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); + } + } - return updatedArray.toString(); + return updatedArray.toString(); } - private String removeObject(JSONObject object, String tempArrayContent) { Iterator keysItr = object.keys(); while (keysItr.hasNext()) { @@ -4800,7 +4789,7 @@ public String generateSignatureWithRequest(String request, String partnerId) { String singResponse = null; try { singResponse = sign(request, false, true, false, null, getKeysDirPath(), partnerId); - } catch (NoSuchAlgorithmException | UnrecoverableEntryException | KeyStoreException | CertificateException + } catch (NoSuchAlgorithmException | UnrecoverableEntryException | KeyStoreException | CertificateException | OperatorCreationException | JoseException | IOException e) { logger.error(e.getMessage()); } @@ -4847,7 +4836,7 @@ public static void copyResidentTestResource() { public static void copyPartnerTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.PARTNER); } - + public static void copyPmsNewTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.PARTNERNEW); } @@ -4903,7 +4892,8 @@ private static ArrayList convertJson(String[] templateFields, String isFilterRequired = true; } } else if (jsonObject.has(GlobalConstants.KEYWORD_DATA)) { - String filterValueToConvert = jsonObject.getJSONArray(GlobalConstants.KEYWORD_DATA).get(0).toString(); + String filterValueToConvert = jsonObject.getJSONArray(GlobalConstants.KEYWORD_DATA).get(0) + .toString(); JSONObject filtervalue = new JSONObject(filterValueToConvert); if (filtervalue.has(fieldToConvert)) { valueToConvert = filtervalue.getString(fieldToConvert); @@ -4999,13 +4989,15 @@ public static String getKeysDirPath() { // String path = "/Users/kamalsingh/mosip/authcerts" + "/" + "IDA-" + environment + ".mosip.net"; // logger.info("certificate path is::" + path); // return new File(path).getAbsolutePath(); - - String certsTargetDir = System.getProperty("java.io.tmpdir") + File.separator + System.getProperty("parent.certs.folder.name", "AUTHCERTS"); + + String certsTargetDir = System.getProperty("java.io.tmpdir") + File.separator + + System.getProperty("parent.certs.folder.name", "AUTHCERTS"); if (System.getProperty("os.name").toLowerCase().contains("windows") == false) { - certsTargetDir = "/home/mosip/authcerts"; - } - logger.info("Certs target path is: " +certsTargetDir + File.separator + certsForModule + "-IDA-" + environment + ".mosip.net"); + certsTargetDir = "/home/mosip/authcerts"; + } + logger.info("Certs target path is: " + certsTargetDir + File.separator + certsForModule + "-IDA-" + environment + + ".mosip.net"); return certsTargetDir + File.separator + certsForModule + "-IDA-" + environment + ".mosip.net"; } @@ -5299,476 +5291,461 @@ public static String modifySchemaGenerateHbs() { } public static String modifySchemaGenerateHbs(boolean regenerateHbs) { - if (identityHbs != null && !regenerateHbs) { - - return identityHbs; - } - JSONObject requestJson = new JSONObject(); - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); - - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); - - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); - - Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); - - String schemaFile = schemaJsonData; - - boolean emailFieldAdditionallyAdded = false; - boolean phoneFieldAdditionallyAdded = false; - try { - JSONObject schemaFileJson = new JSONObject(schemaFile); - JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); - JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); - JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); - JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); - - schemaRequiredField = requiredPropsArray.toString(); - - String phone = getValueFromAuthActuator("json-property", "phone_number"); - String result = phone.replaceAll("\\[\"|\"\\]", ""); - - - - if (!isElementPresent(requiredPropsArray, result)) { - requiredPropsArray.put(result); - phoneFieldAdditionallyAdded = true; - } - if (identityPropsJson.has(result)) { - phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators") - .getJSONObject(0).getString("validator"); - } - - String email = getValueFromAuthActuator("json-property", "emailId"); - String emailResult = email.replaceAll("\\[\"|\"\\]", ""); - - if (!isElementPresent(requiredPropsArray, emailResult)) { - requiredPropsArray.put(emailResult); - emailFieldAdditionallyAdded = true; - } - - requestJson.put("id", "{{id}}"); - requestJson.put("request", new HashMap<>()); - requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); - JSONObject identityJson = new JSONObject(); - identityJson.put("UIN", "{{UIN}}"); - JSONArray handleArray = new JSONArray(); - handleArray.put("handles"); - - List selectedHandles = new ArrayList<>(); - //requiredPropsArray.put("functionalId"); - for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { - String eachRequiredProp = requiredPropsArray.getString(i); - - if (!identityPropsJson.has(eachRequiredProp)) { - continue; - } - - JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); - String randomValue = ""; - if(eachRequiredProp == emailResult) { - randomValue ="shshssh"; - } - if(eachRequiredProp == result) { - randomValue =phoneSchemaRegex ; - } - - - // Processing for TaggedListType - if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { - JSONArray eachPropDataArrayForHandles = new JSONArray(); - JSONObject eachValueJsonForHandles = new JSONObject(); - if (eachRequiredProp.equals(emailResult)) { - eachValueJsonForHandles.put("value", "$EMAILVALUE$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(emailResult); - - } else if (eachRequiredProp.equals(result)) { - eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); - //"tags": ":["handle"] - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(result); - } - - else if (eachRequiredProp.equals("nrcId")) { - eachValueJsonForHandles.put("value", "$NRCID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add("nrcId"); - } - - else { - eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(eachRequiredProp); - } - eachPropDataArrayForHandles.put(eachValueJsonForHandles); - identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); - - } - - - - else if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("simpleType")) { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - JSONArray eachPropDataArray = new JSONArray(); - - for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { - if (BaseTestCase.getLanguageList().get(j) != null - && !BaseTestCase.getLanguageList().get(j).isEmpty()) { - JSONObject eachValueJson = new JSONObject(); - eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); - if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); - } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); - } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); - } else { - eachValueJson.put(GlobalConstants.VALUE, - (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp - : propsMap.getProperty(eachRequiredProp) + BaseTestCase.getLanguageList().get(j)); - } - eachPropDataArray.put(eachValueJson); - } - } - identityJson.put(eachRequiredProp, eachPropDataArray); - - } else { - if (eachRequiredProp.equals("proofOfIdentity")) { - - identityJson.put(eachRequiredProp, new HashMap<>()); - identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); - identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); - identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); - } else if (eachRequiredProp.equals("proofOfAddress")) { - identityJson.put(eachRequiredProp, new HashMap<>()); - identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); - identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); - identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); - } else if (eachRequiredProp.equals("preferredLang")) { - identityJson.put(eachRequiredProp, "$1STLANG$"); - } else if (eachRequiredProp.equals("registrationType")) { - identityJson.put(eachRequiredProp, genStringAsperRegex( - eachPropDataJson.getJSONArray("validators").getJSONObject(0).getString("validator"))); - } else if (eachRequiredProp.equals(result)) { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); - } else if (eachRequiredProp.equals(emailResult)) { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$EMAILVALUE$"); - } - - else if (eachRequiredProp.equals("nrcId")) { - String nrcID = "$NRCID$"; - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, nrcID); - } - - else if (eachRequiredProp.equals("password")) { - identityJson.put(eachRequiredProp, new HashMap<>()); - if (addIdentityPassword.isBlank() && addIdentitySalt.isBlank()) - getPasswordSaltFromKeyManager(PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION); - identityJson.getJSONObject(eachRequiredProp).put("hash", addIdentityPassword); - identityJson.getJSONObject(eachRequiredProp).put("salt", addIdentitySalt); - } else if (eachRequiredProp.equals("individualBiometrics")) { - identityJson.put(eachRequiredProp, new HashMap<>()); - identityJson.getJSONObject(eachRequiredProp).put("format", "cbeff"); - identityJson.getJSONObject(eachRequiredProp).put("version", 1); - identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); - } else if (eachRequiredProp.equals("IDSchemaVersion")) { - identityJson.put(eachRequiredProp, schemaVersion); - } else { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); - } - } - } - if (selectedHandles != null && selectedHandles.size()>=1) { - setfoundHandlesInIdSchema(true); - identityJson.put("selectedHandles", selectedHandles); - } - - - // Constructing and adding functionalIds - JSONArray functionalIdsArray = new JSONArray(); - for (String language : BaseTestCase.getLanguageList()) { - if (language != null && !language.isEmpty()) { - JSONObject functionalId = new JSONObject(); - functionalId.put("value", "TEST_CITY" + language); - functionalIdsArray.put(functionalId); - } - } - //identityJson.put("functionalIds", functionalIdsArray); - - if (isElementPresent(requiredPropsArray, "individualBiometrics")) { - JSONArray requestDocArray = new JSONArray(); - JSONObject docJson = new JSONObject(); - docJson.put("value", "{{value}}"); - docJson.put("category", "{{category}}"); - requestDocArray.put(docJson); - - requestJson.getJSONObject("request").put("documents", requestDocArray); - } - requestJson.getJSONObject("request").put("identity", identityJson); - requestJson.put("requesttime", "{{requesttime}}"); - requestJson.put("version", "{{version}}"); - - System.out.println(requestJson); - - } catch (Exception e) { - logger.error(e.getMessage()); - } - - identityHbs = requestJson.toString(); - return identityHbs; - } - - + if (identityHbs != null && !regenerateHbs) { + + return identityHbs; + } + JSONObject requestJson = new JSONObject(); + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); + + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + + Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); + + String schemaFile = schemaJsonData; + + boolean emailFieldAdditionallyAdded = false; + boolean phoneFieldAdditionallyAdded = false; + try { + JSONObject schemaFileJson = new JSONObject(schemaFile); + JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); + JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); + JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); + JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); + + schemaRequiredField = requiredPropsArray.toString(); + + String phone = getValueFromAuthActuator("json-property", "phone_number"); + String result = phone.replaceAll("\\[\"|\"\\]", ""); + + if (!isElementPresent(requiredPropsArray, result)) { + requiredPropsArray.put(result); + phoneFieldAdditionallyAdded = true; + } + if (identityPropsJson.has(result)) { + phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators").getJSONObject(0) + .getString("validator"); + } + + String email = getValueFromAuthActuator("json-property", "emailId"); + String emailResult = email.replaceAll("\\[\"|\"\\]", ""); + + if (!isElementPresent(requiredPropsArray, emailResult)) { + requiredPropsArray.put(emailResult); + emailFieldAdditionallyAdded = true; + } + + requestJson.put("id", "{{id}}"); + requestJson.put("request", new HashMap<>()); + requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); + JSONObject identityJson = new JSONObject(); + identityJson.put("UIN", "{{UIN}}"); + JSONArray handleArray = new JSONArray(); + handleArray.put("handles"); + + List selectedHandles = new ArrayList<>(); + // requiredPropsArray.put("functionalId"); + for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { + String eachRequiredProp = requiredPropsArray.getString(i); + + if (!identityPropsJson.has(eachRequiredProp)) { + continue; + } + + JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); + String randomValue = ""; + if (eachRequiredProp == emailResult) { + randomValue = "shshssh"; + } + if (eachRequiredProp == result) { + randomValue = phoneSchemaRegex; + } + + // Processing for TaggedListType + if (eachPropDataJson.has("$ref") + && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { + JSONArray eachPropDataArrayForHandles = new JSONArray(); + JSONObject eachValueJsonForHandles = new JSONObject(); + if (eachRequiredProp.equals(emailResult)) { + eachValueJsonForHandles.put("value", "$EMAILVALUE$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(emailResult); + + } else if (eachRequiredProp.equals(result)) { + eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); + // "tags": ":["handle"] + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(result); + } + + else if (eachRequiredProp.equals("nrcId")) { + eachValueJsonForHandles.put("value", "$NRCID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add("nrcId"); + } + + else { + eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(eachRequiredProp); + } + eachPropDataArrayForHandles.put(eachValueJsonForHandles); + identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); + + } + + else if (eachPropDataJson.has("$ref") + && eachPropDataJson.get("$ref").toString().contains("simpleType")) { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + JSONArray eachPropDataArray = new JSONArray(); + + for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { + if (BaseTestCase.getLanguageList().get(j) != null + && !BaseTestCase.getLanguageList().get(j).isEmpty()) { + JSONObject eachValueJson = new JSONObject(); + eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); + if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); + } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); + } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); + } else { + eachValueJson.put(GlobalConstants.VALUE, + (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp + : propsMap.getProperty(eachRequiredProp) + + BaseTestCase.getLanguageList().get(j)); + } + eachPropDataArray.put(eachValueJson); + } + } + identityJson.put(eachRequiredProp, eachPropDataArray); + + } else { + if (eachRequiredProp.equals("proofOfIdentity")) { + + identityJson.put(eachRequiredProp, new HashMap<>()); + identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); + identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); + identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); + } else if (eachRequiredProp.equals("proofOfAddress")) { + identityJson.put(eachRequiredProp, new HashMap<>()); + identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); + identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); + identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); + } else if (eachRequiredProp.equals("preferredLang")) { + identityJson.put(eachRequiredProp, "$1STLANG$"); + } else if (eachRequiredProp.equals("registrationType")) { + identityJson.put(eachRequiredProp, genStringAsperRegex( + eachPropDataJson.getJSONArray("validators").getJSONObject(0).getString("validator"))); + } else if (eachRequiredProp.equals(result)) { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); + } else if (eachRequiredProp.equals(emailResult)) { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$EMAILVALUE$"); + } + + else if (eachRequiredProp.equals("nrcId")) { + String nrcID = "$NRCID$"; + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, nrcID); + } + + else if (eachRequiredProp.equals("password")) { + identityJson.put(eachRequiredProp, new HashMap<>()); + if (addIdentityPassword.isBlank() && addIdentitySalt.isBlank()) + getPasswordSaltFromKeyManager(PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION); + identityJson.getJSONObject(eachRequiredProp).put("hash", addIdentityPassword); + identityJson.getJSONObject(eachRequiredProp).put("salt", addIdentitySalt); + } else if (eachRequiredProp.equals("individualBiometrics")) { + identityJson.put(eachRequiredProp, new HashMap<>()); + identityJson.getJSONObject(eachRequiredProp).put("format", "cbeff"); + identityJson.getJSONObject(eachRequiredProp).put("version", 1); + identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); + } else if (eachRequiredProp.equals("IDSchemaVersion")) { + identityJson.put(eachRequiredProp, schemaVersion); + } else { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); + } + } + } + if (selectedHandles != null && selectedHandles.size() >= 1) { + setfoundHandlesInIdSchema(true); + identityJson.put("selectedHandles", selectedHandles); + } + + // Constructing and adding functionalIds + JSONArray functionalIdsArray = new JSONArray(); + for (String language : BaseTestCase.getLanguageList()) { + if (language != null && !language.isEmpty()) { + JSONObject functionalId = new JSONObject(); + functionalId.put("value", "TEST_CITY" + language); + functionalIdsArray.put(functionalId); + } + } + // identityJson.put("functionalIds", functionalIdsArray); + + if (isElementPresent(requiredPropsArray, "individualBiometrics")) { + JSONArray requestDocArray = new JSONArray(); + JSONObject docJson = new JSONObject(); + docJson.put("value", "{{value}}"); + docJson.put("category", "{{category}}"); + requestDocArray.put(docJson); + + requestJson.getJSONObject("request").put("documents", requestDocArray); + } + requestJson.getJSONObject("request").put("identity", identityJson); + requestJson.put("requesttime", "{{requesttime}}"); + requestJson.put("version", "{{version}}"); + + System.out.println(requestJson); + + } catch (Exception e) { + logger.error(e.getMessage()); + } + + identityHbs = requestJson.toString(); + return identityHbs; + } + public static String updateIdentityHbs(boolean regenerateHbs) { - if (updateIdentityHbs != null && !regenerateHbs) { - - return updateIdentityHbs; - } - JSONObject requestJson = new JSONObject(); - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); - - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); - - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); - - Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); - - String schemaFile = schemaJsonData; - - boolean emailFieldAdditionallyAdded = false; - boolean phoneFieldAdditionallyAdded = false; - try { - JSONObject schemaFileJson = new JSONObject(schemaFile); - JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); - JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); - JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); - JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); - - schemaRequiredField = requiredPropsArray.toString(); - - String phone = getValueFromAuthActuator("json-property", "phone_number"); - String result = phone.replaceAll("\\[\"|\"\\]", ""); - - if (!isElementPresent(requiredPropsArray, result)) { - requiredPropsArray.put(result); - phoneFieldAdditionallyAdded = true; - } - if (identityPropsJson.has(result)) { - phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators") - .getJSONObject(0).getString("validator"); - } - - String email = getValueFromAuthActuator("json-property", "emailId"); - String emailResult = email.replaceAll("\\[\"|\"\\]", ""); - - if (!isElementPresent(requiredPropsArray, emailResult)) { - requiredPropsArray.put(emailResult); - emailFieldAdditionallyAdded = true; - } - - requestJson.put("id", "{{id}}"); - requestJson.put("status", "ACTIVATED"); - requestJson.put("request", new HashMap<>()); - requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); - JSONObject identityJson = new JSONObject(); - identityJson.put("UIN", "{{UIN}}"); - JSONArray handleArray = new JSONArray(); - handleArray.put("handles"); - - List selectedHandles = new ArrayList<>(); - //requiredPropsArray.put("functionalId"); - for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { - String eachRequiredProp = requiredPropsArray.getString(i); - - if (!identityPropsJson.has(eachRequiredProp)) { - continue; - } - - JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); - String randomValue = ""; - if(eachRequiredProp == emailResult) { - randomValue ="shshssh"; - } - if(eachRequiredProp == result) { - randomValue =phoneSchemaRegex ; - } - - - // Processing for TaggedListType - if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { - JSONArray eachPropDataArrayForHandles = new JSONArray(); - JSONObject eachValueJsonForHandles = new JSONObject(); - if (eachRequiredProp.equals(emailResult)) { - eachValueJsonForHandles.put("value", "$EMAILVALUE$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(emailResult); - - } else if (eachRequiredProp.equals(result)) { - eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); - //"tags": ":["handle"] - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(result); - } - - else if (eachRequiredProp.equals("nrcId")) { - eachValueJsonForHandles.put("value", "$NRCID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add("nrcId"); - } - - else { - eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(eachRequiredProp); - } - - - eachPropDataArrayForHandles.put(eachValueJsonForHandles); - identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); - - } - - - - else if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("simpleType")) { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - JSONArray eachPropDataArray = new JSONArray(); - - for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { - if (BaseTestCase.getLanguageList().get(j) != null - && !BaseTestCase.getLanguageList().get(j).isEmpty()) { - JSONObject eachValueJson = new JSONObject(); - eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); - if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); - } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); - } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); - } else { - eachValueJson.put(GlobalConstants.VALUE, - (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp - : propsMap.getProperty(eachRequiredProp) + BaseTestCase.getLanguageList().get(j)); - } - eachPropDataArray.put(eachValueJson); - } - } - identityJson.put(eachRequiredProp, eachPropDataArray); - - } else { - if (eachRequiredProp.equals("IDSchemaVersion")) { - identityJson.put(eachRequiredProp, schemaVersion); - } - else if (eachRequiredProp.equals("individualBiometrics")) { - identityJson.remove("individualBiometrics"); - } - else if (eachRequiredProp.equals(emailResult)) { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$EMAILVALUE$"); - } - else if (eachRequiredProp.equals(result)) { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); - } - else if (eachRequiredProp.equals("nrcId")) { - String nrcID = "$NRCID$"; - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, nrcID); - } - else if (eachRequiredProp.equals("proofOfIdentity")) { - identityJson.remove("proofOfIdentity"); - } - else { - if(eachPropDataJson.has("handle")){ - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); - } - } - } - if (selectedHandles != null) { - setfoundHandlesInIdSchema(true); - identityJson.put("selectedHandles", selectedHandles); - } - - - // Constructing and adding functionalIds - JSONArray functionalIdsArray = new JSONArray(); - for (String language : BaseTestCase.getLanguageList()) { - if (language != null && !language.isEmpty()) { - JSONObject functionalId = new JSONObject(); - functionalId.put("value", "TEST_CITY" + language); - functionalIdsArray.put(functionalId); - } - } - requestJson.getJSONObject("request").put("identity", identityJson); - requestJson.put("requesttime", "{{requesttime}}"); - requestJson.put("version", "{{version}}"); - - System.out.println(requestJson); - - } catch (Exception e) { - logger.error(e.getMessage()); - } - - updateIdentityHbs = requestJson.toString(); - return updateIdentityHbs; - } - - - - public static String generateLatestSchemaVersion() { - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + if (updateIdentityHbs != null && !regenerateHbs) { - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); + return updateIdentityHbs; + } + JSONObject requestJson = new JSONObject(); + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + + Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); + + String schemaFile = schemaJsonData; + + boolean emailFieldAdditionallyAdded = false; + boolean phoneFieldAdditionallyAdded = false; + try { + JSONObject schemaFileJson = new JSONObject(schemaFile); + JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); + JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); + JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); + JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); + + schemaRequiredField = requiredPropsArray.toString(); + + String phone = getValueFromAuthActuator("json-property", "phone_number"); + String result = phone.replaceAll("\\[\"|\"\\]", ""); - BigDecimal schemaVersion = schemaData.getBigDecimal(GlobalConstants.ID_VERSION); - String latestSchemaVersion = schemaVersion.toString(); - logger.info(latestSchemaVersion); - return latestSchemaVersion; + if (!isElementPresent(requiredPropsArray, result)) { + requiredPropsArray.put(result); + phoneFieldAdditionallyAdded = true; + } + if (identityPropsJson.has(result)) { + phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators").getJSONObject(0) + .getString("validator"); + } + + String email = getValueFromAuthActuator("json-property", "emailId"); + String emailResult = email.replaceAll("\\[\"|\"\\]", ""); + + if (!isElementPresent(requiredPropsArray, emailResult)) { + requiredPropsArray.put(emailResult); + emailFieldAdditionallyAdded = true; + } + + requestJson.put("id", "{{id}}"); + requestJson.put("status", "ACTIVATED"); + requestJson.put("request", new HashMap<>()); + requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); + JSONObject identityJson = new JSONObject(); + identityJson.put("UIN", "{{UIN}}"); + JSONArray handleArray = new JSONArray(); + handleArray.put("handles"); + + List selectedHandles = new ArrayList<>(); + // requiredPropsArray.put("functionalId"); + for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { + String eachRequiredProp = requiredPropsArray.getString(i); + + if (!identityPropsJson.has(eachRequiredProp)) { + continue; + } + + JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); + String randomValue = ""; + if (eachRequiredProp == emailResult) { + randomValue = "shshssh"; + } + if (eachRequiredProp == result) { + randomValue = phoneSchemaRegex; + } + + // Processing for TaggedListType + if (eachPropDataJson.has("$ref") + && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { + JSONArray eachPropDataArrayForHandles = new JSONArray(); + JSONObject eachValueJsonForHandles = new JSONObject(); + if (eachRequiredProp.equals(emailResult)) { + eachValueJsonForHandles.put("value", "$EMAILVALUE$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(emailResult); + + } else if (eachRequiredProp.equals(result)) { + eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); + // "tags": ":["handle"] + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(result); + } + + else if (eachRequiredProp.equals("nrcId")) { + eachValueJsonForHandles.put("value", "$NRCID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add("nrcId"); + } + + else { + eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(eachRequiredProp); + } + + eachPropDataArrayForHandles.put(eachValueJsonForHandles); + identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); + + } + + else if (eachPropDataJson.has("$ref") + && eachPropDataJson.get("$ref").toString().contains("simpleType")) { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + JSONArray eachPropDataArray = new JSONArray(); + + for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { + if (BaseTestCase.getLanguageList().get(j) != null + && !BaseTestCase.getLanguageList().get(j).isEmpty()) { + JSONObject eachValueJson = new JSONObject(); + eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); + if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); + } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); + } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); + } else { + eachValueJson.put(GlobalConstants.VALUE, + (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp + : propsMap.getProperty(eachRequiredProp) + + BaseTestCase.getLanguageList().get(j)); + } + eachPropDataArray.put(eachValueJson); + } + } + identityJson.put(eachRequiredProp, eachPropDataArray); + + } else { + if (eachRequiredProp.equals("IDSchemaVersion")) { + identityJson.put(eachRequiredProp, schemaVersion); + } else if (eachRequiredProp.equals("individualBiometrics")) { + identityJson.remove("individualBiometrics"); + } else if (eachRequiredProp.equals(emailResult)) { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$EMAILVALUE$"); + } else if (eachRequiredProp.equals(result)) { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); + } else if (eachRequiredProp.equals("nrcId")) { + String nrcID = "$NRCID$"; + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, nrcID); + } else if (eachRequiredProp.equals("proofOfIdentity")) { + identityJson.remove("proofOfIdentity"); + } else { + if (eachPropDataJson.has("handle")) { + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); + } + } + } + if (selectedHandles != null) { + setfoundHandlesInIdSchema(true); + identityJson.put("selectedHandles", selectedHandles); + } + + // Constructing and adding functionalIds + JSONArray functionalIdsArray = new JSONArray(); + for (String language : BaseTestCase.getLanguageList()) { + if (language != null && !language.isEmpty()) { + JSONObject functionalId = new JSONObject(); + functionalId.put("value", "TEST_CITY" + language); + functionalIdsArray.put(functionalId); + } + } + requestJson.getJSONObject("request").put("identity", identityJson); + requestJson.put("requesttime", "{{requesttime}}"); + requestJson.put("version", "{{version}}"); + + System.out.println(requestJson); + + } catch (Exception e) { + logger.error(e.getMessage()); + } + + updateIdentityHbs = requestJson.toString(); + return updateIdentityHbs; } + public static String generateLatestSchemaVersion() { + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); + + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + + BigDecimal schemaVersion = schemaData.getBigDecimal(GlobalConstants.ID_VERSION); + String latestSchemaVersion = schemaVersion.toString(); + logger.info(latestSchemaVersion); + return latestSchemaVersion; + } public static String generateHbsForUpdateDraft() { if (draftHbs != null) { @@ -5842,11 +5819,11 @@ public static String generateHbsForUpdateDraft() { identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); } - + else if (eachRequiredProp.equals("nrcId")) { - String nrcID = "$NRCID$"; - identityJson.put(eachRequiredProp, nrcID); - } + String nrcID = "$NRCID$"; + identityJson.put(eachRequiredProp, nrcID); + } else if (eachRequiredProp.equals("individualBiometrics")) { identityJson.put(eachRequiredProp, new HashMap<>()); @@ -6797,7 +6774,7 @@ public static String getValueFromEsignetWellKnownEndPoint(String key, String bas } return responseJson.getString(key); } - + public static String getValueFromInjiCertifyWellKnownEndPoint(String key, String baseURL) { String url = baseURL + ConfigManager.getproperty("injiCertifyWellKnownEndPoint"); @@ -6892,13 +6869,12 @@ public static String getValueFromActuator(String section, String key) { } } - + public static JSONArray mimotoActuatorResponseArray = null; public static String getValueFromMimotoActuator(String section, String key) { String url = ApplnURI + ConfigManager.getproperty("actuatorMimotoEndpoint"); - if (!(System.getenv("useOldContextURL") == null) - && !(System.getenv("useOldContextURL").isBlank()) + if (!(System.getenv("useOldContextURL") == null) && !(System.getenv("useOldContextURL").isBlank()) && System.getenv("useOldContextURL").equalsIgnoreCase("true")) { if (url.contains("/v1/mimoto/")) { url = url.replace("/v1/mimoto/", "/residentmobileapp/"); @@ -7138,31 +7114,30 @@ public static String getRegprocWaitFromActuator() { return waitInterval; } } - + private static Map testcaseIDNameMap = new HashMap<>(); - - public static void addTestCaseDetailsToMap(String testCaseName,String uniqueIdentifier) { + + public static void addTestCaseDetailsToMap(String testCaseName, String uniqueIdentifier) { testcaseIDNameMap.put(testCaseName, uniqueIdentifier); } - + public static String getTestCaseUniqueIdentifier(String testCaseName) { return testcaseIDNameMap.get(testCaseName); } - public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { String testCaseName = testCaseDTO.getTestCaseName(); - + int indexof = testCaseName.indexOf("_"); String modifiedTestCaseName = testCaseName.substring(indexof + 1); - + addTestCaseDetailsToMap(modifiedTestCaseName, testCaseDTO.getUniqueIdentifier()); - + JSONArray dobArray = new JSONArray(getValueFromAuthActuator("json-property", "dob")); JSONArray emailArray = new JSONArray(getValueFromAuthActuator("json-property", "emailId")); JSONArray phoneArray = new JSONArray(getValueFromAuthActuator("json-property", "phone_number")); JSONArray postalCodeArray = new JSONArray(getValueFromAuthActuator("json-property", "postal_code")); - + JSONArray individualBiometricsArray = new JSONArray( getValueFromAuthActuator("json-property", "individualBiometrics")); String dob = dobArray.getString(0); @@ -7174,28 +7149,23 @@ public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { && (!isElementPresent(new JSONArray(schemaRequiredField), dob))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); } - - if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("_handle") && foundHandlesInIdSchema == false) { + + if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("_handle") + && foundHandlesInIdSchema == false) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); } - - if (testCaseName.startsWith("IdRepository_") && - (testCaseName.contains("_withInvalidEmail") || - testCaseName.contains("_with_invalid_Email") || - testCaseName.contains("_with_Missing_Email") || - testCaseName.contains("_with_Empty_Email") || - testCaseName.contains("_with_SpaceVal_Email")) && - (globalRequiredFields != null && !globalRequiredFields.toList().contains(emailArray))) { + + if (testCaseName.startsWith("IdRepository_") && (testCaseName.contains("_withInvalidEmail") + || testCaseName.contains("_with_invalid_Email") || testCaseName.contains("_with_Missing_Email") + || testCaseName.contains("_with_Empty_Email") || testCaseName.contains("_with_SpaceVal_Email")) + && (globalRequiredFields != null && !globalRequiredFields.toList().contains(emailArray))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); - } - - if (testCaseName.startsWith("IdRepository_") && - testCaseName.contains("_with_Missing_phone") && - (globalRequiredFields != null && !globalRequiredFields.toList().contains(phoneArray))) { + } + + if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("_with_Missing_phone") + && (globalRequiredFields != null && !globalRequiredFields.toList().contains(phoneArray))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); - } - - + } else if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("Email") && (!isElementPresent(new JSONArray(schemaRequiredField), email))) { @@ -7230,16 +7200,16 @@ else if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("Inva && (ConfigManager.isInServiceNotDeployedList(GlobalConstants.HOTLIST))) { throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE); } - - } + + } else if (testCaseName.startsWith("Prereg_") && (testCaseName.contains("_Invalid_PostalCode_") || testCaseName.contains("_SpacialCharacter_PostalCode_")) && (globalRequiredFields != null && !globalRequiredFields.toList().contains(postalCodeArray))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); - } - + } + // else if (BaseTestCase.currentModule.equalsIgnoreCase(GlobalConstants.ESIGNET)) { // if ((testCaseName.startsWith("Esignet_") || testCaseName.startsWith("ESignet_")) // && (testCaseName.contains("_KycBioAuth_") || testCaseName.contains("_BioAuth_") @@ -7253,8 +7223,6 @@ else if (testCaseName.startsWith("Prereg_") && BaseTestCase.currentModule.equalsIgnoreCase("resident") && testCaseName.contains("_SignJWT_")) { throw new SkipException("esignet module is not deployed"); } - - if ((ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) && BaseTestCase.currentModule.equalsIgnoreCase("resident") @@ -7388,14 +7356,13 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) { if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) { emailId = request.getJSONObject(GlobalConstants.REQUEST).getString("userId"); logger.info(emailId); - - if(testCaseName.contains("_INVALIDOTP")) { + + if (testCaseName.contains("_INVALIDOTP")) { otp = "26258976"; - } - else { + } else { otp = OTPListener.getOtp(emailId); } - + request.getJSONObject(GlobalConstants.REQUEST).put("otp", otp); inputJson = request.toString(); return inputJson; @@ -7546,7 +7513,7 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) { if (emailId.endsWith(GlobalConstants.OTP_AS_PHONE)) emailId = emailId.replace(GlobalConstants.OTP_AS_PHONE, ""); logger.info(emailId); - if(testCaseName.contains("_EmptyChannel_Invalid_Neg")) + if (testCaseName.contains("_EmptyChannel_Invalid_Neg")) otp = ""; else otp = OTPListener.getOtp(emailId); @@ -7698,12 +7665,12 @@ public static void getLocationData() { if (!(languageList.size() > 1)) { currentLanguage = BaseTestCase.languageList.get(0); } - + for (int i = 0; i < data.length(); i++) { JSONObject entry = data.getJSONObject(i); String langCode = entry.getString("langCode"); hierarchyLevel = entry.getInt("hierarchyLevel"); - + if (hierarchyLevel == recommendedHierarchyLevel) { if (currentLanguage.equals(langCode)) { hierarchyName = entry.getString("hierarchyName"); @@ -7835,7 +7802,7 @@ public static void getZoneName() { logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); } } - + public static void getLeafZone() { Response response = null; @@ -7863,7 +7830,7 @@ public static void getLeafZone() { logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); } } - + public static void getRegistrationCenterData() { Response response = null; @@ -7879,7 +7846,8 @@ public static void getRegistrationCenterData() { responseJson = new JSONObject(response.getBody().asString()); try { - JSONObject responseObject = responseJson.getJSONObject("response").getJSONArray("registrationCenters").getJSONObject(0); + JSONObject responseObject = responseJson.getJSONObject("response").getJSONArray("registrationCenters") + .getJSONObject(0); locationCode = responseObject.getString("locationCode"); @@ -7891,12 +7859,13 @@ public static void getRegistrationCenterData() { logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); } } - + public static void getLocationDataWithLocationCode(String locationCode) { Response response = null; JSONObject responseJson = null; - String url = ApplnURI + props.getProperty("fetchLocationDataWithCode") + locationCode + "/" + BaseTestCase.getLanguageList().get(0); + String url = ApplnURI + props.getProperty("fetchLocationDataWithCode") + locationCode + "/" + + BaseTestCase.getLanguageList().get(0); String token = kernelAuthLib.getTokenByRole("globalAdmin"); try { @@ -8091,21 +8060,21 @@ public String getPasswordPattern() { } return password; } - + public String getSubjectFromJwt(String JwtEncodedString) { String subject = ""; try { - DecodedJWT decodedJWT = JWT.decode(JwtEncodedString); - subject = decodedJWT.getSubject(); - logger.info("The subject of the Jwt Encoded String is " + subject); + DecodedJWT decodedJWT = JWT.decode(JwtEncodedString); + subject = decodedJWT.getSubject(); + logger.info("The subject of the Jwt Encoded String is " + subject); } catch (JwtException e) { logger.info("Invalid JWT token."); } return subject; } - + public static JSONArray ArrayOfJsonObjects = null; - + public static JSONArray getSyncDataResponseArray() { if (ArrayOfJsonObjects != null) { return ArrayOfJsonObjects; @@ -8122,7 +8091,7 @@ public static JSONArray getSyncDataResponseArray() { } return ArrayOfJsonObjects; } - + public static boolean IsCertSyncd(String certSubjectSubString) { if (ArrayOfJsonObjects == null) { ArrayOfJsonObjects = getSyncDataResponseArray(); @@ -8138,19 +8107,17 @@ public static boolean IsCertSyncd(String certSubjectSubString) { } return false; } - - + public static void setfoundHandlesInIdSchema(boolean foundHandles) { - - foundHandlesInIdSchema=foundHandles; + + foundHandlesInIdSchema = foundHandles; } - - public static boolean isHandlesAvailableInIdSchema(boolean foundHandles) { - - return foundHandlesInIdSchema; + + public static boolean isHandlesAvailableInIdSchema(boolean foundHandles) { + + return foundHandlesInIdSchema; } - // public static boolean checkIsCertTrusted(String certIssuer, JSONArray ArrayOfJsonObjects, int recursiveCount) { // for (int i = 0; i < ArrayOfJsonObjects.length(); i++) { // if (ArrayOfJsonObjects.getJSONObject(i).has("certSubject") @@ -8191,38 +8158,33 @@ public static boolean isHandlesAvailableInIdSchema(boolean foundHandles) { // } // return false; // } - - - public static JSONArray getRequiredField() { - - - - JSONObject requestJson = new JSONObject(); - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); - - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); - - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); - - Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); - - String schemaFile = schemaJsonData; - - JSONObject schemaFileJson = new JSONObject(schemaFile); - JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); - JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); - globalRequiredFields = schemaIdentityJson.getJSONArray("required"); + + public static JSONArray getRequiredField() { + + JSONObject requestJson = new JSONObject(); + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); + + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + + Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); + + String schemaFile = schemaJsonData; + + JSONObject schemaFileJson = new JSONObject(schemaFile); + JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); + JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); + globalRequiredFields = schemaIdentityJson.getJSONArray("required"); return globalRequiredFields; - - } - -} + } +} diff --git a/apitest-commons/src/main/resources/config/Kernel.properties b/apitest-commons/src/main/resources/config/Kernel.properties index d508aa1ae8..3e5ebcb951 100644 --- a/apitest-commons/src/main/resources/config/Kernel.properties +++ b/apitest-commons/src/main/resources/config/Kernel.properties @@ -104,7 +104,6 @@ signupSettingsEndPoint=/v1/signup/settings esignetActuatorPropertySection=esignet-default.properties eSignetbaseurl= signupBaseUrl= -injiCertifyBaseURL= @@ -139,17 +138,17 @@ AuthClientID = mosip-resident-client #---------------------------------- Client Secret Keys -----------------------# #-- When test rig ran in docker, these values dervied from the environment ---# -mosip_partner_client_secret = -mosip_pms_client_secret = -mosip_resident_client_secret = -mosip_idrepo_client_secret = -mosip_reg_client_secret = -mosip_admin_client_secret = -mosip_hotlist_client_secret = -mosip_regproc_client_secret = -mpartner_default_mobile_secret = -mosip_testrig_client_secret = -AuthClientSecret = +mosip_partner_client_secret = 99tv8e83mlRKBoqc +mosip_pms_client_secret = ysd1exB4FXsZebbA +mosip_resident_client_secret = hYRNOwBlVfc3D3bY +mosip_idrepo_client_secret = mvBAX00IQ5NQT5fO +mosip_reg_client_secret = HCDIiTptc6vGh2NT +mosip_admin_client_secret = t4S9EXBDCWBy0rqG +mosip_hotlist_client_secret = wpTPqD8yXRsJaxGC +mosip_regproc_client_secret = bEUdGgFNUIenBc4d +mpartner_default_mobile_secret = y7amekWDgkESksgE +mosip_testrig_client_secret = mj9ue2l98aeKoVCM +AuthClientSecret = hYRNOwBlVfc3D3bY @@ -171,8 +170,8 @@ new_Resident_Password = mosip123 new_Resident_Role = default-roles-mosip,PARTNER_ADMIN roles.111995 = PARTNER_ADMIN,default-roles-mosip keycloak_UserName = admin -keycloak_Password = -keycloak-external-url = https://iam.camdgc-qa1.mosip.net +keycloak_Password = RwF3PlqGlP +keycloak-external-url = https://iam.es-qa.mosip.net keycloak-realm-id = mosip iam-users-to-create=111997,111998,220005,111992,globaladmin,111999,111887,111888 iam-users-password=mosip123,mosip123,mosip123,mosip123,mosip123,mosip123,mosip123,mosip123 @@ -194,27 +193,27 @@ pool_size=1 dialect=org.hibernate.dialect.PostgreSQLDialect show_sql=true current_session_context_class=thread -audit_url=jdbc:postgresql://camdgc-qa1.mosip.net:5432/mosip_audit +audit_url=jdbc:postgresql://es-qa.mosip.net:5432/mosip_audit audit_username=postgres -audit_password= +audit_password=hSKEJJm6RL audit_default_schema=audit DB_PORT= installation-domain= -partner_url=jdbc:postgresql://camdgc-qa1.mosip.net:5432/mosip_ida +partner_url=jdbc:postgresql://es-qa.mosip.net:5432/mosip_ida partner_username=postgres -partner_password= +partner_password=hSKEJJm6RL partner_default_schema=partner reportLogPath=automationLogAndReport postgresqlUser=postgresql db-port=5432 -db-server=camdgc-qa1.mosip.net +db-server=es-qa.mosip.net hibernate.connection.driver_class=org.postgresql.Driver hibernate.connection.pool_size=1 hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect hibernate.show_sql=true hibernate.current_session_context_class=thread db-su-user=postgres -postgres-password= +postgres-password=hSKEJJm6RL master_db_schema=master ida_db_schema=ida @@ -222,12 +221,12 @@ ida_db_schema=ida #------------------------ Generic properties ------------------------# enableDebug=yes preconfiguredOtp=111111 -usePreConfiguredOtp=false +usePreConfiguredOtp=true # supported values yes or no. Assume that by Default e-signet is deployed eSignetDeployed=yes partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732 -reportIgnoredTestCases=yes -reportKnownIssueTestCases=yes +reportIgnoredTestCases=no +reportKnownIssueTestCases=no servicesNotDeployed= esignetMockBaseURL=esignet-insurance. sunBirdBaseURL=registry @@ -263,9 +262,9 @@ langselect=0 #----------------------------------AuthDemoService Host properties----------------------------------------------------------# #Uncommemnt the below to run locally -#authCertsPath= +authCertsPath= #Uncommemnt the below to run in Docker -authCertsPath=/home/mosip/authcerts +#authCertsPath=/home/mosip/authcerts mosip_components_base_urls= From 44153e31760f1a3626c0760cdcbc3c6db79a32a3 Mon Sep 17 00:00:00 2001 From: NitinHegde Date: Thu, 5 Dec 2024 13:02:32 +0530 Subject: [PATCH 2/3] MOSIP-38033 changed if condition for the challengeList negative scenarios Signed-off-by: NitinHegde --- .../main/resources/config/Kernel.properties | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/apitest-commons/src/main/resources/config/Kernel.properties b/apitest-commons/src/main/resources/config/Kernel.properties index 3e5ebcb951..d508aa1ae8 100644 --- a/apitest-commons/src/main/resources/config/Kernel.properties +++ b/apitest-commons/src/main/resources/config/Kernel.properties @@ -104,6 +104,7 @@ signupSettingsEndPoint=/v1/signup/settings esignetActuatorPropertySection=esignet-default.properties eSignetbaseurl= signupBaseUrl= +injiCertifyBaseURL= @@ -138,17 +139,17 @@ AuthClientID = mosip-resident-client #---------------------------------- Client Secret Keys -----------------------# #-- When test rig ran in docker, these values dervied from the environment ---# -mosip_partner_client_secret = 99tv8e83mlRKBoqc -mosip_pms_client_secret = ysd1exB4FXsZebbA -mosip_resident_client_secret = hYRNOwBlVfc3D3bY -mosip_idrepo_client_secret = mvBAX00IQ5NQT5fO -mosip_reg_client_secret = HCDIiTptc6vGh2NT -mosip_admin_client_secret = t4S9EXBDCWBy0rqG -mosip_hotlist_client_secret = wpTPqD8yXRsJaxGC -mosip_regproc_client_secret = bEUdGgFNUIenBc4d -mpartner_default_mobile_secret = y7amekWDgkESksgE -mosip_testrig_client_secret = mj9ue2l98aeKoVCM -AuthClientSecret = hYRNOwBlVfc3D3bY +mosip_partner_client_secret = +mosip_pms_client_secret = +mosip_resident_client_secret = +mosip_idrepo_client_secret = +mosip_reg_client_secret = +mosip_admin_client_secret = +mosip_hotlist_client_secret = +mosip_regproc_client_secret = +mpartner_default_mobile_secret = +mosip_testrig_client_secret = +AuthClientSecret = @@ -170,8 +171,8 @@ new_Resident_Password = mosip123 new_Resident_Role = default-roles-mosip,PARTNER_ADMIN roles.111995 = PARTNER_ADMIN,default-roles-mosip keycloak_UserName = admin -keycloak_Password = RwF3PlqGlP -keycloak-external-url = https://iam.es-qa.mosip.net +keycloak_Password = +keycloak-external-url = https://iam.camdgc-qa1.mosip.net keycloak-realm-id = mosip iam-users-to-create=111997,111998,220005,111992,globaladmin,111999,111887,111888 iam-users-password=mosip123,mosip123,mosip123,mosip123,mosip123,mosip123,mosip123,mosip123 @@ -193,27 +194,27 @@ pool_size=1 dialect=org.hibernate.dialect.PostgreSQLDialect show_sql=true current_session_context_class=thread -audit_url=jdbc:postgresql://es-qa.mosip.net:5432/mosip_audit +audit_url=jdbc:postgresql://camdgc-qa1.mosip.net:5432/mosip_audit audit_username=postgres -audit_password=hSKEJJm6RL +audit_password= audit_default_schema=audit DB_PORT= installation-domain= -partner_url=jdbc:postgresql://es-qa.mosip.net:5432/mosip_ida +partner_url=jdbc:postgresql://camdgc-qa1.mosip.net:5432/mosip_ida partner_username=postgres -partner_password=hSKEJJm6RL +partner_password= partner_default_schema=partner reportLogPath=automationLogAndReport postgresqlUser=postgresql db-port=5432 -db-server=es-qa.mosip.net +db-server=camdgc-qa1.mosip.net hibernate.connection.driver_class=org.postgresql.Driver hibernate.connection.pool_size=1 hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect hibernate.show_sql=true hibernate.current_session_context_class=thread db-su-user=postgres -postgres-password=hSKEJJm6RL +postgres-password= master_db_schema=master ida_db_schema=ida @@ -221,12 +222,12 @@ ida_db_schema=ida #------------------------ Generic properties ------------------------# enableDebug=yes preconfiguredOtp=111111 -usePreConfiguredOtp=true +usePreConfiguredOtp=false # supported values yes or no. Assume that by Default e-signet is deployed eSignetDeployed=yes partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732 -reportIgnoredTestCases=no -reportKnownIssueTestCases=no +reportIgnoredTestCases=yes +reportKnownIssueTestCases=yes servicesNotDeployed= esignetMockBaseURL=esignet-insurance. sunBirdBaseURL=registry @@ -262,9 +263,9 @@ langselect=0 #----------------------------------AuthDemoService Host properties----------------------------------------------------------# #Uncommemnt the below to run locally -authCertsPath= +#authCertsPath= #Uncommemnt the below to run in Docker -#authCertsPath=/home/mosip/authcerts +authCertsPath=/home/mosip/authcerts mosip_components_base_urls= From bc9de20c4967fabba0000afe4e62699f0f3236ca Mon Sep 17 00:00:00 2001 From: NitinHegde Date: Thu, 5 Dec 2024 13:09:34 +0530 Subject: [PATCH 3/3] MOSIP-38033 changed if condition for the challengeList negative scenarios Signed-off-by: NitinHegde --- .../testrig/apirig/utils/AdminTestUtil.java | 1459 +++++++++-------- 1 file changed, 750 insertions(+), 709 deletions(-) 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 bbf7d08d41..61c9584933 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 @@ -139,9 +139,10 @@ public class AdminTestUtil extends BaseTestCase { protected static Properties properties = null; protected static Properties propsMap = null; protected static Properties propsBio = null; - public static String propsHealthCheckURL = getGlobalResourcePath() + "/" + "config/healthCheckEndpoint.properties"; + public static String propsHealthCheckURL = getGlobalResourcePath() + "/" + + "config/healthCheckEndpoint.properties"; private static String serverComponentsCommitDetails; - private static boolean foundHandlesInIdSchema = false; + private static boolean foundHandlesInIdSchema= false; private static JSONArray globalRequiredFields = null; protected static String token = null; String idToken = null; @@ -170,8 +171,9 @@ public class AdminTestUtil extends BaseTestCase { protected static String policygroupId = null; protected static String regDeviceResponse = null; protected static String generatedVID = null; - public String RANDOM_ID = "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis(); - public final String RANDOM_ID_2 = "mosip" + generateRandomNumberString(2) + public String RANDOM_ID = "mosip" + generateRandomNumberString(2) + + Calendar.getInstance().getTimeInMillis(); + public final String RANDOM_ID_2 = "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis(); public static final String RANDOM_ID_V2 = "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis(); @@ -254,6 +256,7 @@ public class AdminTestUtil extends BaseTestCase { public static final String BINDINGCERTCONSENTEMPTYCLAIMFILE = "BINDINGCERTCONSENTEMPTYCLAIMFile"; public static final String BINDINGCERTCONSENTUSER2FILE = "BINDINGCERTCONSENTUSER2File"; public static final String BINDINGCERTVIDCONSENTUSER2FILE = "BINDINGCERTCONSENTVIDUSER2File"; + private static final String UIN_CODE_VERIFIER_POS_1 = generateRandomAlphaNumericString(GlobalConstants.INTEGER_36); @@ -262,17 +265,24 @@ public class AdminTestUtil extends BaseTestCase { public static final int OTP_CHECK_INTERVAL = 10000; private static final Map actuatorValueCache = new HashMap<>(); - + + public static void init() { - properties = getproperty(getGlobalResourcePath() + "/" + "config/application.properties"); - propsMap = getproperty(getGlobalResourcePath() + "/" + "config/valueMapping.properties"); - propsBio = getproperty(getGlobalResourcePath() + "/" + "config/bioValue.properties"); - - PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION = properties.getProperty("passwordForAddIdentity"); + properties = getproperty( + getGlobalResourcePath() + "/" + "config/application.properties"); + propsMap = getproperty( + getGlobalResourcePath() + "/" + "config/valueMapping.properties"); + propsBio = getproperty( + getGlobalResourcePath() + "/" + "config/bioValue.properties"); + + PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION = properties + .getProperty("passwordForAddIdentity"); PASSWORD_TO_RESET = properties.getProperty("passwordToReset"); - + BaseTestCase.init(); } + + protected static boolean triggerESignetKeyGen1 = true; @@ -435,7 +445,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a String role, String testCaseName) { return postWithBodyAndCookie(url, jsonInput, auditLogCheck, cookieName, role, testCaseName, false); } - + protected Response postWithBodyAndCookie(String url, String jsonInput, boolean auditLogCheck, String cookieName, String role, String testCaseName, boolean bothAccessAndIdToken) { Response response = null; @@ -484,7 +494,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a return response; } - + protected Response deleteWithBodyAndCookie(String url, String jsonInput, String cookieName, String role, String testCaseName) { Response response = null; @@ -525,7 +535,7 @@ protected Response postWithBodyAndCookieWithText(String url, String jsonInput, S protected Response postWithBodyAndCookieWithoutBody(String url, String jsonInput, String cookieName, String role, String testCaseName) { Response response = null; - + String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); url = uriKeyWordHandelerUri(url, testCaseName); token = kernelAuthLib.getTokenByRole(role); @@ -560,7 +570,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin .toString(); headers.put(OAUTH_TRANSID_HEADERNAME, transactionId); } - + token = properties.getProperty(GlobalConstants.XSRFTOKEN); if (request.has(GlobalConstants.HEADERTRANSACTIONID)) { @@ -589,7 +599,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin cookiesMap.put(GlobalConstants.XSRF_TOKEN, token); request.remove(GlobalConstants.IDV_TRANSACTION_ID); } - + inputJson = request.toString(); if (BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA)) { inputJson = smtpOtpHandler(inputJson, testCaseName); @@ -717,7 +727,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin String pathFragmentCookie = null; String pathFragmentCookieTransactionId = null; Map cookiesMap = new HashMap<>(); - + if (request.has(GlobalConstants.ENCODEDHASH)) { encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString(); request.remove(GlobalConstants.ENCODEDHASH); @@ -731,16 +741,14 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN)); headers.put(OAUTH_HASH_HEADERNAME, encodedResp); headers.put(OAUTH_TRANSID_HEADERNAME, transactionId); - - if (request.has(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID) - && request.has(GlobalConstants.PATH_FRAGMENT_COOKIE)) { - pathFragmentCookieTransactionId = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID) - .toString(); + + if (request.has(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID) && request.has(GlobalConstants.PATH_FRAGMENT_COOKIE)) { + pathFragmentCookieTransactionId = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID).toString(); pathFragmentCookie = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE).toString(); request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID); request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE); } - + inputJson = request.toString(); if (BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.equals("auth") || BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET) @@ -749,7 +757,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin } token = properties.getProperty(GlobalConstants.XSRFTOKEN); - + if (request.has(GlobalConstants.IDV_TRANSACTION_ID)) { headerTransactionID = request.get(GlobalConstants.IDV_TRANSACTION_ID).toString(); headers.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID); @@ -757,20 +765,19 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin cookiesMap.put(GlobalConstants.XSRF_TOKEN, token); request.remove(GlobalConstants.IDV_TRANSACTION_ID); } - + logger.info(GlobalConstants.POST_REQ_URL + url); GlobalMethods.reportRequest(headers.toString(), inputJson, url); try { - if (pathFragmentCookie != null) { - response = RestClient.postRequestWithMultipleHeadersAndMultipleCookies(url, inputJson, - MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, pathFragmentCookieTransactionId, - pathFragmentCookie, headers); + if (pathFragmentCookie!=null) { + response = RestClient.postRequestWithMultipleHeadersAndMultipleCookies(url, inputJson, MediaType.APPLICATION_JSON, + MediaType.APPLICATION_JSON, pathFragmentCookieTransactionId, pathFragmentCookie, headers); } else if (cookiesMap.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) { response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookiesMap, headers); } else { - response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, - MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token, headers); + response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON, + MediaType.APPLICATION_JSON, cookieName, token, headers); } GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response); if (testCaseName.toLowerCase().contains("_sid")) { @@ -785,7 +792,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin return response; } } - + protected Response getRequestWithCookieAuthHeaderAndXsrfToken(String url, String jsonInput, String cookieName, String role, String testCaseName) { Response response = null; @@ -805,9 +812,9 @@ protected Response getRequestWithCookieAuthHeaderAndXsrfToken(String url, String headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN)); headers.put(OAUTH_HASH_HEADERNAME, encodedResp); headers.put(OAUTH_TRANSID_HEADERNAME, transactionId); - + token = null; - + if (request.has(GlobalConstants.IDV_SLOT_ALLOTED)) { token = request.get(GlobalConstants.IDV_SLOT_ALLOTED).toString(); cookieName = "IDV_SLOT_ALLOTTED"; @@ -976,7 +983,7 @@ protected Response postRequestWithCookieAuthHeaderAndSignature(String url, Strin headers.put(AUTHORIZATHION_HEADERNAME, AUTH_HEADER_VALUE); String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); headers.put(SIGNATURE_HEADERNAME, generateSignatureWithRequest(inputJson, partnerId)); - + if (testCaseName.contains("NOAUTH")) { token = ""; } else { @@ -2165,7 +2172,7 @@ protected Response getWithPathParamAndCookie(String url, String jsonInput, boole cookiesMap.put(GlobalConstants.XSRF_TOKEN, token); map.remove(GlobalConstants.VERIFIEDTRANSACTIONID); } - + if (map != null && map.containsKey(GlobalConstants.IDV_TRANSACTION_ID)) { headerTransactionID = map.get(GlobalConstants.IDV_TRANSACTION_ID).toString(); cookiesMap.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID); @@ -2893,7 +2900,7 @@ public static void initiateMimotoTest() { public static void initiateesignetTest() { copyEsignetTestResource(); } - + public static void initiateSignupTest() { copySignupTestResource(); } @@ -2917,7 +2924,7 @@ public static void copyMimotoTestResource() { public static void copyEsignetTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.ESIGNET); } - + public static void copySignupTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.SIGNUP); } @@ -3077,37 +3084,37 @@ public String uriKeyWordHandelerUri(String uri, String testCaseName) { return uri; } - + public static String getAuthTransactionId(String oidcTransactionId) { final String transactionId = oidcTransactionId.replaceAll("_|-", ""); String lengthOfTransactionId = AdminTestUtil.getValueFromEsignetActuator( ConfigManager.getEsignetActuatorPropertySection(), "mosip.esignet.auth-txn-id-length"); - int authTransactionIdLength = lengthOfTransactionId != null ? Integer.parseInt(lengthOfTransactionId) : 0; - final byte[] oidcTransactionIdBytes = transactionId.getBytes(); - final byte[] authTransactionIdBytes = new byte[authTransactionIdLength]; - int i = oidcTransactionIdBytes.length - 1; - int j = 0; - while (j < authTransactionIdLength) { - authTransactionIdBytes[j++] = oidcTransactionIdBytes[i--]; - if (i < 0) { - i = oidcTransactionIdBytes.length - 1; - } - } - return new String(authTransactionIdBytes); - } - - private static String removeSuffixUnderscores(String input, String[] suffixes) { - for (String suffix : suffixes) { - if (input.endsWith(suffix)) { - // Remove underscores from the suffix - String modifiedSuffix = suffix.replace("_", ""); - // Replace the original suffix in the input string with the modified one - return input.substring(0, input.length() - suffix.length()) + modifiedSuffix; - } - } - return input; // Return the original input if no suffix matches - } - + int authTransactionIdLength = lengthOfTransactionId != null ? Integer.parseInt(lengthOfTransactionId): 0; + final byte[] oidcTransactionIdBytes = transactionId.getBytes(); + final byte[] authTransactionIdBytes = new byte[authTransactionIdLength]; + int i = oidcTransactionIdBytes.length - 1; + int j = 0; + while(j < authTransactionIdLength) { + authTransactionIdBytes[j++] = oidcTransactionIdBytes[i--]; + if(i < 0) { i = oidcTransactionIdBytes.length - 1; } + } + return new String(authTransactionIdBytes); + } + + + private static String removeSuffixUnderscores(String input, String[] suffixes) { + for (String suffix : suffixes) { + if (input.endsWith(suffix)) { + // Remove underscores from the suffix + String modifiedSuffix = suffix.replace("_", ""); + // Replace the original suffix in the input string with the modified one + return input.substring(0, input.length() - suffix.length()) + modifiedSuffix; + } + } + return input; // Return the original input if no suffix matches + } + + public static String getTestCaseIDFromKeyword(String keyword) { String[] suffixes = { "time_slot_from$", "appointment_date$", "access_token$" }; @@ -3130,6 +3137,7 @@ public static String getTestCaseIDFromKeyword(String keyword) { return tempString; } + public String replaceKeywordWithValue(String jsonString, String keyword, String value) { if (value != null && !value.isEmpty()) @@ -3166,6 +3174,9 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$POLICYNUMBERFORSUNBIRDRC$", properties.getProperty("policyNumberForSunBirdRC")); } + + + if (jsonString.contains("$FULLNAMEFORSUNBIRDRC$")) { jsonString = replaceKeywordWithValue(jsonString, "$FULLNAMEFORSUNBIRDRC$", fullNameForSunBirdRC); @@ -3174,12 +3185,12 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$DOBFORSUNBIRDRC$")) { jsonString = replaceKeywordWithValue(jsonString, "$DOBFORSUNBIRDRC$", dobForSunBirdRC); } - + if (jsonString.contains("$CHALLENGEVALUEFORSUNBIRDRC$")) { jsonString = replaceKeywordWithValue(jsonString, "$CHALLENGEVALUEFORSUNBIRDRC$", properties.getProperty("challengeValueForSunBirdRC")); } - + if (jsonString.contains("$CHALLENGEVALUEFORSUNBIRDC$")) { HashMap mapForChallenge = new HashMap(); @@ -3260,7 +3271,8 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$RID$", genRid); if (jsonString.contains("$SCHEMAVERSION$")) - jsonString = replaceKeywordWithValue(jsonString, "$SCHEMAVERSION$", generateLatestSchemaVersion()); + jsonString = replaceKeywordWithValue(jsonString, "$SCHEMAVERSION$", generateLatestSchemaVersion()); + if (jsonString.contains("$PHONENUMBERFORIDENTITY$")) { String phoneNumber = ""; @@ -3272,18 +3284,20 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { } jsonString = replaceKeywordWithValue(jsonString, "$PHONENUMBERFORIDENTITY$", phoneNumber); } - + if (jsonString.contains("$NRCID$")) { - String nrcId = (100000 + new Random().nextInt(900000)) + "/" + (10 + new Random().nextInt(90)) + "/" - + (1 + new Random().nextInt(9)); + String nrcId = (100000 + new Random().nextInt(900000)) + "/" + (10 + new Random().nextInt(90)) + "/" + (1 + new Random().nextInt(9)); jsonString = replaceKeywordWithValue(jsonString, "$NRCID$", nrcId); } - + + + if (jsonString.contains("$1STLANG$")) jsonString = replaceKeywordWithValue(jsonString, "$1STLANG$", BaseTestCase.languageList.get(0)); if (jsonString.contains("$2NDLANG$")) jsonString = replaceKeywordWithValue(jsonString, "$2NDLANG$", BaseTestCase.languageList.get(1)); + if (jsonString.contains(GlobalConstants.KEYCLOAK_USER_1)) jsonString = replaceKeywordWithValue(jsonString, GlobalConstants.KEYCLOAK_USER_1, @@ -3376,7 +3390,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$USERID$")) jsonString = replaceKeywordWithValue(jsonString, "$USERID$", BaseTestCase.currentModule + ConfigManager.getproperty("admin_userName")); - + if (jsonString.contains("$LEAF_ZONE_CODE$")) jsonString = replaceKeywordWithValue(jsonString, "$LEAF_ZONE_CODE$", leafZoneCode); @@ -3396,14 +3410,13 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$PARENTLOCCODE$")) { jsonString = replaceKeywordWithValue(jsonString, "$PARENTLOCCODE$", parentLocCode); } - + if (jsonString.contains("$LOCATIONNAME$")) { jsonString = replaceKeywordWithValue(jsonString, "$LOCATIONNAME$", locationName); } - + if (jsonString.contains("$HIERARCHYLEVELWITHLOCATIONCODE$")) { - jsonString = replaceKeywordWithValue(jsonString, "$HIERARCHYLEVELWITHLOCATIONCODE$", - String.valueOf(hierarchyLevelWithLocationCode)); + jsonString = replaceKeywordWithValue(jsonString, "$HIERARCHYLEVELWITHLOCATIONCODE$", String.valueOf(hierarchyLevelWithLocationCode)); } if (jsonString.contains("$CACERT$")) { @@ -3532,7 +3545,8 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { publickey = JsonPrecondtion.getJsonValueFromJson(jsonString, "request.publicKey"); } if (jsonString.contains("$PUBLICKEYFORBINDING$")) { - jsonString = replaceKeywordWithValue(jsonString, "$PUBLICKEYFORBINDING$", generatePublicKeyForMimoto()); + jsonString = replaceKeywordWithValue(jsonString, "$PUBLICKEYFORBINDING$", + generatePublicKeyForMimoto()); } if (jsonString.contains("$BLOCKEDPARTNERID$")) { jsonString = replaceKeywordWithValue(jsonString, "$BLOCKEDPARTNERID$", getPartnerId()); @@ -3555,12 +3569,12 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$RANDOMID$2", RANDOM_ID_2); jsonString = replaceKeywordWithValue(jsonString, "$RANDOMID$", RANDOM_ID); } - + if (jsonString.contains("$RANDOMIDFOROIDCCLIENT$")) { jsonString = replaceKeywordWithValue(jsonString, "$RANDOMIDFOROIDCCLIENT$", "mosip" + generateRandomNumberString(2) + Calendar.getInstance().getTimeInMillis()); } - + if (jsonString.contains("$RANDOMUUID$")) { jsonString = replaceKeywordWithValue(jsonString, "$RANDOMUUID$", UUID.randomUUID().toString()); } @@ -3574,10 +3588,10 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$OIDCCLIENT$", getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.module.clientID")); } - - if (jsonString.contains("$DOB$")) { - jsonString = replaceKeywordWithValue(jsonString, "$DOB$", - getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.date-of-birth.pattern")); + + if (jsonString.contains("$DOB$")) { + jsonString = replaceKeywordWithValue(jsonString, "$DOB$", + getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.date-of-birth.pattern")); } if (jsonString.contains("$IDPREDIRECTURI$")) { jsonString = replaceKeywordWithValue(jsonString, "$IDPREDIRECTURI$", @@ -3761,9 +3775,9 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (request.has("client_id")) { clientId = request.get("client_id").toString(); } - + String tempUrl = getValueFromEsignetWellKnownEndPoint("token_endpoint", ConfigManager.getEsignetBaseUrl()); - + jsonString = replaceKeywordWithValue(jsonString, "$CLIENT_ASSERTION_JWK$", signJWKKey(clientId, oidcJWKKey1, tempUrl)); } @@ -3782,7 +3796,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (request.has("client_id")) { clientId = request.get("client_id").toString(); } - + String tempUrl = getValueFromEsignetWellKnownEndPoint("token_endpoint", ConfigManager.getEsignetBaseUrl()); jsonString = replaceKeywordWithValue(jsonString, "$CLIENT_ASSERTION_USER3_JWK$", signJWKKey(clientId, oidcJWKKey3, tempUrl)); @@ -3934,10 +3948,10 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { if (jsonString.contains("$NAMEFORUPDATEUIN$")) { String name = getValueFromAuthActuator("json-property", "name"); String nameResult = ""; - + if (new JSONArray(name).length() > 1) { nameResult = new JSONArray(name).getString(0); - } else { + }else { nameResult = name.replaceAll("\\[\"|\"\\]", ""); } jsonString = replaceKeywordWithValue(jsonString, "$NAMEFORUPDATEUIN$", nameResult); @@ -4016,7 +4030,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) { jsonString = replaceKeywordWithValue(jsonString, "$PROOF_JWT_2$", signJWKForMock(clientId, accessToken, oidcJWKKey4, testCaseName, tempUrl)); } - + if (jsonString.contains(GlobalConstants.IDT_TOKEN)) { JSONObject request = new JSONObject(jsonString); @@ -4169,7 +4183,7 @@ else if (testCaseName.contains("_Invalid_Exp_")) } return proofJWT; } - + public static String generatePulicKey() { String publicKey = null; try { @@ -4182,7 +4196,7 @@ public static String generatePulicKey() { } return publicKey; } - + public static KeyPairGenerator keyPairGen = null; public static KeyPairGenerator getKeyPairGeneratorInstance() { @@ -4198,7 +4212,7 @@ public static KeyPairGenerator getKeyPairGeneratorInstance() { return keyPairGen; } - + public static String generateJWKPublicKey() { try { KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA"); @@ -4213,7 +4227,7 @@ public static String generateJWKPublicKey() { return null; } } - + public static String generatePublicKeyForMimoto() { String vcString = ""; @@ -4400,7 +4414,7 @@ else if (testCaseName.toLowerCase().startsWith(GlobalConstants.INJICERTIFY)) autoGenFileName = injiCertifyAutoGeneratedIdPropFileName; else if (testCaseName.toLowerCase().startsWith(GlobalConstants.SIGNUP)) autoGenFileName = signupAutoGeneratedIdPropFileName; - + else { autoGenFileName = "default"; logger.info("testCaseName: " + testCaseName); @@ -4426,12 +4440,13 @@ public String updateTimestampOtp(String otpIdentyEnryptRequest, String otpChanne otpIdentyEnryptRequest = JsonPrecondtion.parseAndReturnJsonContent(otpIdentyEnryptRequest, generateCurrentUTCTimeStamp(), "timestamp"); String otp = null; - + otp = OTPListener.getOtp(otpChannel); - - if (otp != null && !otp.isBlank()) { + + if(otp!=null && !otp.isBlank()){ otpIdentyEnryptRequest = JsonPrecondtion.parseAndReturnJsonContent(otpIdentyEnryptRequest, otp, "otp"); - } else { + } + else { logger.error("Not Able To Fetch OTP From SMTP"); } return otpIdentyEnryptRequest; @@ -4516,32 +4531,31 @@ private String replaceIdWithAutogeneratedId(String jsonString, String idKey, Str return jsonString; String keyForIdProperty = StringUtils.substringBetween(jsonString, idKey, "$"); String keyToReplace = ""; - + // mock = email,phone; default // mock = phone; // mock = email; // $ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$ - + // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone - if (keyForIdProperty.endsWith("_EMAIL") - && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("phone")) { - String temp = idKey + keyForIdProperty + "$"; // $ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$ - keyForIdProperty = keyForIdProperty.replace("_EMAIL", "_PHONE"); // AddIdentity_withValidParameters_smoke_Pos_PHONE - keyToReplace = temp; // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone - - jsonString = jsonString.replace(temp, temp + "@phone"); - - } else if (keyForIdProperty.endsWith("_PHONE") - && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("email")) { - String temp = idKey + keyForIdProperty + "$"; // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$ - keyForIdProperty = keyForIdProperty.replace("_PHONE", "_EMAIL"); // AddIdentity_withValidParameters_smoke_Pos_EMAIL - keyToReplace = temp + "@phone"; + if (keyForIdProperty.endsWith("_EMAIL") && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("phone")) { + String temp = idKey + keyForIdProperty + "$" ; //$ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$ + keyForIdProperty = keyForIdProperty.replace("_EMAIL", "_PHONE"); // AddIdentity_withValidParameters_smoke_Pos_PHONE + keyToReplace = temp; // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone + + jsonString = jsonString.replace(temp, temp + "@phone"); + + + } else if (keyForIdProperty.endsWith("_PHONE") && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("email")) { + String temp = idKey + keyForIdProperty + "$" ; //$ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$ + keyForIdProperty = keyForIdProperty.replace("_PHONE", "_EMAIL"); // AddIdentity_withValidParameters_smoke_Pos_EMAIL + keyToReplace = temp + "@phone"; } else { - keyToReplace = idKey + keyForIdProperty + "$"; // AddIdentity_withValidParameters_smoke_Pos_EMAIL + keyToReplace = idKey + keyForIdProperty + "$"; //AddIdentity_withValidParameters_smoke_Pos_EMAIL } - + Properties props = new Properties(); try (FileInputStream inputStream = new FileInputStream(getResourcePath() + autoGenIdFileName);) { @@ -4590,73 +4604,74 @@ private String replaceIdWithAutogeneratedId(String jsonString, String idKey, Str } public String removeObject(JSONObject object) { - List keysToRemove = new ArrayList<>(); - Iterator keysItr = object.keys(); + List keysToRemove = new ArrayList<>(); + Iterator keysItr = object.keys(); - while (keysItr.hasNext()) { - String key = keysItr.next(); - Object value = object.get(key); + while (keysItr.hasNext()) { + String key = keysItr.next(); + Object value = object.get(key); - if (value instanceof JSONArray) { - JSONArray array = (JSONArray) value; - JSONArray updatedArray = new JSONArray(); + if (value instanceof JSONArray) { + JSONArray array = (JSONArray) value; + JSONArray updatedArray = new JSONArray(); - for (int i = 0; i < array.length(); i++) { - Object arrayElement = array.get(i); + for (int i = 0; i < array.length(); i++) { + Object arrayElement = array.get(i); - // Check if array element is JSONObject - if (arrayElement instanceof JSONObject) { - String updatedObject = removeObject((JSONObject) arrayElement); - updatedArray.put(new JSONObject(updatedObject)); + // Check if array element is JSONObject + if (arrayElement instanceof JSONObject) { + String updatedObject = removeObject((JSONObject) arrayElement); + updatedArray.put(new JSONObject(updatedObject)); - } else if (arrayElement instanceof String) { - if (!arrayElement.equals(GlobalConstants.REMOVE)) { - updatedArray.put(arrayElement); - } + } else if (arrayElement instanceof String) { + if (!arrayElement.equals(GlobalConstants.REMOVE)) { + updatedArray.put(arrayElement); + } - } else if (arrayElement instanceof JSONArray) { - updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); - } - } + } else if (arrayElement instanceof JSONArray) { + updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); + } + } - object.put(key, updatedArray); + object.put(key, updatedArray); - } else if (value instanceof JSONObject) { - String objectContent = removeObject((JSONObject) value); - object.put(key, new JSONObject(objectContent)); + } else if (value instanceof JSONObject) { + String objectContent = removeObject((JSONObject) value); + object.put(key, new JSONObject(objectContent)); - } else if (value instanceof String && value.equals(GlobalConstants.REMOVE)) { - keysToRemove.add(key); - } - } + } else if (value instanceof String && value.equals(GlobalConstants.REMOVE)) { + keysToRemove.add(key); + } + } - for (String keyToRemove : keysToRemove) { - object.remove(keyToRemove); - } + for (String keyToRemove : keysToRemove) { + object.remove(keyToRemove); + } - return object.toString(); + return object.toString(); } // Helper method to process JSONArray elements private String removeObject(JSONArray array) { - JSONArray updatedArray = new JSONArray(); + JSONArray updatedArray = new JSONArray(); - for (int i = 0; i < array.length(); i++) { - Object arrayElement = array.get(i); + for (int i = 0; i < array.length(); i++) { + Object arrayElement = array.get(i); - if (arrayElement instanceof JSONObject) { - updatedArray.put(new JSONObject(removeObject((JSONObject) arrayElement))); + if (arrayElement instanceof JSONObject) { + updatedArray.put(new JSONObject(removeObject((JSONObject) arrayElement))); - } else if (arrayElement instanceof String && !arrayElement.equals(GlobalConstants.REMOVE)) { - updatedArray.put(arrayElement); - } else if (arrayElement instanceof JSONArray) { - updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); - } - } + } else if (arrayElement instanceof String && !arrayElement.equals(GlobalConstants.REMOVE)) { + updatedArray.put(arrayElement); + } else if (arrayElement instanceof JSONArray) { + updatedArray.put(new JSONArray(removeObject((JSONArray) arrayElement))); + } + } - return updatedArray.toString(); + return updatedArray.toString(); } + private String removeObject(JSONObject object, String tempArrayContent) { Iterator keysItr = object.keys(); while (keysItr.hasNext()) { @@ -4789,7 +4804,7 @@ public String generateSignatureWithRequest(String request, String partnerId) { String singResponse = null; try { singResponse = sign(request, false, true, false, null, getKeysDirPath(), partnerId); - } catch (NoSuchAlgorithmException | UnrecoverableEntryException | KeyStoreException | CertificateException + } catch (NoSuchAlgorithmException | UnrecoverableEntryException | KeyStoreException | CertificateException | OperatorCreationException | JoseException | IOException e) { logger.error(e.getMessage()); } @@ -4836,7 +4851,7 @@ public static void copyResidentTestResource() { public static void copyPartnerTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.PARTNER); } - + public static void copyPmsNewTestResource() { copymoduleSpecificAndConfigFile(GlobalConstants.PARTNERNEW); } @@ -4892,8 +4907,7 @@ private static ArrayList convertJson(String[] templateFields, String isFilterRequired = true; } } else if (jsonObject.has(GlobalConstants.KEYWORD_DATA)) { - String filterValueToConvert = jsonObject.getJSONArray(GlobalConstants.KEYWORD_DATA).get(0) - .toString(); + String filterValueToConvert = jsonObject.getJSONArray(GlobalConstants.KEYWORD_DATA).get(0).toString(); JSONObject filtervalue = new JSONObject(filterValueToConvert); if (filtervalue.has(fieldToConvert)) { valueToConvert = filtervalue.getString(fieldToConvert); @@ -4989,15 +5003,13 @@ public static String getKeysDirPath() { // String path = "/Users/kamalsingh/mosip/authcerts" + "/" + "IDA-" + environment + ".mosip.net"; // logger.info("certificate path is::" + path); // return new File(path).getAbsolutePath(); - - String certsTargetDir = System.getProperty("java.io.tmpdir") + File.separator - + System.getProperty("parent.certs.folder.name", "AUTHCERTS"); + + String certsTargetDir = System.getProperty("java.io.tmpdir") + File.separator + System.getProperty("parent.certs.folder.name", "AUTHCERTS"); if (System.getProperty("os.name").toLowerCase().contains("windows") == false) { - certsTargetDir = "/home/mosip/authcerts"; - } - logger.info("Certs target path is: " + certsTargetDir + File.separator + certsForModule + "-IDA-" + environment - + ".mosip.net"); + certsTargetDir = "/home/mosip/authcerts"; + } + logger.info("Certs target path is: " +certsTargetDir + File.separator + certsForModule + "-IDA-" + environment + ".mosip.net"); return certsTargetDir + File.separator + certsForModule + "-IDA-" + environment + ".mosip.net"; } @@ -5291,462 +5303,477 @@ public static String modifySchemaGenerateHbs() { } public static String modifySchemaGenerateHbs(boolean regenerateHbs) { - if (identityHbs != null && !regenerateHbs) { - - return identityHbs; - } - JSONObject requestJson = new JSONObject(); - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); - - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); - - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); - - Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); - - String schemaFile = schemaJsonData; - - boolean emailFieldAdditionallyAdded = false; - boolean phoneFieldAdditionallyAdded = false; - try { - JSONObject schemaFileJson = new JSONObject(schemaFile); - JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); - JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); - JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); - JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); - - schemaRequiredField = requiredPropsArray.toString(); - - String phone = getValueFromAuthActuator("json-property", "phone_number"); - String result = phone.replaceAll("\\[\"|\"\\]", ""); - - if (!isElementPresent(requiredPropsArray, result)) { - requiredPropsArray.put(result); - phoneFieldAdditionallyAdded = true; - } - if (identityPropsJson.has(result)) { - phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators").getJSONObject(0) - .getString("validator"); - } - - String email = getValueFromAuthActuator("json-property", "emailId"); - String emailResult = email.replaceAll("\\[\"|\"\\]", ""); - - if (!isElementPresent(requiredPropsArray, emailResult)) { - requiredPropsArray.put(emailResult); - emailFieldAdditionallyAdded = true; - } - - requestJson.put("id", "{{id}}"); - requestJson.put("request", new HashMap<>()); - requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); - JSONObject identityJson = new JSONObject(); - identityJson.put("UIN", "{{UIN}}"); - JSONArray handleArray = new JSONArray(); - handleArray.put("handles"); - - List selectedHandles = new ArrayList<>(); - // requiredPropsArray.put("functionalId"); - for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { - String eachRequiredProp = requiredPropsArray.getString(i); - - if (!identityPropsJson.has(eachRequiredProp)) { - continue; - } - - JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); - String randomValue = ""; - if (eachRequiredProp == emailResult) { - randomValue = "shshssh"; - } - if (eachRequiredProp == result) { - randomValue = phoneSchemaRegex; - } - - // Processing for TaggedListType - if (eachPropDataJson.has("$ref") - && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { - JSONArray eachPropDataArrayForHandles = new JSONArray(); - JSONObject eachValueJsonForHandles = new JSONObject(); - if (eachRequiredProp.equals(emailResult)) { - eachValueJsonForHandles.put("value", "$EMAILVALUE$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(emailResult); - - } else if (eachRequiredProp.equals(result)) { - eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); - // "tags": ":["handle"] - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(result); - } - - else if (eachRequiredProp.equals("nrcId")) { - eachValueJsonForHandles.put("value", "$NRCID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add("nrcId"); - } - - else { - eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(eachRequiredProp); - } - eachPropDataArrayForHandles.put(eachValueJsonForHandles); - identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); - - } - - else if (eachPropDataJson.has("$ref") - && eachPropDataJson.get("$ref").toString().contains("simpleType")) { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - JSONArray eachPropDataArray = new JSONArray(); - - for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { - if (BaseTestCase.getLanguageList().get(j) != null - && !BaseTestCase.getLanguageList().get(j).isEmpty()) { - JSONObject eachValueJson = new JSONObject(); - eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); - if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); - } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); - } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); - } else { - eachValueJson.put(GlobalConstants.VALUE, - (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp - : propsMap.getProperty(eachRequiredProp) - + BaseTestCase.getLanguageList().get(j)); - } - eachPropDataArray.put(eachValueJson); - } - } - identityJson.put(eachRequiredProp, eachPropDataArray); - - } else { - if (eachRequiredProp.equals("proofOfIdentity")) { - - identityJson.put(eachRequiredProp, new HashMap<>()); - identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); - identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); - identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); - } else if (eachRequiredProp.equals("proofOfAddress")) { - identityJson.put(eachRequiredProp, new HashMap<>()); - identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); - identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); - identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); - } else if (eachRequiredProp.equals("preferredLang")) { - identityJson.put(eachRequiredProp, "$1STLANG$"); - } else if (eachRequiredProp.equals("registrationType")) { - identityJson.put(eachRequiredProp, genStringAsperRegex( - eachPropDataJson.getJSONArray("validators").getJSONObject(0).getString("validator"))); - } else if (eachRequiredProp.equals(result)) { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); - } else if (eachRequiredProp.equals(emailResult)) { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$EMAILVALUE$"); - } - - else if (eachRequiredProp.equals("nrcId")) { - String nrcID = "$NRCID$"; - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, nrcID); - } - - else if (eachRequiredProp.equals("password")) { - identityJson.put(eachRequiredProp, new HashMap<>()); - if (addIdentityPassword.isBlank() && addIdentitySalt.isBlank()) - getPasswordSaltFromKeyManager(PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION); - identityJson.getJSONObject(eachRequiredProp).put("hash", addIdentityPassword); - identityJson.getJSONObject(eachRequiredProp).put("salt", addIdentitySalt); - } else if (eachRequiredProp.equals("individualBiometrics")) { - identityJson.put(eachRequiredProp, new HashMap<>()); - identityJson.getJSONObject(eachRequiredProp).put("format", "cbeff"); - identityJson.getJSONObject(eachRequiredProp).put("version", 1); - identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); - } else if (eachRequiredProp.equals("IDSchemaVersion")) { - identityJson.put(eachRequiredProp, schemaVersion); - } else { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); - } - } - } - if (selectedHandles != null && selectedHandles.size() >= 1) { - setfoundHandlesInIdSchema(true); - identityJson.put("selectedHandles", selectedHandles); - } - - // Constructing and adding functionalIds - JSONArray functionalIdsArray = new JSONArray(); - for (String language : BaseTestCase.getLanguageList()) { - if (language != null && !language.isEmpty()) { - JSONObject functionalId = new JSONObject(); - functionalId.put("value", "TEST_CITY" + language); - functionalIdsArray.put(functionalId); - } - } - // identityJson.put("functionalIds", functionalIdsArray); - - if (isElementPresent(requiredPropsArray, "individualBiometrics")) { - JSONArray requestDocArray = new JSONArray(); - JSONObject docJson = new JSONObject(); - docJson.put("value", "{{value}}"); - docJson.put("category", "{{category}}"); - requestDocArray.put(docJson); - - requestJson.getJSONObject("request").put("documents", requestDocArray); - } - requestJson.getJSONObject("request").put("identity", identityJson); - requestJson.put("requesttime", "{{requesttime}}"); - requestJson.put("version", "{{version}}"); - - System.out.println(requestJson); - - } catch (Exception e) { - logger.error(e.getMessage()); - } - - identityHbs = requestJson.toString(); - return identityHbs; - } - + if (identityHbs != null && !regenerateHbs) { + + return identityHbs; + } + JSONObject requestJson = new JSONObject(); + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); + + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + + Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); + + String schemaFile = schemaJsonData; + + boolean emailFieldAdditionallyAdded = false; + boolean phoneFieldAdditionallyAdded = false; + try { + JSONObject schemaFileJson = new JSONObject(schemaFile); + JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); + JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); + JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); + JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); + + schemaRequiredField = requiredPropsArray.toString(); + + String phone = getValueFromAuthActuator("json-property", "phone_number"); + String result = phone.replaceAll("\\[\"|\"\\]", ""); + + + + if (!isElementPresent(requiredPropsArray, result)) { + requiredPropsArray.put(result); + phoneFieldAdditionallyAdded = true; + } + if (identityPropsJson.has(result)) { + phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators") + .getJSONObject(0).getString("validator"); + } + + String email = getValueFromAuthActuator("json-property", "emailId"); + String emailResult = email.replaceAll("\\[\"|\"\\]", ""); + + if (!isElementPresent(requiredPropsArray, emailResult)) { + requiredPropsArray.put(emailResult); + emailFieldAdditionallyAdded = true; + } + + requestJson.put("id", "{{id}}"); + requestJson.put("request", new HashMap<>()); + requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); + JSONObject identityJson = new JSONObject(); + identityJson.put("UIN", "{{UIN}}"); + JSONArray handleArray = new JSONArray(); + handleArray.put("handles"); + + List selectedHandles = new ArrayList<>(); + //requiredPropsArray.put("functionalId"); + for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { + String eachRequiredProp = requiredPropsArray.getString(i); + + if (!identityPropsJson.has(eachRequiredProp)) { + continue; + } + + JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); + String randomValue = ""; + if(eachRequiredProp == emailResult) { + randomValue ="shshssh"; + } + if(eachRequiredProp == result) { + randomValue =phoneSchemaRegex ; + } + + + // Processing for TaggedListType + if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { + JSONArray eachPropDataArrayForHandles = new JSONArray(); + JSONObject eachValueJsonForHandles = new JSONObject(); + if (eachRequiredProp.equals(emailResult)) { + eachValueJsonForHandles.put("value", "$EMAILVALUE$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(emailResult); + + } else if (eachRequiredProp.equals(result)) { + eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); + //"tags": ":["handle"] + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(result); + } + + else if (eachRequiredProp.equals("nrcId")) { + eachValueJsonForHandles.put("value", "$NRCID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add("nrcId"); + } + + else { + eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(eachRequiredProp); + } + eachPropDataArrayForHandles.put(eachValueJsonForHandles); + identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); + + } + + + + else if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("simpleType")) { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + JSONArray eachPropDataArray = new JSONArray(); + + for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { + if (BaseTestCase.getLanguageList().get(j) != null + && !BaseTestCase.getLanguageList().get(j).isEmpty()) { + JSONObject eachValueJson = new JSONObject(); + eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); + if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); + } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); + } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); + } else { + eachValueJson.put(GlobalConstants.VALUE, + (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp + : propsMap.getProperty(eachRequiredProp) + BaseTestCase.getLanguageList().get(j)); + } + eachPropDataArray.put(eachValueJson); + } + } + identityJson.put(eachRequiredProp, eachPropDataArray); + + } else { + if (eachRequiredProp.equals("proofOfIdentity")) { + + identityJson.put(eachRequiredProp, new HashMap<>()); + identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); + identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); + identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); + } else if (eachRequiredProp.equals("proofOfAddress")) { + identityJson.put(eachRequiredProp, new HashMap<>()); + identityJson.getJSONObject(eachRequiredProp).put("format", "txt"); + identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); + identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); + } else if (eachRequiredProp.equals("preferredLang")) { + identityJson.put(eachRequiredProp, "$1STLANG$"); + } else if (eachRequiredProp.equals("registrationType")) { + identityJson.put(eachRequiredProp, genStringAsperRegex( + eachPropDataJson.getJSONArray("validators").getJSONObject(0).getString("validator"))); + } else if (eachRequiredProp.equals(result)) { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); + } else if (eachRequiredProp.equals(emailResult)) { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$EMAILVALUE$"); + } + + else if (eachRequiredProp.equals("nrcId")) { + String nrcID = "$NRCID$"; + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, nrcID); + } + + else if (eachRequiredProp.equals("password")) { + identityJson.put(eachRequiredProp, new HashMap<>()); + if (addIdentityPassword.isBlank() && addIdentitySalt.isBlank()) + getPasswordSaltFromKeyManager(PASSWORD_FOR_ADDIDENTITY_AND_REGISTRATION); + identityJson.getJSONObject(eachRequiredProp).put("hash", addIdentityPassword); + identityJson.getJSONObject(eachRequiredProp).put("salt", addIdentitySalt); + } else if (eachRequiredProp.equals("individualBiometrics")) { + identityJson.put(eachRequiredProp, new HashMap<>()); + identityJson.getJSONObject(eachRequiredProp).put("format", "cbeff"); + identityJson.getJSONObject(eachRequiredProp).put("version", 1); + identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); + } else if (eachRequiredProp.equals("IDSchemaVersion")) { + identityJson.put(eachRequiredProp, schemaVersion); + } else { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); + } + } + } + if (selectedHandles != null && selectedHandles.size()>=1) { + setfoundHandlesInIdSchema(true); + identityJson.put("selectedHandles", selectedHandles); + } + + + // Constructing and adding functionalIds + JSONArray functionalIdsArray = new JSONArray(); + for (String language : BaseTestCase.getLanguageList()) { + if (language != null && !language.isEmpty()) { + JSONObject functionalId = new JSONObject(); + functionalId.put("value", "TEST_CITY" + language); + functionalIdsArray.put(functionalId); + } + } + //identityJson.put("functionalIds", functionalIdsArray); + + if (isElementPresent(requiredPropsArray, "individualBiometrics")) { + JSONArray requestDocArray = new JSONArray(); + JSONObject docJson = new JSONObject(); + docJson.put("value", "{{value}}"); + docJson.put("category", "{{category}}"); + requestDocArray.put(docJson); + + requestJson.getJSONObject("request").put("documents", requestDocArray); + } + requestJson.getJSONObject("request").put("identity", identityJson); + requestJson.put("requesttime", "{{requesttime}}"); + requestJson.put("version", "{{version}}"); + + System.out.println(requestJson); + + } catch (Exception e) { + logger.error(e.getMessage()); + } + + identityHbs = requestJson.toString(); + return identityHbs; + } + + public static String updateIdentityHbs(boolean regenerateHbs) { - if (updateIdentityHbs != null && !regenerateHbs) { - - return updateIdentityHbs; - } - JSONObject requestJson = new JSONObject(); - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); - - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); - - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); - - Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); - - String schemaFile = schemaJsonData; - - boolean emailFieldAdditionallyAdded = false; - boolean phoneFieldAdditionallyAdded = false; - try { - JSONObject schemaFileJson = new JSONObject(schemaFile); - JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); - JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); - JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); - JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); - - schemaRequiredField = requiredPropsArray.toString(); - - String phone = getValueFromAuthActuator("json-property", "phone_number"); - String result = phone.replaceAll("\\[\"|\"\\]", ""); - - if (!isElementPresent(requiredPropsArray, result)) { - requiredPropsArray.put(result); - phoneFieldAdditionallyAdded = true; - } - if (identityPropsJson.has(result)) { - phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators").getJSONObject(0) - .getString("validator"); - } - - String email = getValueFromAuthActuator("json-property", "emailId"); - String emailResult = email.replaceAll("\\[\"|\"\\]", ""); - - if (!isElementPresent(requiredPropsArray, emailResult)) { - requiredPropsArray.put(emailResult); - emailFieldAdditionallyAdded = true; - } - - requestJson.put("id", "{{id}}"); - requestJson.put("status", "ACTIVATED"); - requestJson.put("request", new HashMap<>()); - requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); - JSONObject identityJson = new JSONObject(); - identityJson.put("UIN", "{{UIN}}"); - JSONArray handleArray = new JSONArray(); - handleArray.put("handles"); - - List selectedHandles = new ArrayList<>(); - // requiredPropsArray.put("functionalId"); - for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { - String eachRequiredProp = requiredPropsArray.getString(i); - - if (!identityPropsJson.has(eachRequiredProp)) { - continue; - } - - JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); - String randomValue = ""; - if (eachRequiredProp == emailResult) { - randomValue = "shshssh"; - } - if (eachRequiredProp == result) { - randomValue = phoneSchemaRegex; - } - - // Processing for TaggedListType - if (eachPropDataJson.has("$ref") - && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { - JSONArray eachPropDataArrayForHandles = new JSONArray(); - JSONObject eachValueJsonForHandles = new JSONObject(); - if (eachRequiredProp.equals(emailResult)) { - eachValueJsonForHandles.put("value", "$EMAILVALUE$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(emailResult); - - } else if (eachRequiredProp.equals(result)) { - eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); - // "tags": ":["handle"] - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(result); - } - - else if (eachRequiredProp.equals("nrcId")) { - eachValueJsonForHandles.put("value", "$NRCID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add("nrcId"); - } - - else { - eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); - eachValueJsonForHandles.put("tags", handleArray); - selectedHandles.add(eachRequiredProp); - } - - eachPropDataArrayForHandles.put(eachValueJsonForHandles); - identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); - - } - - else if (eachPropDataJson.has("$ref") - && eachPropDataJson.get("$ref").toString().contains("simpleType")) { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - JSONArray eachPropDataArray = new JSONArray(); - - for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { - if (BaseTestCase.getLanguageList().get(j) != null - && !BaseTestCase.getLanguageList().get(j).isEmpty()) { - JSONObject eachValueJson = new JSONObject(); - eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); - if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); - } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); - } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { - eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); - } else { - eachValueJson.put(GlobalConstants.VALUE, - (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp - : propsMap.getProperty(eachRequiredProp) - + BaseTestCase.getLanguageList().get(j)); - } - eachPropDataArray.put(eachValueJson); - } - } - identityJson.put(eachRequiredProp, eachPropDataArray); - - } else { - if (eachRequiredProp.equals("IDSchemaVersion")) { - identityJson.put(eachRequiredProp, schemaVersion); - } else if (eachRequiredProp.equals("individualBiometrics")) { - identityJson.remove("individualBiometrics"); - } else if (eachRequiredProp.equals(emailResult)) { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$EMAILVALUE$"); - } else if (eachRequiredProp.equals(result)) { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); - } else if (eachRequiredProp.equals("nrcId")) { - String nrcID = "$NRCID$"; - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, nrcID); - } else if (eachRequiredProp.equals("proofOfIdentity")) { - identityJson.remove("proofOfIdentity"); - } else { - if (eachPropDataJson.has("handle")) { - selectedHandles.add(eachRequiredProp); - } - identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); - } - } - } - if (selectedHandles != null) { - setfoundHandlesInIdSchema(true); - identityJson.put("selectedHandles", selectedHandles); - } - - // Constructing and adding functionalIds - JSONArray functionalIdsArray = new JSONArray(); - for (String language : BaseTestCase.getLanguageList()) { - if (language != null && !language.isEmpty()) { - JSONObject functionalId = new JSONObject(); - functionalId.put("value", "TEST_CITY" + language); - functionalIdsArray.put(functionalId); - } - } - requestJson.getJSONObject("request").put("identity", identityJson); - requestJson.put("requesttime", "{{requesttime}}"); - requestJson.put("version", "{{version}}"); - - System.out.println(requestJson); - - } catch (Exception e) { - logger.error(e.getMessage()); - } - - updateIdentityHbs = requestJson.toString(); - return updateIdentityHbs; - } - + if (updateIdentityHbs != null && !regenerateHbs) { + + return updateIdentityHbs; + } + JSONObject requestJson = new JSONObject(); + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); + + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + + Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); + + String schemaFile = schemaJsonData; + + boolean emailFieldAdditionallyAdded = false; + boolean phoneFieldAdditionallyAdded = false; + try { + JSONObject schemaFileJson = new JSONObject(schemaFile); + JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); + JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); + JSONObject identityPropsJson = schemaIdentityJson.getJSONObject("properties"); + JSONArray requiredPropsArray = schemaIdentityJson.getJSONArray("required"); + + schemaRequiredField = requiredPropsArray.toString(); + + String phone = getValueFromAuthActuator("json-property", "phone_number"); + String result = phone.replaceAll("\\[\"|\"\\]", ""); + + if (!isElementPresent(requiredPropsArray, result)) { + requiredPropsArray.put(result); + phoneFieldAdditionallyAdded = true; + } + if (identityPropsJson.has(result)) { + phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators") + .getJSONObject(0).getString("validator"); + } + + String email = getValueFromAuthActuator("json-property", "emailId"); + String emailResult = email.replaceAll("\\[\"|\"\\]", ""); + + if (!isElementPresent(requiredPropsArray, emailResult)) { + requiredPropsArray.put(emailResult); + emailFieldAdditionallyAdded = true; + } + + requestJson.put("id", "{{id}}"); + requestJson.put("status", "ACTIVATED"); + requestJson.put("request", new HashMap<>()); + requestJson.getJSONObject("request").put("registrationId", "{{registrationId}}"); + JSONObject identityJson = new JSONObject(); + identityJson.put("UIN", "{{UIN}}"); + JSONArray handleArray = new JSONArray(); + handleArray.put("handles"); + + List selectedHandles = new ArrayList<>(); + //requiredPropsArray.put("functionalId"); + for (int i = 0, size = requiredPropsArray.length(); i < size; i++) { + String eachRequiredProp = requiredPropsArray.getString(i); + + if (!identityPropsJson.has(eachRequiredProp)) { + continue; + } + + JSONObject eachPropDataJson = (JSONObject) identityPropsJson.get(eachRequiredProp); + String randomValue = ""; + if(eachRequiredProp == emailResult) { + randomValue ="shshssh"; + } + if(eachRequiredProp == result) { + randomValue =phoneSchemaRegex ; + } + + + // Processing for TaggedListType + if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("TaggedListType")) { + JSONArray eachPropDataArrayForHandles = new JSONArray(); + JSONObject eachValueJsonForHandles = new JSONObject(); + if (eachRequiredProp.equals(emailResult)) { + eachValueJsonForHandles.put("value", "$EMAILVALUE$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(emailResult); + + } else if (eachRequiredProp.equals(result)) { + eachValueJsonForHandles.put("value", "$PHONENUMBERFORIDENTITY$"); + //"tags": ":["handle"] + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(result); + } + + else if (eachRequiredProp.equals("nrcId")) { + eachValueJsonForHandles.put("value", "$NRCID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add("nrcId"); + } + + else { + eachValueJsonForHandles.put("value", "$FUNCTIONALID$"); + eachValueJsonForHandles.put("tags", handleArray); + selectedHandles.add(eachRequiredProp); + } + + + eachPropDataArrayForHandles.put(eachValueJsonForHandles); + identityJson.put(eachRequiredProp, eachPropDataArrayForHandles); + + } + + + + else if (eachPropDataJson.has("$ref") && eachPropDataJson.get("$ref").toString().contains("simpleType")) { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + JSONArray eachPropDataArray = new JSONArray(); + + for (int j = 0; j < BaseTestCase.getLanguageList().size(); j++) { + if (BaseTestCase.getLanguageList().get(j) != null + && !BaseTestCase.getLanguageList().get(j).isEmpty()) { + JSONObject eachValueJson = new JSONObject(); + eachValueJson.put("language", BaseTestCase.getLanguageList().get(j)); + if (eachRequiredProp.contains(GlobalConstants.FULLNAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + "1")); + } else if (eachRequiredProp.contains(GlobalConstants.FIRST_NAME) && regenerateHbs == true) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp + 1)); + } else if (eachRequiredProp.contains(GlobalConstants.GENDER)) { + eachValueJson.put(GlobalConstants.VALUE, propsMap.getProperty(eachRequiredProp)); + } else { + eachValueJson.put(GlobalConstants.VALUE, + (propsMap.getProperty(eachRequiredProp) == null) ? "TEST_" + eachRequiredProp + : propsMap.getProperty(eachRequiredProp) + BaseTestCase.getLanguageList().get(j)); + } + eachPropDataArray.put(eachValueJson); + } + } + identityJson.put(eachRequiredProp, eachPropDataArray); + + } else { + if (eachRequiredProp.equals("IDSchemaVersion")) { + identityJson.put(eachRequiredProp, schemaVersion); + } + else if (eachRequiredProp.equals("individualBiometrics")) { + identityJson.remove("individualBiometrics"); + } + else if (eachRequiredProp.equals(emailResult)) { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$EMAILVALUE$"); + } + else if (eachRequiredProp.equals(result)) { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$"); + } + else if (eachRequiredProp.equals("nrcId")) { + String nrcID = "$NRCID$"; + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, nrcID); + } + else if (eachRequiredProp.equals("proofOfIdentity")) { + identityJson.remove("proofOfIdentity"); + } + else { + if(eachPropDataJson.has("handle")){ + selectedHandles.add(eachRequiredProp); + } + identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}"); + } + } + } + if (selectedHandles != null) { + setfoundHandlesInIdSchema(true); + identityJson.put("selectedHandles", selectedHandles); + } + + + // Constructing and adding functionalIds + JSONArray functionalIdsArray = new JSONArray(); + for (String language : BaseTestCase.getLanguageList()) { + if (language != null && !language.isEmpty()) { + JSONObject functionalId = new JSONObject(); + functionalId.put("value", "TEST_CITY" + language); + functionalIdsArray.put(functionalId); + } + } + requestJson.getJSONObject("request").put("identity", identityJson); + requestJson.put("requesttime", "{{requesttime}}"); + requestJson.put("version", "{{version}}"); + + System.out.println(requestJson); + + } catch (Exception e) { + logger.error(e.getMessage()); + } + + updateIdentityHbs = requestJson.toString(); + return updateIdentityHbs; + } + + + public static String generateLatestSchemaVersion() { - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); - BigDecimal schemaVersion = schemaData.getBigDecimal(GlobalConstants.ID_VERSION); - String latestSchemaVersion = schemaVersion.toString(); - logger.info(latestSchemaVersion); - return latestSchemaVersion; + BigDecimal schemaVersion = schemaData.getBigDecimal(GlobalConstants.ID_VERSION); + String latestSchemaVersion = schemaVersion.toString(); + logger.info(latestSchemaVersion); + return latestSchemaVersion; } + public static String generateHbsForUpdateDraft() { if (draftHbs != null) { return draftHbs; @@ -5819,11 +5846,11 @@ public static String generateHbsForUpdateDraft() { identityJson.getJSONObject(eachRequiredProp).put("type", "DOC001"); identityJson.getJSONObject(eachRequiredProp).put("value", "fileReferenceID"); } - + else if (eachRequiredProp.equals("nrcId")) { - String nrcID = "$NRCID$"; - identityJson.put(eachRequiredProp, nrcID); - } + String nrcID = "$NRCID$"; + identityJson.put(eachRequiredProp, nrcID); + } else if (eachRequiredProp.equals("individualBiometrics")) { identityJson.put(eachRequiredProp, new HashMap<>()); @@ -6774,7 +6801,7 @@ public static String getValueFromEsignetWellKnownEndPoint(String key, String bas } return responseJson.getString(key); } - + public static String getValueFromInjiCertifyWellKnownEndPoint(String key, String baseURL) { String url = baseURL + ConfigManager.getproperty("injiCertifyWellKnownEndPoint"); @@ -6869,12 +6896,13 @@ public static String getValueFromActuator(String section, String key) { } } - + public static JSONArray mimotoActuatorResponseArray = null; public static String getValueFromMimotoActuator(String section, String key) { String url = ApplnURI + ConfigManager.getproperty("actuatorMimotoEndpoint"); - if (!(System.getenv("useOldContextURL") == null) && !(System.getenv("useOldContextURL").isBlank()) + if (!(System.getenv("useOldContextURL") == null) + && !(System.getenv("useOldContextURL").isBlank()) && System.getenv("useOldContextURL").equalsIgnoreCase("true")) { if (url.contains("/v1/mimoto/")) { url = url.replace("/v1/mimoto/", "/residentmobileapp/"); @@ -7114,30 +7142,31 @@ public static String getRegprocWaitFromActuator() { return waitInterval; } } - + private static Map testcaseIDNameMap = new HashMap<>(); - - public static void addTestCaseDetailsToMap(String testCaseName, String uniqueIdentifier) { + + public static void addTestCaseDetailsToMap(String testCaseName,String uniqueIdentifier) { testcaseIDNameMap.put(testCaseName, uniqueIdentifier); } - + public static String getTestCaseUniqueIdentifier(String testCaseName) { return testcaseIDNameMap.get(testCaseName); } + public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { String testCaseName = testCaseDTO.getTestCaseName(); - + int indexof = testCaseName.indexOf("_"); String modifiedTestCaseName = testCaseName.substring(indexof + 1); - + addTestCaseDetailsToMap(modifiedTestCaseName, testCaseDTO.getUniqueIdentifier()); - + JSONArray dobArray = new JSONArray(getValueFromAuthActuator("json-property", "dob")); JSONArray emailArray = new JSONArray(getValueFromAuthActuator("json-property", "emailId")); JSONArray phoneArray = new JSONArray(getValueFromAuthActuator("json-property", "phone_number")); JSONArray postalCodeArray = new JSONArray(getValueFromAuthActuator("json-property", "postal_code")); - + JSONArray individualBiometricsArray = new JSONArray( getValueFromAuthActuator("json-property", "individualBiometrics")); String dob = dobArray.getString(0); @@ -7149,23 +7178,28 @@ public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { && (!isElementPresent(new JSONArray(schemaRequiredField), dob))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); } - - if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("_handle") - && foundHandlesInIdSchema == false) { + + if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("_handle") && foundHandlesInIdSchema == false) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); } - - if (testCaseName.startsWith("IdRepository_") && (testCaseName.contains("_withInvalidEmail") - || testCaseName.contains("_with_invalid_Email") || testCaseName.contains("_with_Missing_Email") - || testCaseName.contains("_with_Empty_Email") || testCaseName.contains("_with_SpaceVal_Email")) - && (globalRequiredFields != null && !globalRequiredFields.toList().contains(emailArray))) { + + if (testCaseName.startsWith("IdRepository_") && + (testCaseName.contains("_withInvalidEmail") || + testCaseName.contains("_with_invalid_Email") || + testCaseName.contains("_with_Missing_Email") || + testCaseName.contains("_with_Empty_Email") || + testCaseName.contains("_with_SpaceVal_Email")) && + (globalRequiredFields != null && !globalRequiredFields.toList().contains(emailArray))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); - } - - if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("_with_Missing_phone") - && (globalRequiredFields != null && !globalRequiredFields.toList().contains(phoneArray))) { + } + + if (testCaseName.startsWith("IdRepository_") && + testCaseName.contains("_with_Missing_phone") && + (globalRequiredFields != null && !globalRequiredFields.toList().contains(phoneArray))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); - } + } + + else if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("Email") && (!isElementPresent(new JSONArray(schemaRequiredField), email))) { @@ -7200,16 +7234,16 @@ else if (testCaseName.startsWith("IdRepository_") && testCaseName.contains("Inva && (ConfigManager.isInServiceNotDeployedList(GlobalConstants.HOTLIST))) { throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE); } - - } + + } else if (testCaseName.startsWith("Prereg_") && (testCaseName.contains("_Invalid_PostalCode_") || testCaseName.contains("_SpacialCharacter_PostalCode_")) && (globalRequiredFields != null && !globalRequiredFields.toList().contains(postalCodeArray))) { throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE); - } - + } + // else if (BaseTestCase.currentModule.equalsIgnoreCase(GlobalConstants.ESIGNET)) { // if ((testCaseName.startsWith("Esignet_") || testCaseName.startsWith("ESignet_")) // && (testCaseName.contains("_KycBioAuth_") || testCaseName.contains("_BioAuth_") @@ -7223,6 +7257,8 @@ else if (testCaseName.startsWith("Prereg_") && BaseTestCase.currentModule.equalsIgnoreCase("resident") && testCaseName.contains("_SignJWT_")) { throw new SkipException("esignet module is not deployed"); } + + if ((ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) && BaseTestCase.currentModule.equalsIgnoreCase("resident") @@ -7356,13 +7392,14 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) { if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) { emailId = request.getJSONObject(GlobalConstants.REQUEST).getString("userId"); logger.info(emailId); - - if (testCaseName.contains("_INVALIDOTP")) { + + if(testCaseName.contains("_INVALIDOTP")) { otp = "26258976"; - } else { + } + else { otp = OTPListener.getOtp(emailId); } - + request.getJSONObject(GlobalConstants.REQUEST).put("otp", otp); inputJson = request.toString(); return inputJson; @@ -7513,7 +7550,7 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) { if (emailId.endsWith(GlobalConstants.OTP_AS_PHONE)) emailId = emailId.replace(GlobalConstants.OTP_AS_PHONE, ""); logger.info(emailId); - if (testCaseName.contains("_EmptyChannel_Invalid_Neg")) + if(testCaseName.contains("_EmptyChannel_Invalid_Neg")) otp = ""; else otp = OTPListener.getOtp(emailId); @@ -7665,12 +7702,12 @@ public static void getLocationData() { if (!(languageList.size() > 1)) { currentLanguage = BaseTestCase.languageList.get(0); } - + for (int i = 0; i < data.length(); i++) { JSONObject entry = data.getJSONObject(i); String langCode = entry.getString("langCode"); hierarchyLevel = entry.getInt("hierarchyLevel"); - + if (hierarchyLevel == recommendedHierarchyLevel) { if (currentLanguage.equals(langCode)) { hierarchyName = entry.getString("hierarchyName"); @@ -7802,7 +7839,7 @@ public static void getZoneName() { logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); } } - + public static void getLeafZone() { Response response = null; @@ -7830,7 +7867,7 @@ public static void getLeafZone() { logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); } } - + public static void getRegistrationCenterData() { Response response = null; @@ -7846,8 +7883,7 @@ public static void getRegistrationCenterData() { responseJson = new JSONObject(response.getBody().asString()); try { - JSONObject responseObject = responseJson.getJSONObject("response").getJSONArray("registrationCenters") - .getJSONObject(0); + JSONObject responseObject = responseJson.getJSONObject("response").getJSONArray("registrationCenters").getJSONObject(0); locationCode = responseObject.getString("locationCode"); @@ -7859,13 +7895,12 @@ public static void getRegistrationCenterData() { logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); } } - + public static void getLocationDataWithLocationCode(String locationCode) { Response response = null; JSONObject responseJson = null; - String url = ApplnURI + props.getProperty("fetchLocationDataWithCode") + locationCode + "/" - + BaseTestCase.getLanguageList().get(0); + String url = ApplnURI + props.getProperty("fetchLocationDataWithCode") + locationCode + "/" + BaseTestCase.getLanguageList().get(0); String token = kernelAuthLib.getTokenByRole("globalAdmin"); try { @@ -8060,21 +8095,21 @@ public String getPasswordPattern() { } return password; } - + public String getSubjectFromJwt(String JwtEncodedString) { String subject = ""; try { - DecodedJWT decodedJWT = JWT.decode(JwtEncodedString); - subject = decodedJWT.getSubject(); - logger.info("The subject of the Jwt Encoded String is " + subject); + DecodedJWT decodedJWT = JWT.decode(JwtEncodedString); + subject = decodedJWT.getSubject(); + logger.info("The subject of the Jwt Encoded String is " + subject); } catch (JwtException e) { logger.info("Invalid JWT token."); } return subject; } - + public static JSONArray ArrayOfJsonObjects = null; - + public static JSONArray getSyncDataResponseArray() { if (ArrayOfJsonObjects != null) { return ArrayOfJsonObjects; @@ -8091,7 +8126,7 @@ public static JSONArray getSyncDataResponseArray() { } return ArrayOfJsonObjects; } - + public static boolean IsCertSyncd(String certSubjectSubString) { if (ArrayOfJsonObjects == null) { ArrayOfJsonObjects = getSyncDataResponseArray(); @@ -8107,17 +8142,19 @@ public static boolean IsCertSyncd(String certSubjectSubString) { } return false; } - + + public static void setfoundHandlesInIdSchema(boolean foundHandles) { - - foundHandlesInIdSchema = foundHandles; + + foundHandlesInIdSchema=foundHandles; } - - public static boolean isHandlesAvailableInIdSchema(boolean foundHandles) { - - return foundHandlesInIdSchema; + + public static boolean isHandlesAvailableInIdSchema(boolean foundHandles) { + + return foundHandlesInIdSchema; } + // public static boolean checkIsCertTrusted(String certIssuer, JSONArray ArrayOfJsonObjects, int recursiveCount) { // for (int i = 0; i < ArrayOfJsonObjects.length(); i++) { // if (ArrayOfJsonObjects.getJSONObject(i).has("certSubject") @@ -8158,33 +8195,37 @@ public static boolean isHandlesAvailableInIdSchema(boolean foundHandles) { // } // return false; // } - - public static JSONArray getRequiredField() { - - JSONObject requestJson = new JSONObject(); - kernelAuthLib = new KernelAuthentication(); - String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); - String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); - - Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, - GlobalConstants.AUTHORIZATION, token); - - org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); - org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); - - Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); - String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); - - String schemaFile = schemaJsonData; - - JSONObject schemaFileJson = new JSONObject(schemaFile); - JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); - JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); - globalRequiredFields = schemaIdentityJson.getJSONArray("required"); + + + public static JSONArray getRequiredField() { + + + + JSONObject requestJson = new JSONObject(); + kernelAuthLib = new KernelAuthentication(); + String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN); + String url = ApplnURI + properties.getProperty(GlobalConstants.MASTER_SCHEMA_URL); + + Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, + GlobalConstants.AUTHORIZATION, token); + + org.json.JSONObject responseJson = new org.json.JSONObject(response.asString()); + org.json.JSONObject schemaData = (org.json.JSONObject) responseJson.get(GlobalConstants.RESPONSE); + + Double schemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + idSchemaVersion = ((BigDecimal) schemaData.get(GlobalConstants.ID_VERSION)).doubleValue(); + String schemaJsonData = schemaData.getString(GlobalConstants.SCHEMA_JSON); + + String schemaFile = schemaJsonData; + + JSONObject schemaFileJson = new JSONObject(schemaFile); + JSONObject schemaPropsJson = schemaFileJson.getJSONObject("properties"); + JSONObject schemaIdentityJson = schemaPropsJson.getJSONObject("identity"); + globalRequiredFields = schemaIdentityJson.getJSONArray("required"); return globalRequiredFields; - - } - + + } + } +