Skip to content

Commit

Permalink
Merge pull request #1185 from Sohandey/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Sohandey authored Nov 7, 2023
2 parents 754996d + 3d7c9cc commit 8de0259
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6252,6 +6252,33 @@ public static String ekycDataDecryption(String url, JSONObject kycDataForDecrypt
return response.getBody().asString();
}

public static String ekycDataDecryptionForDemo(String url, JSONObject kycDataForDecryption, String partnerName,
Boolean keyFileNameByPartnerName) {
url = url + properties.getProperty("decryptKycUrl");

ObjectMapper mapper = new ObjectMapper();
Map<String, String> map = null;
try {
map = mapper.readValue(kycDataForDecryption.toString(), Map.class);
} catch (JsonProcessingException e) {
logger.error(e.getMessage());
}

HashMap<String, Object> queryParamMap = new HashMap<>();
queryParamMap.put("partnerName", partnerName);
queryParamMap.put("moduleName", BaseTestCase.certsForModule);

queryParamMap.put("keyFileNameByPartnerName", keyFileNameByPartnerName);

GlobalMethods.reportRequest(null, map.toString());

Response response = RestClient.postRequestWithQueryParamsAndBody(url, map, queryParamMap,
MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

return response.getBody().asString();
}

public static String getValueFromUrl(String url,String dataToFetch) {
String idValue="";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,26 @@ public static Response postRequestWithQueryParamsAndBody(String url, Object body

return postResponse;
}

public static Response postRequestWithQueryParamsAndBodyForDecryption(String url, Object body,
Map<String, Object> queryParams, String contentHeader) {
Response postResponse;
if (ConfigManager.IsDebugEnabled()) {
RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a POST request with query param " + url);

postResponse = given().config(config).relaxedHTTPSValidation().body(body).queryParams(queryParams)
.contentType(contentHeader).log().all().when().post(url).then().log().all()
.extract().response();

RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_2 + postResponse.asString());
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_3 + postResponse.time());
} else {
postResponse = given().config(config).relaxedHTTPSValidation().body(body).queryParams(queryParams)
.contentType(contentHeader).when().post(url).then().extract().response();
}

return postResponse;
}

public static Response putRequestWithQueryParamAndBody(String url, Object body, Map<String, String> queryParams,
String contentHeader, String acceptHeader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,6 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
.getJSONObject("identity");


/*
* for (int i = 0; i < kycFields.length; i++) { String mappingField =
* getValueFromAuthActuator("json-property", kycFields[i]); mappingField =
* mappingField.replaceAll("\\[\"|\"\\]", "");
* jsonObjectFromIdentityData.append(kycFields[i],
* responseBody.getString(mappingField)); }
*/


//ListIterator<String> listIterator = myList.listIterator();
//while (listIterator.hasNext()) {


for(int j=0;j<names2.size();j++) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.MediaType;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.testng.ITest;
import org.testng.ITestContext;
Expand All @@ -31,6 +35,8 @@
import io.mosip.testrig.apirig.authentication.fw.util.AuthenticationTestException;
import io.mosip.testrig.apirig.authentication.fw.util.OutputValidationUtil;
import io.mosip.testrig.apirig.authentication.fw.util.ReportUtil;
import io.mosip.testrig.apirig.authentication.fw.util.RestClient;
import io.mosip.testrig.apirig.global.utils.GlobalMethods;
import io.mosip.testrig.apirig.ida.certificate.PartnerRegistration;
import io.mosip.testrig.apirig.kernel.util.ConfigManager;
import io.mosip.testrig.apirig.service.BaseTestCase;
Expand All @@ -42,6 +48,7 @@ public class DemoAuthSimplePostForAutoGenId extends AdminTestUtil implements ITe
protected String testCaseName = "";
public String idKeyName = null;
public Response response = null;
public Response newResponse = null;
String url="";

@BeforeClass
Expand Down Expand Up @@ -89,6 +96,7 @@ public Object[] getTestCaseList(ITestContext context) {
public void test(TestCaseDTO testCaseDTO)
throws AuthenticationTestException, AdminTestException, NoSuchAlgorithmException {
testCaseName = testCaseDTO.getTestCaseName();
String[] kycFields = testCaseDTO.getKycFields();
if (HealthChecker.signalTerminateExecution) {
throw new SkipException("Target env health check failed " + HealthChecker.healthCheckFailureMapS);
}
Expand All @@ -111,10 +119,21 @@ public void test(TestCaseDTO testCaseDTO)
testCaseDTO.setEndPoint(
testCaseDTO.getEndPoint().replace("$PartnerKeyURL$", PartnerRegistration.partnerKeyUrl));
}

if (testCaseDTO.getEndPoint().contains("$KycPartnerKeyURL$")) {
testCaseDTO.setEndPoint(
testCaseDTO.getEndPoint().replace("$KycPartnerKeyURL$", PartnerRegistration.ekycPartnerKeyUrl));
}

if (testCaseDTO.getEndPoint().contains("$PartnerName$")) {
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$PartnerName$", PartnerRegistration.partnerId));
}

if (testCaseDTO.getEndPoint().contains("$KycPartnerName$")) {
testCaseDTO.setEndPoint(
testCaseDTO.getEndPoint().replace("$KycPartnerName$", PartnerRegistration.ekycPartnerId));
}

String input = testCaseDTO.getInput();

if (input.contains("$PRIMARYLANG$"))
Expand All @@ -136,6 +155,11 @@ public void test(TestCaseDTO testCaseDTO)
}

String[] templateFields = testCaseDTO.getTemplateFields();
String resolvedUri = null;
String individualId = null;
resolvedUri = uriKeyWordHandelerUri(testCaseDTO.getEndPoint(), testCaseName);

individualId = AdminTestUtil.getValueFromUrl(resolvedUri, "id");

String inputJson = getJsonFromTemplate(input, testCaseDTO.getInputTemplate());

Expand Down Expand Up @@ -216,6 +240,77 @@ public void test(TestCaseDTO testCaseDTO)
if (!OutputValidationUtil.publishOutputResult(ouputValid))
throw new AdminTestException("Failed at output validation");
}

