Skip to content

Commit

Permalink
MOSIP-34075 Resolved Conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Sohan Kumar Dey <[email protected]>
  • Loading branch information
Sohandey committed Jul 4, 2024
2 parents d9db000 + a27aa1f commit 778d2af
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apitest-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.56</version>
<version>1.70</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected void writeSuiteSummary() {

// Left column: "Tested Component Details" with central alignment
writer.print("<th style=\"text-align: center; vertical-align: middle;\" colspan=\"2\"><span class=\"not-bold\"><pre>");
writer.print(Utils.escapeHtml("Tested Component Details"));
writer.print(Utils.escapeHtml("Server Component Details"));
writer.print("</span></th>");

// Right column: Details from AdminTestUtil.getServerComponentsDetails() without bold formatting
Expand All @@ -268,6 +268,17 @@ protected void writeSuiteSummary() {
writer.print("</pre></td>");
writer.print(GlobalConstants.TRTR);

// Left column: "Tested Component Details" with central alignment
writer.print("<th style=\"text-align: center; vertical-align: middle;\" colspan=\"2\"><span class=\"not-bold\"><pre>");
writer.print(Utils.escapeHtml("Tested Components & End Points"));
writer.print("</span></th>");

// Right column: Details from AdminTestUtil.getServerComponentsDetails() without bold formatting
writer.print("<td colspan=\"5\"><pre>");
writer.print(Utils.escapeHtml(GlobalMethods.getComponentDetails()));
writer.print("</pre></td>");
writer.print(GlobalConstants.TRTR);

writer.print("<tr><th colspan=\"7\"><span class=\"not-bold\"><pre>");
writer.print(Utils.escapeHtml("Server Errors " + "\n" + GlobalMethods.getServerErrors()));
writer.print("</pre></span>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a
}

}

logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson, url);
try {
Expand Down Expand Up @@ -2274,6 +2274,40 @@ protected byte[] postWithBodyAndCookieForPdf(String url, String jsonInput, Strin
}
}

protected byte[] postWithFormDataBodyForPdf(String url, String jsonInput, String cookieName, String role,
String testCaseName) {

HashMap<String, String> formDataMap = new HashMap<>();
jsonInput = inputJsonKeyWordHandeler(jsonInput, testCaseName);
logger.info("inputJson is::" + jsonInput);

JSONObject req = new JSONObject(jsonInput);
logger.info(GlobalConstants.REQ_STR + req);
jsonInput = req.toString();

byte[] pdf = null;

try {
formDataMap = new Gson().fromJson(jsonInput, new TypeToken<HashMap<String, String>>() {
}.getType());
} catch (Exception e) {
logger.error(
GlobalConstants.ERROR_STRING_1 + jsonInput + GlobalConstants.EXCEPTION_STRING_1 + e.getMessage());
}

logger.info("******Post request to EndPointUrl: " + url);
GlobalMethods.reportRequest(null, jsonInput, url);

try {
pdf = RestClient.postRequestWithFormDataBodyForPdf(url, formDataMap);
return pdf;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return pdf;
}

}

protected byte[] getWithQueryParamAndCookieForPdf(String url, String jsonInput, String cookieName, String role,
String testCaseName) {
return getWithQueryParamAndCookieForPdf(url, jsonInput, cookieName, role, testCaseName, false);
Expand Down Expand Up @@ -3311,10 +3345,18 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
jsonString = replaceKeywordWithValue(jsonString, "$OIDCCLIENT$",
getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.module.clientID"));
}
if (jsonString.contains("$GETCLIENTIDFROMMIMOTOACTUATOR$")) {
jsonString = replaceKeywordWithValue(jsonString, "$GETCLIENTIDFROMMIMOTOACTUATOR$",
getValueFromMimotoActuator("configService:overrides", "mimoto.oidc.partner.clientid"));
}
if (jsonString.contains("$IDPREDIRECTURI$")) {
jsonString = replaceKeywordWithValue(jsonString, "$IDPREDIRECTURI$",
ApplnURI.replace(GlobalConstants.API_INTERNAL, "healthservices") + "/userprofile");
}
if (jsonString.contains("$INJIREDIRECTURI$")) {
jsonString = replaceKeywordWithValue(jsonString, "$INJIREDIRECTURI$",
ApplnURI.replace(GlobalConstants.API_INTERNAL, "inji") + "/redirect");
}
if (jsonString.contains("$BASE64URI$")) {
String redirectUri = ApplnURI.replace(GlobalConstants.API_INTERNAL, GlobalConstants.RESIDENT)
+ propsKernel.getProperty("currentUserURI");
Expand Down Expand Up @@ -6042,6 +6084,44 @@ public static String getValueFromActuator(String section, String key) {
}

}

public static JSONArray mimotoActuatorResponseArray = null;

public static String getValueFromMimotoActuator(String section, String key) {
String url = ApplnURI + propsKernel.getProperty("actuatorMimotoEndpoint");
String actuatorCacheKey = url + section + key;
String value = actuatorValueCache.get(actuatorCacheKey);
if (value != null && !value.isEmpty())
return value;

try {
if (mimotoActuatorResponseArray == null) {
Response response = null;
JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);

responseJson = new JSONObject(response.getBody().asString());
mimotoActuatorResponseArray = responseJson.getJSONArray("propertySources");
}
for (int i = 0, size = mimotoActuatorResponseArray.length(); i < size; i++) {
JSONObject eachJson = mimotoActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
if (ConfigManager.IsDebugEnabled())
logger.info("Actuator: " + url + " key: " + key + " value: " + value);
break;
}
}
actuatorValueCache.put(actuatorCacheKey, value);

return value;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return "";
}

}

