Skip to content

Commit

Permalink
Merge pull request #1507 from mohanachandran-s/inji-web-apis
Browse files Browse the repository at this point in the history
INJIWEB-179 Added new test cases
  • Loading branch information
lsivanand authored Jun 28, 2024
2 parents 4238b8a + 9b9bb68 commit e44e53b
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 6 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 @@ -436,7 +436,7 @@ protected Response postWithBodyAndCookie(String url, String jsonInput, boolean a
}

}

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

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

HashMap<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 @@ -3312,10 +3346,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 @@ -6039,6 +6081,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 @@ -6517,6 +6597,7 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
}

if (BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET)
|| BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO)
|| testCaseName.startsWith("Mimoto_WalletBinding")) {
if (request.has(GlobalConstants.REQUEST)) {
if (request.getJSONObject(GlobalConstants.REQUEST).has("otp")) {
Expand Down Expand Up @@ -6593,7 +6674,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
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,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 @@ -77,9 +77,15 @@ public static void reportResponse(String responseHeader, String url, String resp
if (formatResponse)
Reporter.log(GlobalConstants.REPORT_RESPONSE_PREFIX + GlobalConstants.REPORT_RESPONSE_BODY + formattedHeader
+ ReportUtil.getTextAreaJsonMsgHtml(response) + GlobalConstants.REPORT_RESPONSE_SUFFIX);
else
Reporter.log(GlobalConstants.REPORT_RESPONSE_PREFIX + GlobalConstants.REPORT_RESPONSE_BODY + responseHeader + response
+ GlobalConstants.REPORT_RESPONSE_SUFFIX);
else {
if(responseHeader == null) {
Reporter.log(GlobalConstants.REPORT_RESPONSE_PREFIX + GlobalConstants.REPORT_RESPONSE_BODY + response
+ GlobalConstants.REPORT_RESPONSE_SUFFIX);
} else {
Reporter.log(GlobalConstants.REPORT_RESPONSE_PREFIX + GlobalConstants.REPORT_RESPONSE_BODY + responseHeader + response
+ GlobalConstants.REPORT_RESPONSE_SUFFIX);
}
}
}

// Hashes a string using SHA-256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import io.mosip.testrig.apirig.testrunner.MosipTestRunner;
import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
import io.restassured.config.HttpClientConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.http.Cookie;
Expand Down Expand Up @@ -1688,4 +1689,23 @@ public static Response postRequestWithQueryParamBodyAndCookie(String url, Object

return postResponse;
}

public static byte[] postRequestWithFormDataBodyForPdf(String url, Map<String, String> formData) {
byte[] pdf;

EncoderConfig encoderConfig = new EncoderConfig().encodeContentTypeAs("application/x-www-form-urlencoded",
io.restassured.http.ContentType.URLENC);
RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a POST request to " + url);

if (ConfigManager.IsDebugEnabled()) {
pdf = given().config(config.encoderConfig(encoderConfig)).relaxedHTTPSValidation().formParams(formData)
.contentType("application/x-www-form-urlencoded").log().all().when().post(url).then().extract()
.asByteArray();
} else {
pdf = given().config(config.encoderConfig(encoderConfig)).relaxedHTTPSValidation().formParams(formData)
.contentType("application/x-www-form-urlencoded").when().post(url).then().extract().asByteArray();
}

return pdf;
}
}

0 comments on commit e44e53b

Please sign in to comment.