Skip to content

Commit

Permalink
-sMOSIP-29525
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohandey committed Oct 31, 2023
1 parent df21636 commit 1ddfe47
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> 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;

}



}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public class TestCaseDTO {
private boolean auditLogCheck;
private boolean checkErrorsOnlyInResponse;
private String allowedErrorCodes;
private String[] kycFields;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,13 +31,17 @@
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;
import io.mosip.testrig.apirig.authentication.fw.dto.OutputValidationDto;
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;
Expand All @@ -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())
Expand Down Expand Up @@ -71,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) {
logger.info("Started executing yml: " + ymlFile);
return getYmlTestData(ymlFile);
}


/**
* Test method for OTP Generation execution
Expand All @@ -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);
}
Expand All @@ -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();

Expand Down Expand Up @@ -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<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 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()) {

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

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

String mappingField = getValueFromAuthActuator("json-property",names2.get(j));
mappingField = mappingField.replaceAll("\\[\"|\"\\]", "");
jsonObjectFromIdentityData.append(names.get(j), responseBody.getString(mappingField));
}

ouputValid = OutputValidationUtil.doJsonOutputValidation(jsonObjectFromIdentityData.toString(),
jsonObjectFromKycData.toString(), testCaseDTO.isCheckErrorsOnlyInResponse());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));

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

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


}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class DemoAuthSimplePostForAutoGenId extends AdminTestUtil implements ITe
protected String testCaseName = "";
public String idKeyName = null;
public Response response = null;
String url="";

@BeforeClass
public static void setLogLevel() {
Expand Down Expand Up @@ -169,7 +170,14 @@ public void test(TestCaseDTO testCaseDTO)
throw new AdminTestException("Failed at output validation");
}
} else {
String url = ConfigManager.getAuthDemoServiceUrl();
if(testCaseName.contains("partnerDemoDown")){

url = ConfigManager.getAuthDemoServiceUrl()+"local";
}
else {
url = ConfigManager.getAuthDemoServiceUrl();
}

response = postWithBodyAndCookie(url + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
String ActualOPJson = getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ fetchLocationData=/v1/masterdata/locations/all
fetchLocationLevel=/v1/masterdata/locations/level/
fetchTitle=/v1/masterdata/title
fetchZone=/v1/masterdata/zones/zonename
fetchZoneCode=/v1/masterdata/zones/hierarchy
decryptKycUrl=/v1/identity/decryptEkycData
decryptKycUrl=/v1/identity/decryptEkycData
retrieveIdByUin=/idrepository/v1/identity/idvid/
70 changes: 69 additions & 1 deletion automationtests/src/main/resources/ida/DemoAuth/DemoAuth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ DemoAuthNew:
role: resident
restMethod: post
inputTemplate: ida/DemoAuth/DemoIdentityEncryptName
outputTemplate: ida/DemoAuth/error
outputTemplate: ida/DemoAuth/DemoAuthResult
input: '{
"name": [
{
Expand All @@ -1169,4 +1169,72 @@ DemoAuthNew:
}'
output: '{
"authStatus": "true"
}'
auth_DemoAuth_DOB_Valid_Smoke_with_invalid_certs:
endPoint: /v1/identity/authenticate?moduleName=$MODULENAME$&certsDir=$abagc123&transactionId=$TRANSACTIONID$&id=$ID:AddIdentity_withValidParameters_smoke_Pos_UIN$&partnerUrlSuffix=$PartnerKeyURL$&keyFileNameByPartnerName=true&partnerName=$PartnerName$
role: resident
restMethod: post
inputTemplate: ida/DemoAuth/DemoAuth
outputTemplate: ida/DemoAuth/error
input: '{
"timestamp": "$TIMESTAMP$",
"transactionId": "$TRANSACTIONID$",
"value": "1970/07/08",
"key": "dob"
}'
output: '{
"authStatus": "false"
}'
auth_DemoAuth_DOB_Valid_Smoke_with_invalid_certs_and_inavlid_vid:
endPoint: /v1/identity/authenticate?moduleName=$MODULENAME$&certsDir=$abagc123&transactionId=$TRANSACTIONID$&id=$ID:GenerateVID_All_Valid_Smoke_Perpetual_sid_vid$&idType=VID&partnerUrlSuffix=$PartnerKeyURL$&keyFileNameByPartnerName=true&partnerName=$PartnerName$
role: resident
restMethod: post
inputTemplate: ida/DemoAuth/DemoAuth
outputTemplate: ida/DemoAuth/error
input: '{
"timestamp": "$TIMESTAMP$",
"transactionId": "$TRANSACTIONID$",
"value": "1970/07/08",
"key": "dob"
}'
output: '{
"authStatus": "false"
}'
auth_DemoAuthValid_when_partnerDemoDown_and_inavlid_vid:
endPoint: /v1/identity/authenticate?moduleName=$MODULENAME$&certsDir=$CERTSDIR$&transactionId=$TRANSACTIONID$id=$ID:AddIdentity_withValidParameters_smoke_Pos_UIN$&partnerUrlSuffix=$PartnerKeyURL$&keyFileNameByPartnerName=true&partnerName=$PartnerName$
role: resident
restMethod: post
inputTemplate: ida/DemoAuth/DemoIdentityEncryptName
outputTemplate: ida/DemoAuth/error
input: '{
"name": [
{
"language": "$PRIMARYLANG$",
"value": "TEST_FIRSTNAMEeng"
}
],
"timestamp": "$TIMESTAMP$",
"transactionId": "$TRANSACTIONID$"
}'
output: '{
"authStatus": "false"
}'
auth_DemoAuthValid_when_partnerDemoDown:
endPoint: /v1/identity/authenticate?moduleName=$MODULENAME$&certsDir=$CERTSDIR$&transactionId=$TRANSACTIONID$id=$ID:GenerateVID_All_Valid_Smoke_Perpetual_sid_vid$&idType=VID&partnerUrlSuffix=$PartnerKeyURL$&keyFileNameByPartnerName=true&partnerName=$PartnerName$
role: resident
restMethod: post
inputTemplate: ida/DemoAuth/DemoIdentityEncryptName
outputTemplate: ida/DemoAuth/error
input: '{
"name": [
{
"language": "$PRIMARYLANG$",
"value": "TEST_FIRSTNAMEeng"
}
],
"timestamp": "$TIMESTAMP$",
"transactionId": "$TRANSACTIONID$"
}'
output: '{
"authStatus": "false"
}'
Loading

0 comments on commit 1ddfe47

Please sign in to comment.