public static JSONArray regprocActuatorResponseArray = null;

Expand Down Expand Up @@ -6411,7 +6491,6 @@ else if (testCaseName.contains("_Exceeding_Limit_Value_On_Name_Field_Neg"))
}

public static String smtpOtpHandler(String inputJson, String testCaseName) {

JSONObject request = new JSONObject(inputJson);
String emailId = null;
String otp = null;
Expand All @@ -6434,7 +6513,6 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
}
}
}

if (BaseTestCase.currentModule.equals(GlobalConstants.PREREG)) {
if (request.has(GlobalConstants.REQUEST)) {
if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) {
Expand All @@ -6447,8 +6525,6 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
}
}
}


if (BaseTestCase.currentModule.equals("auth")) {
if (testCaseName.startsWith("auth_GenerateVID") || testCaseName.startsWith("auth_AuthLock")
|| testCaseName.startsWith("auth_AuthUnLock") || testCaseName.startsWith("auth_RevokeVID")) {
Expand Down Expand Up @@ -6531,7 +6607,6 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
}
}
}

if (BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET)
|| testCaseName.startsWith("Mimoto_WalletBinding")) {
if (request.has(GlobalConstants.REQUEST)) {
Expand Down Expand Up @@ -6581,9 +6656,7 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
return inputJson;
}
}

}