if (testCaseName.toLowerCase().contains("kyc")) {
JSONObject resJsonObject = new JSONObject(response.asString());
String res = "";
try {
// res = resJsonObject.get("response").toString();
resJsonObject = new JSONObject(response.getBody().asString()).getJSONObject("authResponse")
.getJSONObject("body").getJSONObject("response");

res = AdminTestUtil.ekycDataDecryptionForDemo(url, resJsonObject, PartnerRegistration.ekycPartnerId, true);

JSONObject jsonObjectkycRes = new JSONObject(res);
JSONObject jsonObjectFromKycData = new JSONObject();
JSONObject jsonObjectFromIdentityData = new JSONObject();
//List<String> myList =new ArrayList<>();

ArrayList<String> names = new ArrayList<>();
ArrayList<String> names2 = new ArrayList<>();

for (int i = 0; i < kycFields.length; i++) {
for (String key : jsonObjectkycRes.keySet()) {
if (key.contains(kycFields[i])) {
names.add(key);//dob gender_eng
names2.add(kycFields[i]);//dob gender
jsonObjectFromKycData.append(key, jsonObjectkycRes.getString(key));
break;
}
}

}

newResponse = RestClient.getRequestWithCookie(
ApplnURI + props.getProperty("retrieveIdByUin") + individualId, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, COOKIENAME, kernelAuthLib.getTokenByRole("idrepo"),
IDTOKENCOOKIENAME, null);

GlobalMethods.reportResponse(newResponse.getHeaders().asList().toString(), url, newResponse);

JSONObject responseBody = new JSONObject(newResponse.getBody().asString()).getJSONObject("response")
.getJSONObject("identity");



for(int j=0;j<names2.size();j++) {

String mappingField = getValueFromAuthActuator("json-property",names2.get(j));
mappingField = mappingField.replaceAll("\\[\"|\"\\]", "");
JSONArray valueOfJsonArray=responseBody.optJSONArray(mappingField);
if(valueOfJsonArray!=null) {
jsonObjectFromIdentityData.append(names.get(j), valueOfJsonArray.getJSONObject(0).get("value"));

valueOfJsonArray=null;
}
else {
jsonObjectFromIdentityData.append(names.get(j), responseBody.getString(mappingField));
}

}

Map<String, List<OutputValidationDto>> ouputValidNew = OutputValidationUtil.doJsonOutputValidation(jsonObjectFromIdentityData.toString(),
jsonObjectFromKycData.toString(), testCaseDTO.isCheckErrorsOnlyInResponse());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValidNew));

if (!OutputValidationUtil.publishOutputResult(ouputValidNew))
throw new AdminTestException("Failed at output validation");

} catch (JSONException e) {
logger.error(e.getMessage());
}

}

}

Expand Down
Loading

0 comments on commit 8de0259

Please sign in to comment.