From 1ddfe4736935f5aef91731c4983a7de50377a97e Mon Sep 17 00:00:00 2001 From: Sohan Kumar Dey <72375959+Sohandey@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:56:22 +0530 Subject: [PATCH] -sMOSIP-29525 --- .../apirig/admin/fw/util/AdminTestUtil.java | 37 ++++++- .../apirig/admin/fw/util/TestCaseDTO.java | 1 + .../testrig/apirig/testscripts/BioAuth.java | 102 +++++++++++++++--- .../DemoAuthSimplePostForAutoGenId.java | 10 +- .../resources/config/application.properties | 4 +- .../main/resources/ida/DemoAuth/DemoAuth.yml | 70 +++++++++++- .../policy/DefinePolicy/DefinePolicy.yml | 78 ++++++++++++++ 7 files changed, 284 insertions(+), 18 deletions(-) diff --git a/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/AdminTestUtil.java b/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/AdminTestUtil.java index 376709a3933..7a7c5842ba9 100644 --- a/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/AdminTestUtil.java +++ b/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/AdminTestUtil.java @@ -17,6 +17,8 @@ import java.io.StringReader; import java.lang.reflect.Type; import java.math.BigInteger; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; @@ -5799,7 +5801,40 @@ public static String ekycDataDecryption(String url, JSONObject kycDataForDecrypt MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN); GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response); - return response.toString(); + return response.getBody().asString(); } + + public static String getValueFromUrl(String url,String dataToFetch) { + String idValue=""; + try { + URI uri = new URI(url); + Map queryParams = new HashMap<>(); + String query = uri.getQuery(); + if (query != null) { + String[] pairs = query.split("&"); + for (String pair : pairs) { + String[] param = pair.split("="); + String key = param[0]; + String value = param.length > 1 ? param[1] : ""; + queryParams.put(key, value); + } + + } + idValue = queryParams.get("id"); + if (idValue != null) { + System.out.println("Value of 'id' parameter: " + idValue); + } else { + System.out.println("'id' parameter not found in the URL."); + } + + } catch (URISyntaxException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + return idValue; + + } + + } diff --git a/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/TestCaseDTO.java b/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/TestCaseDTO.java index 9369e43d441..c14ad98b35e 100644 --- a/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/TestCaseDTO.java +++ b/automationtests/src/main/java/io/mosip/testrig/apirig/admin/fw/util/TestCaseDTO.java @@ -18,4 +18,5 @@ public class TestCaseDTO { private boolean auditLogCheck; private boolean checkErrorsOnlyInResponse; private String allowedErrorCodes; + private String[] kycFields; } diff --git a/automationtests/src/main/java/io/mosip/testrig/apirig/testscripts/BioAuth.java b/automationtests/src/main/java/io/mosip/testrig/apirig/testscripts/BioAuth.java index 237aa1d40f5..43739e70ea2 100644 --- a/automationtests/src/main/java/io/mosip/testrig/apirig/testscripts/BioAuth.java +++ b/automationtests/src/main/java/io/mosip/testrig/apirig/testscripts/BioAuth.java @@ -3,8 +3,16 @@ import static io.mosip.testrig.apirig.service.BaseTestCase.getRequestJson; import java.lang.reflect.Field; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.ListIterator; import java.util.Map; +import org.testng.Assert; + +import javax.ws.rs.core.MediaType; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -23,6 +31,9 @@ import org.testng.internal.BaseTestMethod; import org.testng.internal.TestResult; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + import io.mosip.testrig.apirig.admin.fw.util.AdminTestException; import io.mosip.testrig.apirig.admin.fw.util.AdminTestUtil; import io.mosip.testrig.apirig.admin.fw.util.TestCaseDTO; @@ -30,6 +41,7 @@ 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; @@ -41,8 +53,9 @@ public class BioAuth extends AdminTestUtil implements ITest { private static final Logger logger = Logger.getLogger(BioAuth.class); protected String testCaseName = ""; public Response response = null; + public Response newResponse = null; public boolean isInternal = false; - + @BeforeClass public static void setLogLevel() { if (ConfigManager.IsDebugEnabled()) @@ -71,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) { logger.info("Started executing yml: " + ymlFile); return getYmlTestData(ymlFile); } - /** * Test method for OTP Generation execution @@ -85,6 +97,8 @@ public Object[] getTestCaseList(ITestContext context) { @Test(dataProvider = "testcaselist") public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); + String[] kycFields = testCaseDTO.getKycFields(); + if (HealthChecker.signalTerminateExecution) { throw new SkipException("Target env health check failed " + HealthChecker.healthCheckFailureMapS); } @@ -94,35 +108,41 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad throw new SkipException("Idtype UIN is not supported. Hence skipping the testcase"); } } - + if (testCaseDTO.getTestCaseName().contains("vid") || testCaseDTO.getTestCaseName().contains("VID")) { if (!BaseTestCase.getSupportedIdTypesValueFromActuator().contains("VID") && !BaseTestCase.getSupportedIdTypesValueFromActuator().contains("vid")) { throw new SkipException("Idtype VID is not supported. Hence skipping the testcase"); } } - + if (testCaseDTO.getEndPoint().contains("$PartnerKeyURL$")) { 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)); + testCaseDTO.setEndPoint( + testCaseDTO.getEndPoint().replace("$KycPartnerName$", PartnerRegistration.ekycPartnerId)); } String request = testCaseDTO.getInput(); request = buildIdentityRequest(request); String inputJSON = getJsonFromTemplate(request, testCaseDTO.getInputTemplate()); + String resolvedUri = null; + String individualId = null; + resolvedUri = uriKeyWordHandelerUri(testCaseDTO.getEndPoint(), testCaseName); + + individualId = AdminTestUtil.getValueFromUrl(resolvedUri, "id"); String url = ConfigManager.getAuthDemoServiceUrl(); @@ -170,19 +190,75 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad JSONObject resJsonObject = new JSONObject(response.asString()); String res = ""; try { - //res = resJsonObject.get("response").toString(); + // res = resJsonObject.get("response").toString(); resJsonObject = new JSONObject(response.getBody().asString()).getJSONObject("authResponse") .getJSONObject("body").getJSONObject("response"); + + res = AdminTestUtil.ekycDataDecryption(url, resJsonObject, PartnerRegistration.ekycPartnerId, true); + + JSONObject jsonObjectkycRes = new JSONObject(res); + JSONObject jsonObjectFromKycData = new JSONObject(); + JSONObject jsonObjectFromIdentityData = new JSONObject(); + //List myList =new ArrayList<>(); + + ArrayList names = new ArrayList<>(); + ArrayList 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 i = 0; i < kycFields.length; i++) { String mappingField = + * getValueFromAuthActuator("json-property", kycFields[i]); mappingField = + * mappingField.replaceAll("\\[\"|\"\\]", ""); + * jsonObjectFromIdentityData.append(kycFields[i], + * responseBody.getString(mappingField)); } + */ + + + //ListIterator listIterator = myList.listIterator(); + //while (listIterator.hasNext()) { - res= AdminTestUtil.ekycDataDecryption( url, resJsonObject, PartnerRegistration.ekycPartnerId, - true); + for(int j=0;j