if (BaseTestCase.currentModule.equals(GlobalConstants.RESIDENT)) {
if (request.has(GlobalConstants.REQUEST)) {
if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) {
Expand All @@ -6609,7 +6682,8 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
.getString(GlobalConstants.CHALLENGE).endsWith(GlobalConstants.MOSIP_NET)
|| request.getJSONObject(GlobalConstants.REQUEST)
.getJSONArray(GlobalConstants.CHALLENGELIST).getJSONObject(0)
.getString(GlobalConstants.CHALLENGE).endsWith(GlobalConstants.OTP_AS_PHONE)) {
.getString(GlobalConstants.CHALLENGE)
.endsWith(GlobalConstants.OTP_AS_PHONE)) {
emailId = request.getJSONObject(GlobalConstants.REQUEST)
.getJSONArray(GlobalConstants.CHALLENGELIST).getJSONObject(0)
.getString(GlobalConstants.CHALLENGE);
Expand Down Expand Up @@ -7045,4 +7119,4 @@ public String getPasswordPattern() {
return password;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,5 @@ public class GlobalConstants {
public static final String TARGET_ENV_HEALTH_CHECK_FAILED = "Target env health check failed ";
public static final String HOTLIST = "hotlist";
public static final String XSRF_TOKEN = "XSRF-TOKEN";
public static final String _AUTHENTICATEUSER = "_AuthenticateUser";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import org.testng.Reporter;
Expand All @@ -18,6 +24,88 @@ public class GlobalMethods {
public static Map<Object, Object> serverFailuresMapS = Collections
.synchronizedMap(new HashMap<Object, Object>());

public static Set<String> serverEndpoints = new HashSet<>();

public static void main(String[] arg) {

}

public static void addToServerEndPointMap(String url) {
serverEndpoints.add(url);
}

public static String removeNumerics(String url) {
// Define the regex patterns
String regex1 = "/\\d+/"; // Remove numeric characters between slashes
String regex2 = "/\\d+$"; // Remove numeric characters after the last slash at the end of the string
String regex3 = "/mosip_[a-zA-Z0-9_]+/"; // Remove alphanumeric sequences starting with 'mosip_' between slashes
// Compile the regex patterns
Pattern pattern1 = Pattern.compile(regex1);
Pattern pattern2 = Pattern.compile(regex2);
Pattern pattern3 = Pattern.compile(regex3);
// Apply the regex replacements sequentially
String modifiedString = url;
modifiedString = pattern1.matcher(modifiedString).replaceAll("/");
modifiedString = pattern2.matcher(modifiedString).replaceAll("/");
modifiedString = pattern3.matcher(modifiedString).replaceAll("/");
return modifiedString;
}

public static String getComponentDetails() {
// Define the regex pattern to extract the domain and the path after the domain
String regex = "https://([^/]+)/(v[0-9]+)?/(partnermanager|masterdata|idgenerator|policymanager|idauthentication|idrepository)/([^,]+)";
// Compile the regex pattern
Pattern pattern = Pattern.compile(regex);
// Set to store unique results
Set<String> uniqueResults = new HashSet<>();
// Iterate over the set of URLs
for (String url : serverEndpoints) {
// Create a matcher for the current URL
Matcher matcher = pattern.matcher(url);
// Find matches

while (matcher.find()) {
String domain = matcher.group(1);
String version = matcher.group(2) != null ? matcher.group(2) : ""; // Handle null for optional group
String module = matcher.group(3);
String endpoint = version + "/" + module + "/" + matcher.group(4);
String result = "Domain: " + domain + " ---- Module: " + module + " ---- End Point: "
+ removeNumerics(endpoint);
uniqueResults.add(result);
}
}

regex = "https://([^/]+)/(partnermanager|masterdata|idgenerator|policymanager|idauthentication|idrepository)/(v[0-9]+)/([^,]+)";
// Compile the regex pattern
pattern = Pattern.compile(regex);
// Iterate over the set of URLs
for (String url : serverEndpoints) {
// Create a matcher for the current URL
Matcher matcher = pattern.matcher(url);
// Find matches
while (matcher.find()) {
String domain = matcher.group(1);
String module = matcher.group(2) != null ? matcher.group(2) : ""; // Handle null for optional group
String version = matcher.group(3);
String endpoint = module + "/" + version + "/" + matcher.group(4);
String result = "Domain: " + domain + " ---- Module: " + module + " ---- End Point: "
+ removeNumerics(endpoint);

uniqueResults.add(result);
}
}



// Convert the set to an ArrayList
List<String> uniqueList = new ArrayList<>(uniqueResults);
StringBuilder stringBuilder = new StringBuilder();
// Print the unique results
for (String result : uniqueList) {
stringBuilder.append("\n").append(result);
}
return stringBuilder.toString();
}

public static void reportServerError(Object code, Object errorMessage) {
serverFailuresMapS.put(code, errorMessage);
Expand All @@ -34,6 +122,22 @@ public static String getServerErrors() {

}

public static String maskOutSensitiveInfo(String strInput) {
if (ConfigManager.IsDebugEnabled())
return strInput;

Pattern INDIVIDUAL_BIOMETRICS_PATTERN = Pattern.compile("\"category\":\\s?\"individualBiometrics\",\\s?\"value\":\\s?\"(.*?)\"");
Pattern UIN_PATTERN = Pattern.compile("\"UIN\":\\s?\"(\\d{10})\"");

Matcher biometricsMatcher = INDIVIDUAL_BIOMETRICS_PATTERN.matcher(strInput);
String maskedInput = biometricsMatcher.replaceAll("\"category\": \"individualBiometrics\", \"value\": \"***** MASKED *****\"");

// Matcher uinMatcher = UIN_PATTERN.matcher(maskedInput);
// maskedInput = uinMatcher.replaceAll("\"UIN\": \"***** MASKED *****\"");

return maskedInput;
}

public static void ReportRequestAndResponse(String reqHeader,String resHeader,String url, String requestBody, String response, boolean formatResponse ) {
reportRequest(reqHeader,requestBody, url);
reportResponse(resHeader,url, response, formatResponse);
Expand All @@ -49,15 +153,17 @@ public static void reportRequest(String requestHeader, String request) {
}

public static void reportRequest(String requestHeader, String request, String url) {

String formattedHeader = ReportUtil.getTextAreaForHeaders(requestHeader);

if (request != null && !request.equals("{}"))
Reporter.log(GlobalConstants.REPORT_REQUEST_PREFIX + url + GlobalConstants.REPORT_REQUEST_BODY + formattedHeader + ReportUtil.getTextAreaJsonMsgHtml(request)
Reporter.log(GlobalConstants.REPORT_REQUEST_PREFIX + url + GlobalConstants.REPORT_REQUEST_BODY
+ formattedHeader + ReportUtil.getTextAreaJsonMsgHtml(maskOutSensitiveInfo(request))
+ GlobalConstants.REPORT_REQUEST_SUFFIX);
else
Reporter.log(
GlobalConstants.REPORT_REQUEST_PREFIX + url + GlobalConstants.REPORT_REQUEST_BODY + formattedHeader + ReportUtil.getTextAreaJsonMsgHtml("No request body") + GlobalConstants.REPORT_REQUEST_SUFFIX);
Reporter.log(GlobalConstants.REPORT_REQUEST_PREFIX + url + GlobalConstants.REPORT_REQUEST_BODY
+ formattedHeader + ReportUtil.getTextAreaJsonMsgHtml("No request body")
+ GlobalConstants.REPORT_REQUEST_SUFFIX);
}

public static void reportResponse(String responseHeader, String url, Response response) {
Expand Down
Loading

0 comments on commit 778d2af

Please sign in to comment.